Skip to content

Commit

Permalink
fix: do not handle flags with whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagowfx committed Oct 13, 2023
1 parent 8641494 commit ff53762
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/puppeteer-core/src/node/ChromeLauncher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ describe('getFeatures', () => {
expect(result).toEqual(['bar', 'baz']);
});

it('handles whitespace around the flag and value', () => {
it('does not handle whitespace', () => {
const result = getFeatures('--foo', ['--foo bar', '--foo baz ']);
expect(result).toEqual(['bar', 'baz']);
expect(result).toEqual([]);
});

it('handles equals sign around the flag and value', () => {
Expand Down
7 changes: 4 additions & 3 deletions packages/puppeteer-core/src/node/ChromeLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ function convertPuppeteerChannelToBrowsersChannel(
}

/**
* Extracts all features from the given command-line flag.
* Extracts all features from the given command-line flag
* (e.g. `--enable-features`, `--enable-features=`).
*
* Example input:
* ["--enable-features=NetworkService,NetworkServiceInProcess", "--enable-features=Foo"]
Expand All @@ -285,10 +286,10 @@ function convertPuppeteerChannelToBrowsersChannel(
export function getFeatures(flag: string, options: string[] = []): string[] {
const opts = options
.filter(s => {
return s.startsWith(flag);
return s.startsWith(flag.endsWith('=') ? flag : `${flag}=`);
})
.map(s => {
return s.split(new RegExp(`${flag}` + '[=\\s]*'))[1]!.trim();
return s.split(new RegExp(`${flag}` + '=\\s*'))[1]?.trim();
});
return opts.length === 0 ? [] : opts.join(',').split(',');
}

0 comments on commit ff53762

Please sign in to comment.