Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace escape_quotes with json.dumps in DOM.create_element #1386

Merged
merged 2 commits into from
May 29, 2024

Conversation

lanzz
Copy link
Contributor

@lanzz lanzz commented May 17, 2024

escape_quotes is inadequate here, as it will happily leave multiline strings as they are, which is a syntax error in javascript. It also doesn't seem to adequately deal with things like existing backslash escapes in the string.

json.dumps is guaranteed to produce valid json, which is also guaranteed to be a valid javascript data structure. By ensuring the type of html to be str, we guarantee that the output of json.dumps will be a valid javascript string, properly quoted and escaped.

lanzz added 2 commits May 17, 2024 17:58
`escape_quotes` is inadequate here, as it will happily leave multiline strings
as they are, which is a syntax error in javascript. it also doesn't seem to
adequately deal with things like existing backslash escapes in the string.

`json.dumps` is guaranteed to produce valid json, which is also guaranteed to be
a valid javascript data structure. by ensuring the type of `html` to be `str`,
we guarantee that the output of `json.dumps` will be a valid javascript string,
properly quoted and escaped.
@r0x0r r0x0r merged commit 99f18d0 into r0x0r:master May 29, 2024
1 check failed
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.

None yet

2 participants