summaryrefslogtreecommitdiff
path: root/test/objspace
diff options
context:
space:
mode:
authorJohn Hawthorn <john@hawthorn.email>2020-07-09 14:59:59 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2020-08-17 09:47:53 -0700
commit971857c3326b163c45f02922bb5c5143d54e520d (patch)
tree0245113f14e505d3b7a178708068e4bf1d325e9f /test/objspace
parentb52a501ca786a54fdaadf1a60fef517c55dd6ca3 (diff)
downloadruby-971857c3326b163c45f02922bb5c5143d54e520d.tar.gz
Fix method name escaping in ObjectSpace.dump
It's possible to define methods with any name, even if the parser doesn't support it and it can only be used with ex. send. This fixes an issue where invalid JSON was output from ObjectSpace.dump when a method name needed escaping.
Diffstat (limited to 'test/objspace')
-rw-r--r--test/objspace/test_objspace.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb
index 5073bbee06..42fbc3e03c 100644
--- a/test/objspace/test_objspace.rb
+++ b/test/objspace/test_objspace.rb
@@ -362,6 +362,24 @@ class TestObjSpace < Test::Unit::TestCase
end
end
+ def test_dump_escapes_method_name
+ method_name = "foo\"bar"
+ klass = Class.new do
+ define_method(method_name) { "TEST STRING" }
+ end
+ ObjectSpace.trace_object_allocations_start
+
+ obj = klass.new.send(method_name)
+
+ dump = ObjectSpace.dump(obj)
+ assert_includes dump, '"method":"foo\"bar"'
+
+ parsed = JSON.parse(dump)
+ assert_equal "foo\"bar", parsed["method"]
+ ensure
+ ObjectSpace.trace_object_allocations_stop
+ end
+
def test_dump_reference_addresses_match_dump_all_addresses
assert_in_out_err(%w[-robjspace], "#{<<-"begin;"}\n#{<<-'end;'}") do |output, error|
begin;