Issue Task Closed

#102207Escape dynamic values in selector queries

Benjamin Franzke 10/19/23, 11:02 updated 01/30/24, 08:30

Description

Whenever dynamic data is passed to query selectors, it needs to be escaped.

Example for a wrong example:

const baz = readFromSomeDynamicData(),
const foo = document.querySelector('foo[bar="' + baz + '"]');

Better/Correct:

const baz = readFromSomeDynamicData(),
const foo = document.querySelector('foo[bar="' + CSS.escape(baz) + '"]');

Ideal/Desired would be to use a string literal for syntax sugar reasons:

const baz = readFromSomeDynamicData(),
const foo = document.querySelector(selector`foo[bar="${baz]"]`);

Reviews 2

History 212

  1. Gerrit Code Review pushed patch set 2 for main to change 81477 status New Under Review 10/19/23, 11:03

  2. Gerrit Code Review pushed patch set 3 for main to change 81477 10/19/23, 11:27

  3. Gerrit Code Review pushed patch set 4 for main to change 81477 10/20/23, 06:22

  4. Gerrit Code Review pushed patch set 5 for main to change 81477 10/20/23, 11:41

  5. Gerrit Code Review pushed patch set 6 for main to change 81477 10/20/23, 12:08

  6. Gerrit Code Review pushed patch set 7 for main to change 81477 10/21/23, 13:01

  7. Gerrit Code Review pushed patch set 8 for main to change 81477 10/21/23, 13:06

  8. Gerrit Code Review pushed patch set 9 for main to change 81477 10/23/23, 06:19

  9. Gerrit Code Review pushed patch set 10 for main to change 81477 10/27/23, 04:48

  10. Gerrit Code Review pushed patch set 1 for 12.4 to change 81592 10/27/23, 09:01

  11. Anonymous commented and changed status Under Review Resolved done 0 % 100 % 10/30/23, 16:30

    Applied in changeset commit:a86d38f2483dee546293e8c74ce44935abb40536.

  12. Benni Mack changed status Resolved Closed 01/30/24, 08:30