Skip to content

Commit

Permalink
Fix generate(script_safe: true) to not confuse unrelated characters
Browse files Browse the repository at this point in the history
Fix: #715

The first byte check was missing.
  • Loading branch information
byroot committed Dec 3, 2024
1 parent d0c38f2 commit 93a7f87
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 93a7f87

Please sign in to comment.