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

"Show me" On-Click Error #312

Closed
jonathanfrosty opened this issue Sep 20, 2023 · 1 comment
Closed

"Show me" On-Click Error #312

jonathanfrosty opened this issue Sep 20, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@jonathanfrosty
Copy link

It seems that from version 0.14.4 onwards an error is thrown after clicking the "Show me" action button when the editor is modified in "Text" mode to contain certain invalid JSON.

https://codesandbox.io/s/svelte-jsoneditor-react-forked-qz65tt

The linked codesandbox is the React playground example provided in this library's README.
To reproduce, perform the following steps:

  • ensure you are using version 0.14.4 or later
  • change to "text" mode
  • modify the true value to tru
  • an error alert should appear and the first character of the entire JSON text (not where the error is) should be identified in red
  • click the "Show me" button in the error alert (or click the error message itself)
  • the following error should be thrown: Cannot read properties of undefined (reading 'length')

Another example that causes this would be adding a letter at the end of line 6 (or 7, or 8, etc.), though adding a number works fine.

If you switch to version 0.14.3, this error is not thrown and your cursor is moved to where the red error is.

Looking at the release history, it seems the "Show me" button was first added in 0.14.4.

I also noticed that when modifying the JSON to be in the invalid state, the ContentParseError object provided inside the third argument of the onChange event contains null values for column, line, and position. This is the case for both 0.14.3 and 0.14.4 onwards.

@josdejong josdejong added the bug Something isn't working label Sep 20, 2023
@josdejong
Copy link
Owner

josdejong commented Sep 20, 2023

Thanks for reporting. I could reproduce the issue on Chrome (doesn't happen on Firefox).

In most cases, parse error messages look like the following:

Uncaught SyntaxError: Expected ',' or '}' after property value in JSON at position 22

You see that the error reports the position where the error occurred. The exact error message and way of reporting the position differs though between the different browsers. JSONEditor normalizes this, and when found, fills in these values in the ParseError object. If not found, it leaves column, line and position null. The case you found is an error without position information:

Unexpected token ',', ..."lean": tru,
  "color"... is not valid JSON

The "Show me" button wasn't reconing with the fact that position may be null. I've now fixed this via d839e95 (Not yet published)

josdejong added a commit that referenced this issue Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants