diff --git a/lib/addressable/uri.rb b/lib/addressable/uri.rb index 59fd32aa..d9a7f877 100644 --- a/lib/addressable/uri.rb +++ b/lib/addressable/uri.rb @@ -2588,7 +2588,7 @@ def reset_ivs @query = nil end - NONE = Object.new.freeze + NONE = Module.new.freeze private_constant :NONE end diff --git a/spec/addressable/uri_spec.rb b/spec/addressable/uri_spec.rb index 5acf2ac0..26ee923d 100644 --- a/spec/addressable/uri_spec.rb +++ b/spec/addressable/uri_spec.rb @@ -6769,6 +6769,37 @@ def to_str end end +describe Addressable::URI, "support serialization roundtrip" do + before do + @uri = Addressable::URI.new( + :scheme => "http", + :user => "user", + :password => "password", + :host => "example.com", + :port => 80, + :path => "/path", + :query => "query=value", + :fragment => "fragment" + ) + end + + it "is in a working state after being serialized with Marshal" do + @uri = Addressable::URI.parse("http://example.com") + cloned_uri = Marshal.load(Marshal.dump(@uri)) + expect(cloned_uri.normalized_scheme).to be == @uri.normalized_scheme + end + + it "is in a working state after being serialized with YAML" do + @uri = Addressable::URI.parse("http://example.com") + cloned_uri = if YAML.respond_to?(:unsafe_load) + YAML.unsafe_load(YAML.dump(@uri)) + else + YAML.load(YAML.dump(@uri)) + end + expect(cloned_uri.normalized_scheme).to be == @uri.normalized_scheme + end +end + describe Addressable::URI, "when initialized in a non-main `Ractor`" do it "should have the same value as if used in the main `Ractor`" do pending("Ruby 3.0+ for `Ractor` support") unless defined?(Ractor)