mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(locators): make regex escape work when multiple spaces are present (#17893)
This commit is contained in:
parent
dffa469718
commit
b64457d8ce
@ -68,7 +68,7 @@ export function escapeForTextSelector(text: string | RegExp, exact: boolean, cas
|
|||||||
if (exact)
|
if (exact)
|
||||||
return '"' + text.replace(/["]/g, '\\"') + '"';
|
return '"' + text.replace(/["]/g, '\\"') + '"';
|
||||||
if (text.includes('"') || text.includes('>>') || text[0] === '/')
|
if (text.includes('"') || text.includes('>>') || text[0] === '/')
|
||||||
return `/${escapeForRegex(text).replace(/\s+/, '\\s+')}/` + (caseSensitive ? '' : 'i');
|
return `/${escapeForRegex(text).replace(/\s+/g, '\\s+')}/` + (caseSensitive ? '' : 'i');
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,29 +108,31 @@ it('getByTitle should work', async ({ page }) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('getBy escaping', async ({ page }) => {
|
it('getBy escaping', async ({ page }) => {
|
||||||
await page.setContent(`<label id=label for=control>Hello
|
await page.setContent(`<label id=label for=control>Hello my
|
||||||
wo"rld</label><input id=control />`);
|
wo"rld</label><input id=control />`);
|
||||||
await page.$eval('input', input => {
|
await page.$eval('input', input => {
|
||||||
input.setAttribute('placeholder', 'hello\nwo"rld');
|
input.setAttribute('placeholder', 'hello my\nwo"rld');
|
||||||
input.setAttribute('title', 'hello\nwo"rld');
|
input.setAttribute('title', 'hello my\nwo"rld');
|
||||||
input.setAttribute('alt', 'hello\nwo"rld');
|
input.setAttribute('alt', 'hello my\nwo"rld');
|
||||||
});
|
});
|
||||||
await expect(page.getByText('hello\nwo"rld')).toHaveAttribute('id', 'label');
|
await expect(page.getByText('hello my\nwo"rld')).toHaveAttribute('id', 'label');
|
||||||
await expect(page.getByLabel('hello\nwo"rld')).toHaveAttribute('id', 'control');
|
await expect(page.getByText('hello my wo"rld')).toHaveAttribute('id', 'label');
|
||||||
await expect(page.getByPlaceholder('hello\nwo"rld')).toHaveAttribute('id', 'control');
|
await expect(page.getByLabel('hello my\nwo"rld')).toHaveAttribute('id', 'control');
|
||||||
await expect(page.getByAltText('hello\nwo"rld')).toHaveAttribute('id', 'control');
|
await expect(page.getByPlaceholder('hello my\nwo"rld')).toHaveAttribute('id', 'control');
|
||||||
await expect(page.getByTitle('hello\nwo"rld')).toHaveAttribute('id', 'control');
|
await expect(page.getByAltText('hello my\nwo"rld')).toHaveAttribute('id', 'control');
|
||||||
|
await expect(page.getByTitle('hello my\nwo"rld')).toHaveAttribute('id', 'control');
|
||||||
|
|
||||||
await page.setContent(`<label id=label for=control>Hello
|
await page.setContent(`<label id=label for=control>Hello my
|
||||||
world</label><input id=control />`);
|
world</label><input id=control />`);
|
||||||
await page.$eval('input', input => {
|
await page.$eval('input', input => {
|
||||||
input.setAttribute('placeholder', 'hello\nworld');
|
input.setAttribute('placeholder', 'hello my\nworld');
|
||||||
input.setAttribute('title', 'hello\nworld');
|
input.setAttribute('title', 'hello my\nworld');
|
||||||
input.setAttribute('alt', 'hello\nworld');
|
input.setAttribute('alt', 'hello my\nworld');
|
||||||
});
|
});
|
||||||
await expect(page.getByText('hello\nworld')).toHaveAttribute('id', 'label');
|
await expect(page.getByText('hello my\nworld')).toHaveAttribute('id', 'label');
|
||||||
await expect(page.getByLabel('hello\nworld')).toHaveAttribute('id', 'control');
|
await expect(page.getByText('hello my world')).toHaveAttribute('id', 'label');
|
||||||
await expect(page.getByPlaceholder('hello\nworld')).toHaveAttribute('id', 'control');
|
await expect(page.getByLabel('hello my\nworld')).toHaveAttribute('id', 'control');
|
||||||
await expect(page.getByAltText('hello\nworld')).toHaveAttribute('id', 'control');
|
await expect(page.getByPlaceholder('hello my\nworld')).toHaveAttribute('id', 'control');
|
||||||
await expect(page.getByTitle('hello\nworld')).toHaveAttribute('id', 'control');
|
await expect(page.getByAltText('hello my\nworld')).toHaveAttribute('id', 'control');
|
||||||
|
await expect(page.getByTitle('hello my\nworld')).toHaveAttribute('id', 'control');
|
||||||
});
|
});
|
||||||
|
@ -740,11 +740,11 @@ test('test.setTimeout should work separately in afterAll', async ({ runInlineTes
|
|||||||
});
|
});
|
||||||
test.afterAll(async () => {
|
test.afterAll(async () => {
|
||||||
console.log('\\n%%afterAll');
|
console.log('\\n%%afterAll');
|
||||||
test.setTimeout(1000);
|
test.setTimeout(3000);
|
||||||
await new Promise(f => setTimeout(f, 800));
|
await new Promise(f => setTimeout(f, 2000));
|
||||||
});
|
});
|
||||||
`,
|
`,
|
||||||
}, { timeout: '100' });
|
}, { timeout: '1000' });
|
||||||
expect(result.exitCode).toBe(0);
|
expect(result.exitCode).toBe(0);
|
||||||
expect(result.passed).toBe(1);
|
expect(result.passed).toBe(1);
|
||||||
expect(result.output.split('\n').filter(line => line.startsWith('%%'))).toEqual([
|
expect(result.output.split('\n').filter(line => line.startsWith('%%'))).toEqual([
|
||||||
|
Loading…
x
Reference in New Issue
Block a user