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

Quote conversion in JSON pane breaks valid JSON content #1798

Closed
analog-cbarber opened this issue Nov 21, 2020 · 1 comment · Fixed by #2143
Closed

Quote conversion in JSON pane breaks valid JSON content #1798

analog-cbarber opened this issue Nov 21, 2020 · 1 comment · Fixed by #2143
Labels
type: bug Something isn't correct or isn't working

Comments

@analog-cbarber
Copy link

The Javascript code for the JSON pane blindly replaces all single quotes with double quotes, presumably to convert Python single quoted strings to standard JSON double quoted strings.

const text = this.model.text.replace(/(\r\n|\n|\r)/gm, "").replace("'", '"')

However, it is perfectly legal to have single quotes inside of JSON string values, so this will turn correctly encoded JSON string into invalid JSON.

Screen Shot 2020-11-20 at 7 02 53 PM

The simplest fix would simply be to remove the quote conversion hack. Otherwise, you are going to need to be smart enough to only convert quotes that are not inside of strings.

@analog-cbarber
Copy link
Author

The only workaround I can think of in the meantime is to pass in an already encoded string with single quotes replaced by \u0027:

pn.pane.JSON(object="""["can\\u0027t show this"]""")

@jlstevens jlstevens added the type: bug Something isn't correct or isn't working label Nov 23, 2020
@jlstevens jlstevens added this to the next milestone Nov 23, 2020
@philippjfr philippjfr removed this from the next milestone Apr 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't correct or isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants