oj
oj copied to clipboard
Migrating strict mode options to the new usual parser
We are currently using :quirks_mode=>false, :empty_string=>false
options. But they are not available in the new parser. Is there a recommended alternative?
> Oj.load("", :mode=>:strict, :quirks_mode=>false, :empty_string=>false)
JSON::ParserError: Empty input (after ) at line 1, column 1 [parse.c:1062]
> Oj.load("123", :mode=>:strict, :quirks_mode=>false, :empty_string=>false)
Oj::ParseError: unexpected non-document value
> Oj::Parser.new(:usual).parse("")
=> nil
> Oj::Parser.new(:usual).parse("123")
=> 123
I need to look into it. In general the new parser does not have all the options the old one does. That is intentional as the number of detailed options caused confusion and were often the cause of issues where they were not working exactly the way different developers wanted them to.
These options are easy enough to implement on client-side. If they are not offered by other implementations, dropping them seems fine. But :empty_string=>false
behavior is how it works by default in Ruby's built-in JSON and in Javascript, so it seems wrong not to have it here.
I'll look at it tonight. I'm trying to avoid falling into the trap of being just like the JSON gem but I could see the reason it might be reasonable to raise on anything other than a non-empty string.
Please try the raise_on_empty
branch. A test was added in test/test_parser_usual.rb:150.