Skip to content

Commit 0e99fcb

Browse files
rwstaunerbyroot
authored andcommitted
Fix json generation for symbols on TruffleRuby
1 parent ac0670b commit 0e99fcb

3 files changed

Lines changed: 8 additions & 1 deletion

File tree

lib/json/truffle_ruby/generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module Generator
4848
SCRIPT_SAFE_ESCAPE_PATTERN = /[\/"\\\x0-\x1f\u2028-\u2029]/
4949

5050
def self.native_type?(value) # :nodoc:
51-
(false == value || true == value || nil == value || String === value || Array === value || Hash === value || Integer === value || Float === value || Fragment === value)
51+
(false == value || true == value || nil == value || String === value || Symbol === value || Array === value || Hash === value || Integer === value || Float === value || Fragment === value)
5252
end
5353

5454
def self.native_key?(key) # :nodoc:

test/json/json_coder_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ def test_json_coder_with_proc_with_unsupported_value
1919
assert_raise(JSON::GeneratorError) { coder.dump([Object.new]) }
2020
end
2121

22+
def test_json_coder_with_proc_returning_symbol
23+
coder = JSON::Coder.new { _1 }
24+
assert_equal %({"sym":"sym"}), coder.dump({ sym: :sym })
25+
end
26+
2227
def test_json_coder_hash_key
2328
obj = Object.new
2429
coder = JSON::Coder.new do |obj, is_key|

test/json/json_generator_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ def test_dump_strict
8282
assert_equal '"hello"', dump(:hello, strict: true)
8383
assert_equal '"hello"', :hello.to_json(strict: true)
8484
assert_equal '"World"', "World".to_json(strict: true)
85+
assert_equal '["hello"]', dump([:hello], strict: true)
86+
assert_equal '{"hello":"world"}', dump({ hello: :world }, strict: true)
8587
end
8688

8789
def test_not_frozen

0 commit comments

Comments
 (0)