Skip to content

Commit

Permalink
fix(preview): filter slugs with special characters to match dev clien…
Browse files Browse the repository at this point in the history
…ts `exp+<slug>` scheme (#252)

* test(preview): add tests for eas update qr code urls

* fix(preview): use same filtering of `slug` as done in `expo-dev-client`

* chore: rebuild actions
  • Loading branch information
byCedric authored Jan 15, 2024
1 parent b547b4d commit b8a9be8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
3 changes: 2 additions & 1 deletion build/preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42133,7 +42133,8 @@ function getUpdateGroupQr({ projectId, updateGroupId, appSlug, qrTarget, }) {
if (qrTarget === 'dev-build') {
// While the parameter is called `appScheme`, it's actually the app's slug
// This should only be added when using dev clients as target
url.searchParams.append('appScheme', appSlug);
// See: https://github.com/expo/expo/blob/8ae75dde393e5d2393d446227a1fe2482c75eec3/packages/expo-dev-client/plugin/src/getDefaultScheme.ts#L17
url.searchParams.append('appScheme', appSlug.replace(/[^A-Za-z0-9+\-.]/g, ''));
}
url.searchParams.append('projectId', projectId);
url.searchParams.append('groupId', updateGroupId);
Expand Down
3 changes: 2 additions & 1 deletion src/eas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ export function getUpdateGroupQr({
if (qrTarget === 'dev-build') {
// While the parameter is called `appScheme`, it's actually the app's slug
// This should only be added when using dev clients as target
url.searchParams.append('appScheme', appSlug);
// See: https://github.com/expo/expo/blob/8ae75dde393e5d2393d446227a1fe2482c75eec3/packages/expo-dev-client/plugin/src/getDefaultScheme.ts#L17
url.searchParams.append('appScheme', appSlug.replace(/[^A-Za-z0-9+\-.]/g, ''));
}

url.searchParams.append('projectId', projectId);
Expand Down
36 changes: 36 additions & 0 deletions tests/eas.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { getUpdateGroupQr } from '../src/eas';

describe(getUpdateGroupQr, () => {
it('returns url for expo-go', () => {
expect(
getUpdateGroupQr({
qrTarget: 'expo-go',
projectId: 'projectId',
updateGroupId: 'updateGroupId',
appSlug: 'appslug',
})
).toBe('https://qr.expo.dev/eas-update?projectId=projectId&groupId=updateGroupId');
});

it('returns url for dev-build', () => {
expect(
getUpdateGroupQr({
qrTarget: 'dev-build',
projectId: 'projectId',
updateGroupId: 'updateGroupId',
appSlug: 'appslug',
})
).toBe('https://qr.expo.dev/eas-update?appScheme=appslug&projectId=projectId&groupId=updateGroupId');
});

it('returns url for dev-build, with `_` in appSlug', () => {
expect(
getUpdateGroupQr({
qrTarget: 'dev-build',
projectId: 'projectId',
updateGroupId: 'updateGroupId',
appSlug: 'hello_world',
})
).toBe('https://qr.expo.dev/eas-update?appScheme=helloworld&projectId=projectId&groupId=updateGroupId');
});
});

0 comments on commit b8a9be8

Please sign in to comment.