Skip to content

Commit 86b2f93

Browse files
committed
* ext/psych/lib/psych/visitors/yaml_tree.rb: fix NameError dumping and
loading. Fixes GH ruby#85. Thanks @brentdax for the patch! * test/psych/test_exception.rb: test for fix git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47319 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent bdae441 commit 86b2f93

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
Sat Aug 30 06:39:48 2014 Aaron Patterson <[email protected]>
2+
3+
* ext/psych/lib/psych/visitors/yaml_tree.rb: fix NameError dumping and
4+
loading. Fixes GH #85. Thanks @brentdax for the patch!
5+
* test/psych/test_exception.rb: test for fix
6+
17
Sat Aug 30 06:23:40 2014 Aaron Patterson <[email protected]>
28

39
* ext/psych/lib/psych/scalar_scanner.rb: fix loading strings that

ext/psych/lib/psych/visitors/yaml_tree.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,25 @@ def visit_Exception o
211211
@emitter.end_mapping
212212
end
213213

214+
def visit_NameError o
215+
tag = ['!ruby/exception', o.class.name].join ':'
216+
217+
@emitter.start_mapping nil, tag, false, Nodes::Mapping::BLOCK
218+
219+
{
220+
'message' => o.message.to_s,
221+
'backtrace' => private_iv_get(o, 'backtrace'),
222+
}.each do |k,v|
223+
next unless v
224+
@emitter.scalar k, nil, nil, true, false, Nodes::Scalar::ANY
225+
accept v
226+
end
227+
228+
dump_ivars o
229+
230+
@emitter.end_mapping
231+
end
232+
214233
def visit_Regexp o
215234
register o, @emitter.scalar(o.inspect, nil, '!ruby/regexp', false, false, Nodes::Scalar::ANY)
216235
end

test/psych/test_exception.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ def setup
1616
@wups = Wups.new
1717
end
1818

19+
def test_naming_exception
20+
err = String.xxx rescue $!
21+
new_err = Psych.load(Psych.dump(err))
22+
assert_equal err.message, new_err.message
23+
end
24+
1925
def test_load_takes_file
2026
ex = assert_raises(Psych::SyntaxError) do
2127
Psych.load '--- `'

0 commit comments

Comments
 (0)