Skip to content

Commit 89a2eeb

Browse files
byrootmatzbot
authored andcommitted
[ruby/json] Fix handling of unescaped control characters preceeded by a backslash
ruby/json@b575be5302
1 parent a4c8964 commit 89a2eeb

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

ext/json/parser/parser.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,9 @@ NOINLINE(static) VALUE json_string_unescape(JSON_ParserState *state, JSON_Parser
770770
}
771771
raise_parse_error_at("invalid ASCII control character in string: %s", state, pe - 1);
772772
}
773-
} else if (config->allow_invalid_escape) {
773+
}
774+
775+
if (config->allow_invalid_escape) {
774776
APPEND_CHAR(*pe);
775777
} else {
776778
raise_parse_error_at("invalid escape character in string: %s", state, pe - 1);

test/json/json_parser_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,15 @@ def test_parse_allowed_control_chars_in_string
183183
end
184184
end
185185

186+
def test_parsse_control_char_and_backslash
187+
backslash_and_control_char = "\\\t"
188+
assert_raise JSON::ParserError do
189+
JSON.parse(%("#{'a' * 30}#{backslash_and_control_char}"), allow_control_characters: true, allow_invalid_escape: false)
190+
end
191+
192+
JSON.parse(%("#{'a' * 30}#{backslash_and_control_char}"), allow_control_characters: true, allow_invalid_escape: true)
193+
end
194+
186195
def test_parse_invalid_escape
187196
assert_raise JSON::ParserError do
188197
parse(%("fo\\o"))

0 commit comments

Comments
 (0)