Skip to content

Commit 20b501a

Browse files
authored
Merge pull request #716 from byroot/fix-script-safe-kanji
Fix generate(script_safe: true) to not confuse unrelated characters
2 parents d0c38f2 + 93a7f87 commit 20b501a

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

ext/json/ext/generator/generator.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ static void convert_UTF8_to_JSON(FBuffer *out_buffer, VALUE str, const char esca
155155
}
156156
case 3: {
157157
unsigned char b2 = ptr[pos + 1];
158-
if (RB_UNLIKELY(out_script_safe && b2 == 0x80)) {
158+
if (RB_UNLIKELY(out_script_safe && ch == 0xE2 && b2 == 0x80)) {
159159
unsigned char b3 = ptr[pos + 2];
160160
if (b3 == 0xA8) {
161161
FLUSH_POS(3);

test/json/json_generator_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,10 @@ def test_backslash
455455
data = ["'"]
456456
json = '["\\\'"]'
457457
assert_equal '["\'"]', generate(data)
458+
#
459+
data = ["倩", "瀨"]
460+
json = '["倩","瀨"]'
461+
assert_equal json, generate(data, script_safe: true)
458462
end
459463

460464
def test_string_subclass

0 commit comments

Comments
 (0)