Skip to content

Commit

Permalink
Escape attr before using in querySelectorAll. Closes #156.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgerigmeyer committed Feb 28, 2024
1 parent 3b55af9 commit 3d60849
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,9 @@ async function getAnchorEl(
if (customPropName) {
anchorName = getCSSPropertyValue(targetEl, customPropName);
} else if (anchorAttr) {
return await validatedForPositioning(targetEl, [`#${anchorAttr}`]);
return await validatedForPositioning(targetEl, [
`#${CSS.escape(anchorAttr)}`,
]);
}
}
const anchorSelectors = anchorName ? anchorNames[anchorName] ?? [] : [];
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/setup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import fetchMock from 'fetch-mock';

beforeAll(() => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
window.CSS = {
escape: (str) => str,
};
});

afterEach(() => {
fetchMock.reset();
});

0 comments on commit 3d60849

Please sign in to comment.