Skip to content

Commit

Permalink
Merge branch 'main' into improve-serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
dentarg committed May 19, 2023
2 parents 30a38d6 + 736c42a commit 2dafe28
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/addressable/uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2396,6 +2396,25 @@ def defer_validation
@validation_deferred = false
end

def encode_with(coder)
instance_variables.each do |ivar|
value = instance_variable_get(ivar)
if value != NONE
key = ivar.to_s.slice(1..-1)
coder[key] = value
end
end
nil
end

def init_with(coder)
reset_ivs
coder.map.each do |key, value|
instance_variable_set("@#{key}", value)
end
nil
end

protected
SELF_REF = '.'
PARENT = '..'
Expand Down
7 changes: 7 additions & 0 deletions spec/addressable/uri_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6831,3 +6831,10 @@ def to_str
expect(res).to be nil
end
end

describe Addressable::URI, "YAML safe loading" do
it "doesn't serialize anonymous objects" do
url = Addressable::URI.parse("http://example.com/")
expect(YAML.dump(url)).to_not include("!ruby/object {}")
end
end

0 comments on commit 2dafe28

Please sign in to comment.