Skip to content

Commit fe6aa70

Browse files
committed
Disable utf-8 parsing optimization (#135172)
A yet to be understood issue has emerged with the utf8 parsing optimization and the meantime we should disable the optimization. It looks like the wrong values are returned for fields. In the case of the test failures here, that surfaced as unable to the parse fields with IPs and causing index request to fail. However the impact could be larger.
1 parent c2d65bf commit fe6aa70

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,7 @@ public String text() throws IOException {
143143

144144
@Override
145145
public XContentString optimizedText() throws IOException {
146-
if (currentToken().isValue() == false) {
147-
throwOnNoText();
148-
}
149-
if (parser instanceof ESUTF8StreamJsonParser esParser) {
150-
var bytesRef = esParser.getValueAsText();
151-
if (bytesRef != null) {
152-
return bytesRef;
153-
}
154-
}
146+
// TODO: enable utf-8 parsing optimization once verified it is completely safe
155147
return new Text(text());
156148
}
157149

server/src/test/java/org/elasticsearch/common/xcontent/json/JsonXContentTests.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,21 @@ public void testMalformedJsonFieldThrowsXContentException() throws Exception {
4141
assertThrows(XContentParseException.class, () -> parser.text());
4242
}
4343
}
44+
45+
public void testOptimizedTextHasBytes() throws Exception {
46+
XContentBuilder builder = builder().startObject().field("text", new Text("foo")).endObject();
47+
XContentParserConfiguration parserConfig = parserConfig();
48+
if (randomBoolean()) {
49+
parserConfig = parserConfig.withFiltering(null, Set.of("*"), null, true);
50+
}
51+
try (XContentParser parser = createParser(parserConfig, xcontentType().xContent(), BytesReference.bytes(builder))) {
52+
assertSame(XContentParser.Token.START_OBJECT, parser.nextToken());
53+
assertSame(XContentParser.Token.FIELD_NAME, parser.nextToken());
54+
assertTrue(parser.nextToken().isValue());
55+
Text text = (Text) parser.optimizedText();
56+
// TODO: uncomment after utf8 optimized parsing has been enabled again:
57+
// assertTrue(text.hasBytes());
58+
assertThat(text.string(), equalTo("foo"));
59+
}
60+
}
4461
}

0 commit comments

Comments
 (0)