4 ms·
per specifications, json parsing is not lenient, html parsing is lenient
by preseinger 4y ago
per specifications, json parsing is not lenient, html parsing is lenient
- taeric 4y agoRight, and amusingly, more than a few json parsers are very lenient in this. That or folks abandon ship fairly quickly and go for another spec that is far more friendly.
- preseinger 4y agowell json definitely does not accept `{'test':'value'}` as valid input any parser that behaves otherwise is pretty clearly buggy json has many problems but parsing ambiguity is not really one of them
- taeric 4y agoMe thinks you have never looked at the field. I'd as soon declare csv is an error free format. Only true if you ignore the proliferation of applications that get it wrong. In subtle ways, often. Still wrong.
- preseinger 4y agocsv is wildly ambiguous, to the frustration of ~every data science engineer in industry json is not show me an application that parses `{'a':'b'}` as valid JSON, i'm actually interested, probably there are some which exist, but there is no ambiguity about those applications being wrong
- taeric 4y agohttps://news.ycombinator.com/item?id=12796556 https://news.ycombinator.com/item?id=12796556
- preseinger 4y agofun doc! it lists many of the undefined behaviors of the spec, and many of the problems in common parsers afaict none of them permit keys or value strings to be expressed with single quotes
- taeric 4y agoApologies for the, in retrospect, somewhat lazy posting of an article with no comment. I thought that article had a section about how many of them allow single quotes if you don't "enable strict." I am not seeing it on review, though; so either I made that up in my mind, or I'm remembering another article. Either way, apologies. I did find https://github.com/json5/json5 https://github.com/json5/json5 no a quick search that basically says what I asserted about people just jumping to another standard for things that you hand write. I was probably also thinking heavily about python's dict syntax. (And I confess, I still don't know when to use single versus double quotes in python...)
- preseinger 4y agono worries mate
- goto11 4y agoTo be pedantic, html parsing is not lenient, it is unambiguously specified.
- preseinger 4y agoif that were true then browsers would refuse to render text/html responses that didn't include a closing </html> tag, i guess
- goto11 4y agoNo, because the closing </html> tag can be omitted according to the current HTML spec. See https://html.spec.whatwg.org/#optional-tags https://html.spec.whatwg.org/#optional-tags
- preseinger 4y agothis is exactly my point html is not precisely defined
- 4rt 3y agoI think you're missing the point that it is defined, the current html5 spec says that <title> implies the existence of <head>, <body> implies the end of <head>, body tags imply the end of <head> and the start of <body> etc. HTML5 is not XHTML. <!DOCTYPE html> <title>Title <h1>Heading expands to <!DOCTYPE html> <head><title>Title</title></head> <body><h1>Heading</h1></body>
- preseinger 3y agoif `<title>A <h1>Heading` is equivalent to `<head><title>A</title></head> <body><h1>Heading</h1></body>` then this means the language is not precisely defined
- goto11 3y agoSorry I don't understand your argument. HTML is fully and unambiguously defined, as you can see if you follow the link. Some tags are optional in certain contexts, but this is also precisely defined.