Skip to content

Commit c6cf843

Browse files
committed
Merge pull request #15679 from jpountz/fix/text_parsing
Make text parsing less lenient.
2 parents ba755a5 + 5eb7555 commit c6cf843

File tree

7 files changed

+16
-47
lines changed

7 files changed

+16
-47
lines changed

core/src/main/java/org/elasticsearch/common/geo/GeoUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ public static GeoPoint parseGeoPoint(XContentParser parser, GeoPoint point) thro
384384
if(parser.currentToken() == Token.START_OBJECT) {
385385
while(parser.nextToken() != Token.END_OBJECT) {
386386
if(parser.currentToken() == Token.FIELD_NAME) {
387-
String field = parser.text();
387+
String field = parser.currentName();
388388
if(LATITUDE.equals(field)) {
389389
parser.nextToken();
390390
switch (parser.currentToken()) {

core/src/main/java/org/elasticsearch/common/xcontent/XContentLocation.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,9 @@ public XContentLocation(int lineNumber, int columnNumber) {
3434
this.lineNumber = lineNumber;
3535
this.columnNumber = columnNumber;
3636
}
37+
38+
@Override
39+
public String toString() {
40+
return lineNumber + ":" + columnNumber;
41+
}
3742
}

core/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContentParser.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ protected boolean doBooleanValue() throws IOException {
7979

8080
@Override
8181
public String text() throws IOException {
82-
return parser.getText();
82+
if (currentToken().isValue()) {
83+
return parser.getText();
84+
}
85+
throw new IllegalStateException("Can't get text on a " + currentToken() + " at " + getTokenLocation());
8386
}
8487

8588
@Override

core/src/main/java/org/elasticsearch/common/xcontent/support/AbstractXContentParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public double doubleValue(boolean coerce) throws IOException {
194194
protected abstract double doDoubleValue() throws IOException;
195195

196196
@Override
197-
public String textOrNull() throws IOException {
197+
public final String textOrNull() throws IOException {
198198
if (currentToken() == Token.VALUE_NULL) {
199199
return null;
200200
}

core/src/main/java/org/elasticsearch/index/query/GeohashCellQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ public Builder fromXContent(QueryParseContext parseContext) throws IOException {
297297

298298
while ((token = parser.nextToken()) != Token.END_OBJECT) {
299299
if (token == Token.FIELD_NAME) {
300-
String field = parser.text();
300+
String field = parser.currentName();
301301

302302
if (parseContext.isDeprecatedSetting(field)) {
303303
// skip

core/src/test/java/org/elasticsearch/index/mapper/multifield/MultiFieldTests.java

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -335,43 +335,6 @@ public void testConvertMultiFieldGeoPoint() throws Exception {
335335
assertThat(f.stringValue(), equalTo("-1,-1"));
336336
assertThat(f.fieldType().stored(), equalTo(false));
337337
assertNotSame(IndexOptions.NONE, f.fieldType().indexOptions());
338-
339-
json = jsonBuilder().startObject()
340-
.startArray("b").startArray().value(-1).value(-1).endArray().startArray().value(-2).value(-2).endArray().endArray()
341-
.endObject().bytes();
342-
doc = docMapper.parse("test", "type", "1", json).rootDoc();
343-
344-
f = doc.getFields("b")[0];
345-
assertThat(f, notNullValue());
346-
assertThat(f.name(), equalTo("b"));
347-
if (indexCreatedBefore22 == true) {
348-
assertThat(f.stringValue(), equalTo("-1.0,-1.0"));
349-
} else {
350-
assertThat(Long.parseLong(f.stringValue()), equalTo(GeoUtils.mortonHash(-1.0, -1.0)));
351-
}
352-
assertThat(f.fieldType().stored(), equalTo(stored));
353-
assertNotSame(IndexOptions.NONE, f.fieldType().indexOptions());
354-
355-
f = doc.getFields("b")[1];
356-
assertThat(f, notNullValue());
357-
assertThat(f.name(), equalTo("b"));
358-
if (indexCreatedBefore22 == true) {
359-
assertThat(f.stringValue(), equalTo("-2.0,-2.0"));
360-
} else {
361-
assertThat(Long.parseLong(f.stringValue()), equalTo(GeoUtils.mortonHash(-2.0, -2.0)));
362-
}
363-
assertThat(f.fieldType().stored(), equalTo(stored));
364-
assertNotSame(IndexOptions.NONE, f.fieldType().indexOptions());
365-
366-
f = doc.getField("b.a");
367-
assertThat(f, notNullValue());
368-
assertThat(f.name(), equalTo("b.a"));
369-
// NOTE: "]" B/c the lat,long aren't specified as a string, we miss the actual values when parsing the multi
370-
// fields. We already skipped over the coordinates values and can't get to the coordinates.
371-
// This happens if coordinates are specified as array and object.
372-
assertThat(f.stringValue(), equalTo("]"));
373-
assertThat(f.fieldType().stored(), equalTo(false));
374-
assertNotSame(IndexOptions.NONE, f.fieldType().indexOptions());
375338
}
376339

377340
public void testConvertMultiFieldCompletion() throws Exception {

plugins/lang-python/src/test/resources/rest-api-spec/test/lang_python/30_update.yaml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
id: 1
1919
body:
2020
script:
21-
script:
22-
inline: "ctx[\"_source\"][\"myfield\"]=\"bar\""
23-
lang: python
21+
inline: "ctx[\"_source\"][\"myfield\"]=\"bar\""
22+
lang: python
2423
- do:
2524
get:
2625
index: test
@@ -48,9 +47,8 @@
4847
id: 1
4948
body:
5049
script:
51-
script:
52-
inline: "a=42; ctx[\"_source\"][\"myfield\"]=\"bar\""
53-
lang: python
50+
inline: "a=42; ctx[\"_source\"][\"myfield\"]=\"bar\""
51+
lang: python
5452
- do:
5553
get:
5654
index: test

0 commit comments

Comments
 (0)