Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion packages/playwright-core/src/tools/cli-client/minimist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ export function minimist(args: string[], opts?: MinimistOptions): MinimistArgs {
} else {
setArg(key, strings[key] ? '' : true);
}
} else if ((/^-[^-]+/).test(arg)) {
} else if ((/^-[A-Za-z]/).test(arg)) {
// Short flags are letters, so '-100' and '-.5' are arguments, not flags.
const letters = arg.slice(1, -1).split('');

let broken = false;
Expand Down
13 changes: 12 additions & 1 deletion tests/mcp/cli-parsing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { test, expect } from './cli-fixtures';
import { test, expect, eventsPage } from './cli-fixtures';

test('unknown option', async ({ cli, server }) => {
const { error, exitCode } = await cli('open', '--some-option', 'value', 'about:blank');
Expand Down Expand Up @@ -73,6 +73,17 @@ test('wrong argument type', async ({ cli, server }) => {
expect(press.exitCode).toBe(0);
});

test('negative number arguments', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/42321' } }, async ({ cli, server }) => {
server.setContent('/', eventsPage, 'text/html');
await cli('open', server.PREFIX);

expect((await cli('mousewheel', '0', '-100')).exitCode).toBe(0);
await expect.poll(() => cli('snapshot').then(result => result.inlineSnapshot)).toContain('wheel 0 -100');

expect((await cli('mousewheel', '-1.5', '-.5')).exitCode).toBe(0);
await expect.poll(() => cli('snapshot').then(result => result.inlineSnapshot)).toContain('wheel -1.5 -0.5');
});

test('should preserve leading zeros in string arguments', async ({ cli, server }) => {
server.setContent('/', `<input type=text>`, 'text/html');
await cli('open', server.PREFIX);
Expand Down
Loading