josdejong / svelte-jsoneditor

A web-based tool to view, edit, format, repair, query, transform, and validate JSON
https://jsoneditoronline.org
Other
818 stars 108 forks source link

"Show me" On-Click Error #312

Closed jonathanfrosty closed 9 months ago

jonathanfrosty commented 9 months ago

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:

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 commented 9 months ago

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 d839e95c59ce18ff59ac0ad338019da9dc542a18 (Not yet published)