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
25 changes: 0 additions & 25 deletions ext/json/ext/parser/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,6 @@ static VALUE rstring_cache_fetch(rvalue_cache *cache, const char *str, const lon
}
}

if (RB_UNLIKELY(memchr(str, '\\', length))) {
// We assume the overwhelming majority of names don't need to be escaped.
// But if they do, we have to fallback to the slow path.
return Qfalse;
}

VALUE rstring = build_interned_string(str, length);

if (cache->length < JSON_RVALUE_CACHE_CAPA) {
Expand Down Expand Up @@ -174,12 +168,6 @@ static VALUE rsymbol_cache_fetch(rvalue_cache *cache, const char *str, const lon
}
}

if (RB_UNLIKELY(memchr(str, '\\', length))) {
// We assume the overwhelming majority of names don't need to be escaped.
// But if they do, we have to fallback to the slow path.
return Qfalse;
}

VALUE rsymbol = build_symbol(str, length);

if (cache->length < JSON_RVALUE_CACHE_CAPA) {
Expand Down Expand Up @@ -652,19 +640,6 @@ static VALUE json_string_unescape(JSON_ParserState *state, const char *string, c
int unescape_len;
char buf[4];

if (is_name && state->in_array) {
VALUE cached_key;
if (RB_UNLIKELY(symbolize)) {
cached_key = rsymbol_cache_fetch(&state->name_cache, string, bufferSize);
} else {
cached_key = rstring_cache_fetch(&state->name_cache, string, bufferSize);
}

if (RB_LIKELY(cached_key)) {
return cached_key;
}
}

VALUE result = rb_str_buf_new(bufferSize);
rb_enc_associate_index(result, utf8_encindex);
buffer = RSTRING_PTR(result);
Expand Down
12 changes: 12 additions & 0 deletions test/json/json_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,18 @@ def test_parse_big_integers
assert_equal orig, parse(json5)
end

def test_parse_escaped_key
doc = {
"test\r1" => 1,
"entries" => [
"test\t2" => 2,
"test\n3" => 3,
]
}

assert_equal doc, parse(JSON.generate(doc))
end

def test_parse_duplicate_key
expected = {"a" => 2}
expected_sym = {a: 2}
Expand Down
Loading