Skip to content

Commit d7baf01

Browse files
committed
Fix sliced string escaping
1 parent d867e39 commit d7baf01

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

java/src/json/ext/SWARBasicStringEncoder.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ void encode(ByteList src) throws IOException {
2727
// slice a string, the underlying byte array is the same, but the
2828
// begin index and real size are different. When reading from the ptrBytes
2929
// array, we need to always add ptr to the index.
30-
ByteBuffer bb = ByteBuffer.wrap(ptrBytes, ptr, len);
30+
ByteBuffer bb = ByteBuffer.wrap(ptrBytes, 0, ptr + len);
31+
3132
while (pos + 8 <= len) {
32-
long x = bb.getLong(pos);
33+
long x = bb.getLong(ptr + pos);
3334
if (skipChunk(x)) {
3435
pos += 8;
3536
continue;
@@ -48,7 +49,7 @@ void encode(ByteList src) throws IOException {
4849
}
4950

5051
if (pos + 4 <= len) {
51-
int x = bb.getInt(pos);
52+
int x = bb.getInt(ptr + pos);
5253
if (skipChunk(x)) {
5354
pos += 4;
5455
}

test/json/json_encoding_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ def test_generate_shared_string
3535
# Ref: https://github.com/ruby/json/issues/859
3636
s = "01234567890"
3737
assert_equal '"234567890"', JSON.dump(s[2..-1])
38+
s = '01234567890123456789"a"b"c"d"e"f"g"h'
39+
assert_equal '"\"a\"b\"c\"d\"e\"f\"g\""', JSON.dump(s[20, 15])
3840
end
3941

4042
def test_unicode

0 commit comments

Comments
 (0)