Skip to content

Commit 9ebe105

Browse files
samyronbyroot
authored andcommitted
Ensure the SWAR encoder in the java extension checks every byte.
1 parent a458201 commit 9ebe105

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

java/src/json/ext/StringEncoder.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,11 @@ void encodeBasicSWAR(ByteList src) throws IOException {
249249

250250
if (pos + 4 <= len) {
251251
int x = bb.getInt(ptr + pos);
252-
int is_ascii = 0x808080 & ~x;
253-
int xor2 = x ^ 0x020202;
254-
int lt32_or_eq34 = xor2 - 0x212121;
255-
int sub92 = x ^ 0x5C5C5C;
256-
int eq92 = (sub92 - 0x010101);
252+
int is_ascii = 0x80808080 & ~x;
253+
int xor2 = x ^ 0x02020202;
254+
int lt32_or_eq34 = xor2 - 0x21212121;
255+
int sub92 = x ^ 0x5C5C5C5C;
256+
int eq92 = (sub92 - 0x01010101);
257257
boolean skip_chunk = ((lt32_or_eq34 | eq92) & is_ascii) == 0;
258258
if (skip_chunk) {
259259
pos += 4;

test/json/json_generator_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,18 @@ def test_backslash
504504
json = '["\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\""]'
505505
assert_equal json, generate(data)
506506
#
507+
data = '"""""'
508+
json = '"\"\"\"\"\""'
509+
assert_equal json, generate(data)
510+
#
511+
data = "abc\n"
512+
json = '"abc\\n"'
513+
assert_equal json, generate(data)
514+
#
515+
data = "\nabc"
516+
json = '"\\nabc"'
517+
assert_equal json, generate(data)
518+
#
507519
data = ["'"]
508520
json = '["\\\'"]'
509521
assert_equal '["\'"]', generate(data)

0 commit comments

Comments
 (0)