File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -6,9 +6,13 @@ 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 ] ;
11- const labelElem = id ? root . querySelector ( `[for="${ id } "]` ) : null ;
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+
15+ const labelElem = root . querySelector ( `[for="${ id } "]` ) ;
1216 const labelText = labelElem ? labelElem . innerText : null ;
1317
1418 return {
You can’t perform that action at this time.
0 commit comments