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

Fix loading objects with instance variables named "null" #191

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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/psych/visitors/yaml_tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ def dump_ivars target
ivars = find_ivars target

ivars.each do |iv|
@emitter.scalar("#{iv.to_s.sub(/^@/, '')}", nil, nil, true, false, Nodes::Scalar::ANY)
@emitter.scalar("#{iv.to_s.sub(/^@/, ':')}", nil, nil, true, false, Nodes::Scalar::ANY)
accept target.instance_variable_get(iv)
end
end
Expand Down
15 changes: 15 additions & 0 deletions test/psych/test_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ def initialize parent
end
end

class WithNull
attr_accessor :null

def initialize
@null = true
end
end

class TestObject < TestCase
def test_dump_with_tag
tag = Tagged.new
Expand All @@ -40,5 +48,12 @@ def test_cyclic_references
assert_instance_of(Foo, loaded)
assert_equal loaded, loaded.parent
end

def test_null_named_ivar
original = WithNull.new
loaded = Psych.load(Psych.dump(original))

assert_equal(original.null, loaded.null)
end
end
end