Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/launch-argument-name-spaces.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@e2e-dev/core': patch
---

Accept spaces inside a name in the object form of `app.launchArguments`, so a user-defaults key such as `'NSSplitView Subview Frames Main'` no longer fails with `INVALID_CONFIG`. A name with a control character, a space at either end, or any other whitespace is still refused.
10 changes: 6 additions & 4 deletions docs/reference/config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,11 @@ type LaunchArguments = readonly string[] | Readonly<Record<string, LaunchArgumen
```

- An object value is a string, a finite number below 2^53 in magnitude, a
boolean, or a list of strings. A name has no leading dash, whitespace, or
control characters, and nothing holds a NUL character. A value read from the
environment may be `undefined`: that entry is left out.
boolean, or a list of strings. A name has no leading dash and no control
characters. Spaces inside a name are fine, as in
`'NSSplitView Subview Frames Main'`; a space at either end and any other
whitespace are not. Nothing holds a NUL character. A
value read from the environment may be `undefined`: that entry is left out.
- The table under
[Launch arguments and permissions](/reference/mobile#launch-arguments-and-permissions)
shows each value type on iOS and Android.
Expand All @@ -610,7 +612,7 @@ type LaunchArguments = readonly string[] | Readonly<Record<string, LaunchArgumen

| Throws | When |
| --- | --- |
| `INVALID_CONFIG` | A list item that is not a string. An object with an empty name, a name with whitespace or a control character, a value of another kind, a number beyond 2^53 - 1 in magnitude, or a NUL character anywhere. The engine adds its own rules: see [the mobile reference](/reference/mobile#launch-arguments-and-permissions). |
| `INVALID_CONFIG` | A list item that is not a string. An object with an empty name, a name with a control character, a space at either end, or whitespace other than a space, a value of another kind, a number beyond 2^53 - 1 in magnitude, or a NUL character anywhere. The engine adds its own rules: see [the mobile reference](/reference/mobile#launch-arguments-and-permissions). |

#### `permissions`

Expand Down
6 changes: 3 additions & 3 deletions docs/reference/engine.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2041,9 +2041,9 @@ const launchArguments = checkLaunchArguments('device.openApp({ launchArguments }
// device.openApp({ launchArguments }).env must be a string, number, boolean, or array of strings, got null
```

- A list holds strings. An object maps a non-empty name with no whitespace or
control characters to a string, a finite number below 2^53 in magnitude, a
boolean, or a list of strings. Nothing holds a NUL character.
- A list holds strings. An object maps a non-empty name to a string, a finite
number below 2^53 in magnitude, a boolean, or a list of strings. A name has
no control characters, and no whitespace but spaces inside it. Nothing holds a NUL character.
- An object's argument name does not start with a dash: write `AppleLocale`,
not `-AppleLocale`. The engine adds the dash, so a dashed name fails.
- The engine adds its platform's rules after this check, with the same
Expand Down
20 changes: 15 additions & 5 deletions packages/core/src/internal/launch-arguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@ import type { LaunchArgumentValue, LaunchArgumentValues, ResolvedLaunchArguments
/** What an old-style plist string may hold unquoted. `NSUserDefaults` reads a bare value that starts with `-` as the next argument's name. */
const PLIST_UNQUOTED = /^[A-Za-z0-9_$/:.][A-Za-z0-9_$/:.-]*$/;

/** What an argument name may not hold: a control character, or whitespace other than a plain space. */
const CONTROL_OR_NON_SPACE_WHITESPACE = /[^\S ]|\p{Cc}/u;

const LAUNCH_ARGUMENTS_SHAPE = 'an array of strings or an object of argument name to string, number, boolean, or array of strings';

/**
* Launch arguments as declared: a list of strings, or a plain object of
* argument name (non-empty, no leading dash, no whitespace or control
* characters) to string, finite number below 2^53 in magnitude, boolean,
* or list of strings, none holding a NUL character. An `undefined` value, read from the
* argument name (non-empty, no leading dash, no control characters, no
* whitespace but spaces inside it) to string, finite number below 2^53 in
* magnitude, boolean, or list of strings, none holding a NUL character. A
* name may hold spaces, as a user-defaults key such as
* `NSSplitView Subview Frames Main` does: every engine sends it as one
* process argument. A space at either end, or any other whitespace, is a
* typo the app would never read. An `undefined` value, read from the
* environment, is the entry left out. `code` picks the error: a target's
* config fails with `INVALID_CONFIG`, a test's own launch with
* `INVALID_ARGUMENT`.
Expand All @@ -35,8 +42,11 @@ export function checkLaunchArguments(label: string, declared: unknown, code: 'IN
for (const [name, value] of Object.entries(declared)) {
if (value === undefined) continue;
if (name === '') fail(code, `${label} has an empty argument name`);
if (/[\s\p{Cc}]/u.test(name)) {
fail(code, `${label} argument name ${JSON.stringify(name)} must have no whitespace or control characters`);
if (CONTROL_OR_NON_SPACE_WHITESPACE.test(name)) {
fail(code, `${label} argument name ${JSON.stringify(name)} must have no control characters and no whitespace other than a space`);
}
if (name !== name.trim()) {
fail(code, `${label} argument name ${JSON.stringify(name)} must not start or end with a space`);
}
if (name.startsWith('-')) {
fail(code, `${label} argument name ${JSON.stringify(name)} starts with a dash; remove the dash, the engine adds it`);
Expand Down
18 changes: 14 additions & 4 deletions packages/e2e/tests/unit/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -650,13 +650,23 @@ describe('resolveConfig', () => {
expect(() => resolveApp({ launchArguments: null } as never)).toThrow(`${shape}, got null`);
expect(() => resolveApp({ launchArguments: new Map([['AppleLocale', 'fr_FR']]) } as never)).toThrow(`${shape}, got a Map`);
expect(() => resolveApp({ launchArguments: { '': 'x' } })).toThrow('target "web" app.launchArguments has an empty argument name');
expect(() => resolveApp({ launchArguments: { 'Apple Locale': 'fr_FR' } })).toThrow(
'target "web" app.launchArguments argument name "Apple Locale" must have no whitespace or control characters',
);
expect(resolveApp({ bundleId: 'dev.shop.app', launchArguments: { 'NSSplitView Subview Frames Main': ['0, 0, 200, 600'] } }).launchArguments).toEqual({
'NSSplitView Subview Frames Main': ['0, 0, 200, 600'],
});
for (const name of [' AppleLocale', 'AppleLocale ']) {
expect(() => resolveApp({ launchArguments: { [name]: 'fr_FR' } })).toThrow(
`target "web" app.launchArguments argument name ${JSON.stringify(name)} must not start or end with a space`,
);
}
for (const name of ['Apple\tLocale', 'Apple\u00a0Locale', 'Apple\u2028Locale']) {
expect(() => resolveApp({ launchArguments: { [name]: 'fr_FR' } })).toThrow(
`target "web" app.launchArguments argument name ${JSON.stringify(name)} must have no control characters and no whitespace other than a space`,
);
}
expect(() => resolveApp({ launchArguments: { '-AppleLocale': 'fr_FR' } })).toThrow(
'target "web" app.launchArguments argument name "-AppleLocale" starts with a dash; remove the dash, the engine adds it',
);
expect(() => resolveApp({ launchArguments: { 'a\u0000b': 'x' } })).toThrow('argument name "a\\u0000b" must have no whitespace or control characters');
expect(() => resolveApp({ launchArguments: { 'a\u0000b': 'x' } })).toThrow('argument name "a\\u0000b" must have no control characters and no whitespace other than a space');
expect(() => resolveApp({ launchArguments: { env: 'a\u0000' } })).toThrow('target "web" app.launchArguments.env holds a NUL character');
expect(() => resolveApp({ launchArguments: { tags: ['a', 'b\u0000'] } })).toThrow('target "web" app.launchArguments.tags holds a NUL character');
expect(() => resolveApp({ launchArguments: ['-a', 'b\u0000'] })).toThrow('target "web" app.launchArguments item 1 holds a NUL character');
Expand Down
6 changes: 6 additions & 0 deletions packages/mobile/tests/unit/launch-arguments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ describe('launchArgumentList', () => {
]);
expect(launchArgumentList('android', { tags: ['a', 'b c', 'd'] })).toEqual(['--esa', 'tags', 'a,b c,d']);
});

// Characterization: the list never split names; the config check is what now lets a spaced name through.
it('passes a name with spaces through as one argument', () => {
expect(launchArgumentList('ios', { 'NSSplitView Subview Frames Main': ['0, 0, 200, 600'] })).toEqual(['-NSSplitView Subview Frames Main', '("0, 0, 200, 600")']);
expect(launchArgumentList('android', { 'mock server': 'http://localhost:9001' })).toEqual(['--es', 'mock server', 'http://localhost:9001']);
});
});

describe('assertLaunchArgumentsFor', () => {
Expand Down
Loading