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

Migrating strict mode options to the new usual parser #904

Open
semaperepelitsa opened this issue Nov 21, 2023 · 4 comments
Open

Migrating strict mode options to the new usual parser #904

semaperepelitsa opened this issue Nov 21, 2023 · 4 comments

Comments

@semaperepelitsa
Copy link

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
@ohler55
Copy link
Owner

ohler55 commented Nov 21, 2023

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.

@semaperepelitsa
Copy link
Author

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.

@ohler55
Copy link
Owner

ohler55 commented Nov 21, 2023

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.

@ohler55
Copy link
Owner

ohler55 commented Dec 4, 2023

Please try the raise_on_empty branch. A test was added in test/test_parser_usual.rb:150.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants