Skip to content

Conversation

@D-Groenewegen
Copy link

If a value contains an apostrophe, the current implementation fails with 'Syntax error, unrecognized expression'. This fix prevents the issue by using double quotes around the value.

I don't think we need to cater for double quotes in values, at least not if the values are returned by the API in the JSON format. If I'm mistaken though and there are exceptions, then something like this should work:

let optionSelected = $(select).find('option[value="' + values[i].replaceAll('"', '\\"') + '"]')

If a value contains an apostrophe, the current implementation fails with 'Syntax error, unrecognized expression'. This fix prevents the issue by using double quotes around the value. 

I don't think we need to cater for double quotes in values, at least not if the values are returned by the API in the JSON format. If I'm mistaken though and there are exceptions, then something like this should work:

```
let optionSelected = $(select).find('option[value="' + values[i].replaceAll('"', '\\"') + '"]')
```
@Designburo
Copy link
Collaborator

I'd rather do something like
let optionSelected = $(select).find('option[value=\'' + values[i].replace("'", "\\\'") + '\']')

@D-Groenewegen
Copy link
Author

I don't remember the example I was using at the time to test this but your suggestion looks reasonable. The only change I made is to use replaceAll rather than replace. The next thing to do is a matching pull request for the 1.43 branch.

D-Groenewegen added a commit to a-g-van-hamel-foundation/FlexForm that referenced this pull request Dec 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants