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

Define URI::NONE as a module to avoid serialization issues #509

Merged
merged 2 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/addressable/uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2588,7 +2588,7 @@ def reset_ivs
@query = nil
end

NONE = Object.new.freeze
NONE = Module.new.freeze

private_constant :NONE
end
Expand Down
31 changes: 31 additions & 0 deletions spec/addressable/uri_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down