Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ext/json/ext/generator/generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,9 @@ static inline void escape_UTF8_char(search_state *search, unsigned char ch_len)
{
const unsigned char ch = (unsigned char)*search->ptr;
switch (ch_len) {
case 1: {
case ESCAPE_LEN_1: {
search_flush(search);

switch (ch) {
case '"': fbuffer_append(search->buffer, "\\\"", 2); break;
case '\\': fbuffer_append(search->buffer, "\\\\", 2); break;
Expand Down
8 changes: 8 additions & 0 deletions test/json/json_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,14 @@ def run_script_safe_test(ascii_only)
data = '</scriPt'
json = '"\\u003c/scriPt"'
assert_equal json, generate(data, script_safe: true, ascii_only: ascii_only)

data = "a\"b\\c\nd\te\u0001f"
json = '"a\\"b\\\\c\\nd\\te\\u0001f"'
assert_equal json, generate(data, script_safe: true, ascii_only: ascii_only)

data = "<a href=\"/\">\n</script>"
json = '"<a href=\\"/\\">\\n\\u003c/script>"'
assert_equal json, generate(data, script_safe: true, ascii_only: ascii_only)
end

def test_backslash
Expand Down
Loading