diff --git a/lib/addressable/uri.rb b/lib/addressable/uri.rb index 50ccdaf5..89b86767 100644 --- a/lib/addressable/uri.rb +++ b/lib/addressable/uri.rb @@ -2569,7 +2569,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 c54fc3fb..b1bbb0a1 100644 --- a/spec/addressable/uri_spec.rb +++ b/spec/addressable/uri_spec.rb @@ -20,6 +20,7 @@ require "addressable/uri" require "uri" require "ipaddr" +require "yaml" if !"".respond_to?("force_encoding") class String @@ -6768,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)