Skip to content

Commit

Permalink
fix(css selector): properly parse quoted attributes when querying in …
Browse files Browse the repository at this point in the history
…shadow (#2007)
  • Loading branch information
dgozman authored Apr 28, 2020
1 parent d8cccbd commit 8aab725
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/injected/cssSelectorEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ function split(selector: string): string[] {
} else if (c === quote) {
quote = undefined;
index++;
} else if (c === '\'' || c === '"') {
quote = c;
index++;
} else {
index++;
}
Expand Down
26 changes: 26 additions & 0 deletions test/queryselector.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,32 @@ describe('Page.$eval', function() {
expect(await page.$eval(`div >> [placeholder="Select date"]`, e => e.outerHTML)).toBe('<input placeholder="Select date">');
expect(await page.$eval(`div >> [placeholder='Select date']`, e => e.outerHTML)).toBe('<input placeholder="Select date">');
});
it('should work with quotes in css attributes', async({page, server}) => {
await page.setContent('<div><input placeholder="Select&quot;date"></div>');
expect(await page.$(`[placeholder="Select\\"date"]`)).toBeTruthy();
expect(await page.$(`[placeholder='Select"date']`)).toBeTruthy();
await page.setContent('<div><input placeholder="Select &quot; date"></div>');
expect(await page.$(`[placeholder="Select \\" date"]`)).toBeTruthy();
expect(await page.$(`[placeholder='Select " date']`)).toBeTruthy();
await page.setContent('<div><input placeholder="Select&apos;date"></div>');
expect(await page.$(`[placeholder="Select'date"]`)).toBeTruthy();
expect(await page.$(`[placeholder='Select\\'date']`)).toBeTruthy();
await page.setContent('<div><input placeholder="Select &apos; date"></div>');
expect(await page.$(`[placeholder="Select ' date"]`)).toBeTruthy();
expect(await page.$(`[placeholder='Select \\' date']`)).toBeTruthy();
});
it('should work with spaces in css attributes when missing', async({page, server}) => {
const inputPromise = page.waitForSelector(`[placeholder="Select date"]`);
expect(await page.$(`[placeholder="Select date"]`)).toBe(null);
await page.setContent('<div><input placeholder="Select date"></div>');
await inputPromise;
});
it('should work with quotes in css attributes when missing', async({page, server}) => {
const inputPromise = page.waitForSelector(`[placeholder="Select\\"date"]`);
expect(await page.$(`[placeholder="Select\\"date"]`)).toBe(null);
await page.setContent('<div><input placeholder="Select&quot;date"></div>');
await inputPromise;
});
});

describe('Page.$$eval', function() {
Expand Down

0 comments on commit 8aab725

Please sign in to comment.