tonobo / hcloud-ruby

Native ruby client for HetznerCloud
MIT License
31 stars 11 forks source link

[Bug] IPv6 global address is not parsed correctly #49

Closed ghost closed 1 year ago

ghost commented 1 year ago

When using the IPv6 address ::/0 in a firewall rule, we will get the Ruby symbol :":/0" as a parsed response. I was able to trace it down to Oj.load changing the string in parsed_json in entry_loader.rb.

To my understanding, this is probably related to this discussion: https://github.com/ohler55/oj/issues/285

I have to admit, I do not get the arguments of the Oj developers, either. If Oj.load('{"foo": ":"}') does not work, this looks broken. If I get them right, then using the default mode: :object is almost always the wrong thing to do. When parsing JSON data that was not generated with Oj, it seems we need to use mode: :compat.

Here's a minimal reproducing example:

require 'oj'

data = '{"foo": ["::/0"]}'
p "Input data is:"
p data

puts "\n"
p "Oj parsed result with default mode is:"
p Oj.load(data)

puts "\n"
p "Oj parsed result with compat mode is:"
p Oj.load(data, mode: :compat)

with the output:

"Input data is:"
"{\"foo\": [\"::/0\"]}"

"Oj parsed result with default mode is:"
{"foo"=>[:":/0"]}

"Oj parsed result with compat mode is:"
{"foo"=>["::/0"]}