Skip to content

Commit ae432e1

Browse files
committed
Fix subsequent calls to parser.getText() after a call to parser.getValueAsByteRef()
1 parent a9ee991 commit ae432e1

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/json/ESUTF8StreamJsonParser.java

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import com.fasterxml.jackson.core.JsonToken;
1313
import com.fasterxml.jackson.core.ObjectCodec;
14+
import com.fasterxml.jackson.core.SerializableString;
1415
import com.fasterxml.jackson.core.io.IOContext;
1516
import com.fasterxml.jackson.core.json.UTF8StreamJsonParser;
1617
import com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer;
@@ -21,6 +22,8 @@
2122
import java.io.InputStream;
2223

2324
public class ESUTF8StreamJsonParser extends UTF8StreamJsonParser {
25+
protected int stringEnd = -1;
26+
2427
public ESUTF8StreamJsonParser(
2528
IOContext ctxt,
2629
int features,
@@ -43,11 +46,7 @@ public ESUTF8StreamJsonParser(
4346
*/
4447
public ESBytesRef getValueAsByteRef() throws IOException {
4548
if (_currToken == JsonToken.VALUE_STRING && _tokenIncomplete) {
46-
var value = _finishAndReturnByteRef();
47-
if (value != null) {
48-
_tokenIncomplete = false;
49-
}
50-
return value;
49+
return _finishAndReturnByteRef();
5150
}
5251
return null;
5352
}
@@ -67,7 +66,7 @@ protected ESBytesRef _finishAndReturnByteRef() throws IOException {
6766
int c = inputBuffer[ptr] & 0xFF;
6867
if (codes[c] != 0) {
6968
if (c == INT_QUOTE) {
70-
_inputPtr = ptr + 1;
69+
stringEnd = ptr + 1;
7170
return new ESBytesRef(inputBuffer, startPtr, ptr);
7271
}
7372
return null;
@@ -76,4 +75,34 @@ protected ESBytesRef _finishAndReturnByteRef() throws IOException {
7675
}
7776
return null;
7877
}
78+
79+
@Override
80+
public JsonToken nextToken() throws IOException {
81+
if (_currToken == JsonToken.VALUE_STRING && _tokenIncomplete && stringEnd > 0) {
82+
_inputPtr = stringEnd;
83+
_tokenIncomplete = false;
84+
}
85+
stringEnd = -1;
86+
return super.nextToken();
87+
}
88+
89+
@Override
90+
public boolean nextFieldName(SerializableString str) throws IOException {
91+
if (_currToken == JsonToken.VALUE_STRING && _tokenIncomplete && stringEnd > 0) {
92+
_inputPtr = stringEnd;
93+
_tokenIncomplete = false;
94+
}
95+
stringEnd = -1;
96+
return super.nextFieldName(str);
97+
}
98+
99+
@Override
100+
public String nextFieldName() throws IOException {
101+
if (_currToken == JsonToken.VALUE_STRING && _tokenIncomplete && stringEnd > 0) {
102+
_inputPtr = stringEnd;
103+
_tokenIncomplete = false;
104+
}
105+
stringEnd = -1;
106+
return super.nextFieldName();
107+
}
79108
}

0 commit comments

Comments
 (0)