Skip to content

Commit

Permalink
cli: do not double quote chromeFlags (GoogleChrome#3775)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce authored and christhompson committed Nov 17, 2017
1 parent 8e201b3 commit f481741
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
5 changes: 4 additions & 1 deletion lighthouse-cli/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ export function parseChromeFlags(flags: string = '') {
// Avoid '=true', then reintroduce quotes
.map(key => {
if (parsed[key] === true) return `--${key}`;
return `--${key}="${parsed[key]}"`;
// ChromeLauncher passes flags to Chrome as atomic arguments, so do not double quote
// i.e. `lighthouse --chrome-flags="--user-agent='My Agent'"` becomes `chrome "--user-agent=My Agent"`
// see https://github.com/GoogleChrome/lighthouse/issues/3744
return `--${key}=${parsed[key]}`;
});
}

Expand Down
14 changes: 7 additions & 7 deletions lighthouse-cli/test/cli/run-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ describe('Parsing --chrome-flags', () => {
});

it('returns boolean flags that are false with value', () => {
assert.deepStrictEqual(parseChromeFlags('--debug=false'), ['--debug="false"']);
assert.deepStrictEqual(parseChromeFlags('--debug=false'), ['--debug=false']);
});

it('returns boolean flags that empty when passed undefined', () => {
it('returns empty when passed undefined', () => {
assert.deepStrictEqual(parseChromeFlags(), []);
});

Expand All @@ -63,25 +63,25 @@ describe('Parsing --chrome-flags', () => {
});

it('handles numeric values', () => {
assert.deepStrictEqual(parseChromeFlags('--log-level=0'), ['--log-level="0"']);
assert.deepStrictEqual(parseChromeFlags('--log-level=0'), ['--log-level=0']);
});

it('quotes flag values with spaces in them (#2817)', () => {
it('handles flag values with spaces in them (#2817)', () => {
assert.deepStrictEqual(
parseChromeFlags('--user-agent="iPhone UA Test"'),
['--user-agent="iPhone UA Test"']
['--user-agent=iPhone UA Test']
);

assert.deepStrictEqual(
parseChromeFlags('--host-resolver-rules="MAP www.example.org:443 127.0.0.1:8443"'),
['--host-resolver-rules="MAP www.example.org:443 127.0.0.1:8443"']
['--host-resolver-rules=MAP www.example.org:443 127.0.0.1:8443']
);
});

it('returns all flags as provided', () => {
assert.deepStrictEqual(
parseChromeFlags('--spaces="1 2 3 4" --debug=false --verbose --more-spaces="9 9 9"'),
['--spaces="1 2 3 4"', '--debug="false"', '--verbose', '--more-spaces="9 9 9"']
['--spaces=1 2 3 4', '--debug=false', '--verbose', '--more-spaces=9 9 9']
);
});
});

0 comments on commit f481741

Please sign in to comment.