Make text parsing less lenient.

It now requires that the parser is on a value.
This commit is contained in:
Adrien Grand 2015-12-28 15:26:49 +01:00
parent 485915bbe7
commit 5eb7555ffb
7 changed files with 16 additions and 47 deletions

View File

@ -384,7 +384,7 @@ public class GeoUtils {
if(parser.currentToken() == Token.START_OBJECT) {
while(parser.nextToken() != Token.END_OBJECT) {
if(parser.currentToken() == Token.FIELD_NAME) {
String field = parser.text();
String field = parser.currentName();
if(LATITUDE.equals(field)) {
parser.nextToken();
switch (parser.currentToken()) {

View File

@ -34,4 +34,9 @@ public class XContentLocation {
this.lineNumber = lineNumber;
this.columnNumber = columnNumber;
}
@Override
public String toString() {
return lineNumber + ":" + columnNumber;
}
}

View File

@ -79,7 +79,10 @@ public class JsonXContentParser extends AbstractXContentParser {
@Override
public String text() throws IOException {
return parser.getText();
if (currentToken().isValue()) {
return parser.getText();
}
throw new IllegalStateException("Can't get text on a " + currentToken() + " at " + getTokenLocation());
}
@Override

View File

@ -194,7 +194,7 @@ public abstract class AbstractXContentParser implements XContentParser {
protected abstract double doDoubleValue() throws IOException;
@Override
public String textOrNull() throws IOException {
public final String textOrNull() throws IOException {
if (currentToken() == Token.VALUE_NULL) {
return null;
}

View File

@ -297,7 +297,7 @@ public class GeohashCellQuery {
while ((token = parser.nextToken()) != Token.END_OBJECT) {
if (token == Token.FIELD_NAME) {
String field = parser.text();
String field = parser.currentName();
if (parseContext.isDeprecatedSetting(field)) {
// skip

View File

@ -335,43 +335,6 @@ public class MultiFieldTests extends ESSingleNodeTestCase {
assertThat(f.stringValue(), equalTo("-1,-1"));
assertThat(f.fieldType().stored(), equalTo(false));
assertNotSame(IndexOptions.NONE, f.fieldType().indexOptions());
json = jsonBuilder().startObject()
.startArray("b").startArray().value(-1).value(-1).endArray().startArray().value(-2).value(-2).endArray().endArray()
.endObject().bytes();
doc = docMapper.parse("test", "type", "1", json).rootDoc();
f = doc.getFields("b")[0];
assertThat(f, notNullValue());
assertThat(f.name(), equalTo("b"));
if (indexCreatedBefore22 == true) {
assertThat(f.stringValue(), equalTo("-1.0,-1.0"));
} else {
assertThat(Long.parseLong(f.stringValue()), equalTo(GeoUtils.mortonHash(-1.0, -1.0)));
}
assertThat(f.fieldType().stored(), equalTo(stored));
assertNotSame(IndexOptions.NONE, f.fieldType().indexOptions());
f = doc.getFields("b")[1];
assertThat(f, notNullValue());
assertThat(f.name(), equalTo("b"));
if (indexCreatedBefore22 == true) {
assertThat(f.stringValue(), equalTo("-2.0,-2.0"));
} else {
assertThat(Long.parseLong(f.stringValue()), equalTo(GeoUtils.mortonHash(-2.0, -2.0)));
}
assertThat(f.fieldType().stored(), equalTo(stored));
assertNotSame(IndexOptions.NONE, f.fieldType().indexOptions());
f = doc.getField("b.a");
assertThat(f, notNullValue());
assertThat(f.name(), equalTo("b.a"));
// NOTE: "]" B/c the lat,long aren't specified as a string, we miss the actual values when parsing the multi
// fields. We already skipped over the coordinates values and can't get to the coordinates.
// This happens if coordinates are specified as array and object.
assertThat(f.stringValue(), equalTo("]"));
assertThat(f.fieldType().stored(), equalTo(false));
assertNotSame(IndexOptions.NONE, f.fieldType().indexOptions());
}
public void testConvertMultiFieldCompletion() throws Exception {

View File

@ -18,9 +18,8 @@
id: 1
body:
script:
script:
inline: "ctx[\"_source\"][\"myfield\"]=\"bar\""
lang: python
inline: "ctx[\"_source\"][\"myfield\"]=\"bar\""
lang: python
- do:
get:
index: test
@ -48,9 +47,8 @@
id: 1
body:
script:
script:
inline: "a=42; ctx[\"_source\"][\"myfield\"]=\"bar\""
lang: python
inline: "a=42; ctx[\"_source\"][\"myfield\"]=\"bar\""
lang: python
- do:
get:
index: test