Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Jan 19, 2025
1 parent e757777 commit 4b9181c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ static boolean containsEscaped(long v, long quote) {
x22 = (x22 - 0x0101010101010101L) & ~x22;
x5c = (x5c - 0x0101010101010101L) & ~x5c;

return ((x22 | x5c | (0x7F7F7F7F7F7F7F7FL - v + 0x1010101010101010L) | v) & 0x8080808080808080L) != 0;
return ((x22 | x5c | (0x7F7F7F7F7F7F7F7FL - v + 0x2020202020202020L) | v) & 0x8080808080808080L) != 0;
}

protected final void writeStringLatin1BrowserSecure(byte[] values) {
Expand Down
14 changes: 12 additions & 2 deletions core/src/test/java/com/alibaba/fastjson2/JSONWriterUTF8Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
import static com.alibaba.fastjson2.JSONWriter.Feature.*;
import static com.alibaba.fastjson2.util.JDKUtils.ARRAY_CHAR_BASE_OFFSET;
import static com.alibaba.fastjson2.util.JDKUtils.UNSAFE;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.*;

public class JSONWriterUTF8Test {
@Test
Expand Down Expand Up @@ -1131,4 +1130,15 @@ public void writeU4() {
IOUtils.putIntUnaligned(bytes, 2, IOUtils.hex4U(1));
assertEquals("\\u0001", new String(bytes));
}

@Test
public void testSpecial1() {
byte[] buf = new byte[] {'a', 'a', 'a', 'a', 'a', 'a', 'a', 31};
assertEquals("\"aaaaaaa\\u001f\"", new String(JSON.toJSONBytes(new String(buf))));

for (int i = 0; i < 32; i++) {
buf[7] = (byte) i;
assertTrue(JSONWriterUTF8.containsEscaped(IOUtils.getLongUnaligned(buf, 0), 0x2222_2222_2222_2222L));
}
}
}

0 comments on commit 4b9181c

Please sign in to comment.