diff --git a/lib/psych.rb b/lib/psych.rb index 850a6d19..6139d1be 100644 --- a/lib/psych.rb +++ b/lib/psych.rb @@ -623,7 +623,7 @@ def self.dump_stream *objects def self.to_json object visitor = Psych::Visitors::JSONTree.create visitor << object - visitor.tree.yaml + visitor.tree.yaml(nil, line_width: -1) end ### diff --git a/test/psych/test_json_tree.rb b/test/psych/test_json_tree.rb index 37c05075..b1c6efb3 100644 --- a/test/psych/test_json_tree.rb +++ b/test/psych/test_json_tree.rb @@ -7,6 +7,16 @@ def test_string assert_match(/"foo"/, Psych.to_json("foo")) end + def test_long_string + string = 'word ' * 30 + assert_equal "\"#{string}\"\n", Psych.to_json(string) + end + + def test_long_string_in_sequence + string = 'word ' * 30 + assert_include Psych.to_json([[1, string]]), "\"#{string}\"" + end + def test_symbol assert_match(/"foo"/, Psych.to_json(:foo)) end