Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(css selector): properly parse quoted attributes when querying in shadow #2007

Merged
merged 1 commit into from
Apr 28, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/injected/cssSelectorEngine.ts
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
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