Skip to content

Commit 2ad3514

Browse files
authored
Merge pull request #609 from casperisfine/handle-wrongly-encoded-strings
Restore support for improperly encoded strings
2 parents 7b68800 + c5a6d80 commit 2ad3514

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

tests/json_generator_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,15 @@ def test_invalid_encoding_string
446446
end
447447

448448
if defined?(JSON::Ext::Generator) and RUBY_PLATFORM != "java"
449+
def test_valid_utf8_in_different_encoding
450+
utf8_string = "€™"
451+
wrong_encoding_string = utf8_string.b
452+
# This behavior is historical. Not necessary desirable. We should deprecated it.
453+
# The pure and java version of the gem already don't behave this way.
454+
assert_equal utf8_string.to_json, wrong_encoding_string.to_json
455+
assert_equal JSON.dump(utf8_string), JSON.dump(wrong_encoding_string)
456+
end
457+
449458
def test_string_ext_included_calls_super
450459
included = false
451460

tests/ractor_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class JSONInRactorTest < Test::Unit::TestCase
1111
def test_generate
12-
assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
12+
assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}", ignore_stderr: true)
1313
begin;
1414
$VERBOSE = nil
1515
require "json"

0 commit comments

Comments
 (0)