From 42f294c3142e8f90b86f83144c9f4e6c10562b1c Mon Sep 17 00:00:00 2001 From: sjh9714 <163989462+sjh9714@users.noreply.github.com> Date: Sun, 11 Oct 2026 18:12:19 +0900 Subject: [PATCH] Avoid wrapping strings in JSON output --- lib/psych.rb | 2 +- test/psych/test_json_tree.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) 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