Skip to content

Commit

Permalink
Merge pull request #716 from byroot/fix-script-safe-kanji
Browse files Browse the repository at this point in the history
Fix generate(script_safe: true) to not confuse unrelated characters
  • Loading branch information
byroot authored Dec 3, 2024
2 parents d0c38f2 + 93a7f87 commit 20b501a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ext/json/ext/generator/generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ static void convert_UTF8_to_JSON(FBuffer *out_buffer, VALUE str, const char esca
}
case 3: {
unsigned char b2 = ptr[pos + 1];
if (RB_UNLIKELY(out_script_safe && b2 == 0x80)) {
if (RB_UNLIKELY(out_script_safe && ch == 0xE2 && b2 == 0x80)) {
unsigned char b3 = ptr[pos + 2];
if (b3 == 0xA8) {
FLUSH_POS(3);
Expand Down
4 changes: 4 additions & 0 deletions test/json/json_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,10 @@ def test_backslash
data = ["'"]
json = '["\\\'"]'
assert_equal '["\'"]', generate(data)
#
data = ["倩", "瀨"]
json = '["倩","瀨"]'
assert_equal json, generate(data, script_safe: true)
end

def test_string_subclass
Expand Down

0 comments on commit 20b501a

Please sign in to comment.