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

Fix JSON.create_id= to allow nil #869

Merged
merged 2 commits into from
Mar 19, 2023
Merged

Conversation

Watson1978
Copy link
Collaborator

JSON.create_id= method accepts nil as an argument in document.

* - *id* [_nil_|String] new create_id

However, it raises TypeError when passed nil.

irb(main):001:0> require 'oj'
=> true
irb(main):002:0> Oj.mimic_JSON
=> JSON
irb(main):003:0> JSON.create_id = nil
(irb):3:in `create_id=': wrong argument type nil (expected String) (TypeError)
        from (irb):3:in `<main>'                             
        from /home/watson/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/irb-1.6.2/exe/irb:11:in `<top (required)>'
        from /home/watson/.rbenv/versions/3.2.1/bin/irb:25:in `load'
        from /home/watson/.rbenv/versions/3.2.1/bin/irb:25:in `<main>'
irb(main):004:0> 

This patch will accept nil as an argument.

`JSON.create_id=` method accepts `nil` as an argument in document.
https://github.com/ohler55/oj/blob/2c1a622660ed5ab94b9fdfbcc7bc16017307972a/ext/oj/mimic_json.c#L655

However, it raises TypeError when passed `nil`.

```
irb(main):001:0> require 'oj'
=> true
irb(main):002:0> Oj.mimic_JSON
=> JSON
irb(main):003:0> JSON.create_id = nil
(irb):3:in `create_id=': wrong argument type nil (expected String) (TypeError)
        from (irb):3:in `<main>'                             
        from /home/watson/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/irb-1.6.2/exe/irb:11:in `<top (required)>'
        from /home/watson/.rbenv/versions/3.2.1/bin/irb:25:in `load'
        from /home/watson/.rbenv/versions/3.2.1/bin/irb:25:in `<main>'
irb(main):004:0> 
```

This patch will accept `nil` as an argument.
@ohler55 ohler55 merged commit 03084d9 into ohler55:develop Mar 19, 2023
@ohler55
Copy link
Owner

ohler55 commented Mar 19, 2023

arigato

@Watson1978 Watson1978 deleted the create_id branch March 22, 2023 00:46
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

Successfully merging this pull request may close these issues.

2 participants