Skip to content

Commit bf21003

Browse files
authored
fix: escape invalid id's to prevent WSOD (#22)
1 parent 22e3174 commit bf21003

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/lib/queryAdvise.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ export function getData({ root, element }) {
66
const type = element.getAttribute('type');
77
const tagName = element.tagName;
88

9-
// prevent querySelector from tripping over corrupted html like <input id="button\n<button>
10-
const id = (element.getAttribute('id') || '').split('\n')[0];
9+
// escape id to prevent querySelector from tripping over corrupted html like:
10+
// <input id="button\n<button> & <input id=\ntype="text" />
11+
const id = (element.getAttribute('id') || '')
12+
.replace(/\s/g, '')
13+
.replace(/"/g, '\\"');
14+
1115
const labelElem = id ? root.querySelector(`[for="${id}"]`) : null;
1216
const labelText = labelElem ? labelElem.innerText : null;
1317

0 commit comments

Comments
 (0)