mholt / json-to-go

Translates JSON into a Go type in your browser instantly (original)
https://mholt.github.io/json-to-go/
MIT License
4.51k stars 475 forks source link

Pasting from terminal window into entry box includes hidden formatting which breaks parsing #103

Open foogod opened 2 years ago

foogod commented 2 years ago

I was just trying to use https://mholt.github.io/json-to-go/ and found that it seemed to be unable to parse anything I was pasting into it, despite it being valid JSON. Even more strange was that it seemed to be complaining about whitespace characters being present in the input (which should be fine), but then if I typed the same thing by hand (with the same whitespace) it liked it fine. Even weirder was that if I started with a failing case, and edited out all of the whitespace, it liked it, but then if I manually inserted a space character, it broke again.

Eventually I noticed that when I cut-and-pasted JSON from a terminal window (on MacOS) into the web entry box, it was also copying over the formatting (coloring, text size, etc). However, if I used Command-Option-Shift-V to paste just the text without any formatting, lo and behold it was able to parse it just fine.

I can only assume there's something about the rich-text entrybox being used and how it returns data to the underlying code that causes weird characters to be introduced only if there is formatting involved and there are whitespace characters present.

Perhaps this should be changed to use a non-rich-text entrybox of some sort, or to filter out whatever special characters the text box itself is introducing into things?

mholt commented 2 years ago

I noticed this too; probably some JS needed to prevent pasting of rich text (sigh): https://stackoverflow.com/questions/58980235/stop-pasting-html-style-in-a-contenteditable-div-only-paste-the-plain-text