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

Do not send parsed JSON5 setting data as JSON #217

Open
jasongrout opened this issue Oct 5, 2021 · 3 comments
Open

Do not send parsed JSON5 setting data as JSON #217

jasongrout opened this issue Oct 5, 2021 · 3 comments
Labels

Comments

@jasongrout
Copy link
Contributor

Description

The server produces invalid json for a settings get request if the raw setting text includes a value allowed by JSON5, but not by JSON (such as Infinity)

Reproduce

Add a user-level setting, such as Notebook.numberCellsToRenderDirectly, and set it to Infinity. This is a value that is allowed by JSON5, but is not allowed by JSON. Then start JupyterLab and note the many errors in the console about not being able to parse the results of the settings request.

Basically, this line adds converts the JSON5 raw setting to JSON:

settings = json5.loads(raw)

It does a pretty good job of stripping comments, etc, but it leaves in the Infinity. Python can serialize Infinity just fine, but the browser chokes on the response, giving an error like JSON.parse: unexpected character at line 1 column 25047 of the JSON data

Since we've standardized on JSON5, I think perhaps we should not try to include a parsed version of the setting. Instead, just send the raw text over and do a json5 conversion in the browser.

Expected behavior

Infinity to be properly recognized by the setting system.

Context

  • Operating System and version: macOS Catalina
  • Browser and version: Firefox 92
  • JupyterLab version: 3.2 unreleased master
@jasongrout jasongrout added the bug label Oct 5, 2021
@welcome
Copy link

welcome bot commented Oct 5, 2021

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively.
welcome
You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! 👋

Welcome to the Jupyter community! 🎉

@fcollonval
Copy link
Member

The parsing to blame is the one in the connector: https://github.com/jupyterlab/jupyterlab/blob/master/packages/services/src/setting/index.ts#L63

@jasongrout
Copy link
Contributor Author

The parsing to blame is the one in the connector: https://github.com/jupyterlab/jupyterlab/blob/master/packages/services/src/setting/index.ts#L63

I responded on the PR, but copying it here too. I think it would be better if the server did not send nonstandard JSON at all (for example, it could send the setting just as raw text to be interpreted as JSON5 on the frontend). If we send nonstandard JSON in response to a settings request, it breaks the expectation of the rest api that the response is valid JSON.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants