Skip to content

Commit 61819ae

Browse files
committed
bug #2663 [Autocomplete] Escape querySelector option value (Bartheyrman22)
This PR was merged into the 2.x branch. Discussion ---------- [Autocomplete] Escape querySelector option value Properly escape the querySelector for option-values like "["Test"]"/ This to mitigate: ``` SyntaxError: Element.querySelector: ':scope > option[value="["foo"]"]' is not a valid selector ``` | Q | A | ------------- | --- | Bug fix? | yes | New feature? |no | Issues | | License | MIT Some remark where I don't have a solution for: The issue is only reproduceable on Chrome. In Firefox, the code in the controller.js is not executed properly. So the error get's never triggered. But no side effects detected so far. Commits ------- c330c1d [Autocomplete] Escape `querySelector` dynamic selector with `CSS.escape()`
2 parents e9403a6 + c330c1d commit 61819ae

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

src/Autocomplete/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## 2.25.0
4+
5+
- Escape `querySelector` dynamic selector with `CSS.escape()` #2663
6+
37
## 2.23.0
48

59
- Deprecate `ExtraLazyChoiceLoader` in favor of `Symfony\Component\Form\ChoiceList\Loader\LazyChoiceLoader`

src/Autocomplete/assets/dist/controller.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ _default_1_instances = new WeakSet(), _default_1_getCommonConfig = function _def
270270
let orderedOption = null;
271271
for (const [, tomSelectOption] of Object.entries(this.tomSelect.options)) {
272272
if (tomSelectOption.$order === optionOrder) {
273-
orderedOption = parentElement.querySelector(`:scope > option[value="${tomSelectOption[this.tomSelect.settings.valueField]}"]`);
273+
orderedOption = parentElement.querySelector(`:scope > option[value="${CSS.escape(tomSelectOption[this.tomSelect.settings.valueField])}"]`);
274274
break;
275275
}
276276
}

src/Autocomplete/assets/src/controller.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ export default class extends Controller {
192192
for (const [, tomSelectOption] of Object.entries(this.tomSelect.options)) {
193193
if (tomSelectOption.$order === optionOrder) {
194194
orderedOption = parentElement.querySelector(
195-
`:scope > option[value="${tomSelectOption[this.tomSelect.settings.valueField]}"]`
195+
`:scope > option[value="${CSS.escape(tomSelectOption[this.tomSelect.settings.valueField])}"]`
196196
);
197197

198198
break;

0 commit comments

Comments
 (0)