Fix NumberFormatException in Simple Query String Query

Incorrect usage of XContentParser.hasTextCharacters() can result in NumberFormatException as well as other possible issues in template query parser and phrase suggest parsers.

Fixes #7875
This commit is contained in:
Igor Motov 2014-09-25 20:33:46 +04:00
parent 3db50b2ebf
commit 9c9cd01854
4 changed files with 13 additions and 3 deletions

View File

@ -154,6 +154,16 @@ public interface XContentParser extends Releasable {
Object objectBytes() throws IOException;
/**
* Method that can be used to determine whether calling of textCharacters() would be the most efficient way to
* access textual content for the event parser currently points to.
*
* Default implementation simply returns false since only actual
* implementation class has knowledge of its internal buffering
* state.
*
* This method shouldn't be used to check if the token contains text or not.
*/
boolean hasTextCharacters();
char[] textCharacters() throws IOException;

View File

@ -160,7 +160,7 @@ public class SimpleQueryStringParser implements QueryParser {
"[" + NAME + "] default operator [" + op + "] is not allowed");
}
} else if ("flags".equals(currentFieldName)) {
if (parser.hasTextCharacters()) {
if (parser.currentToken() != XContentParser.Token.VALUE_NUMBER) {
// Possible options are:
// ALL, NONE, AND, OR, PREFIX, PHRASE, PRECEDENCE, ESCAPE, WHITESPACE, FUZZY, NEAR, SLOP
flags = SimpleQueryStringFlag.resolveFlags(parser.text());

View File

@ -115,7 +115,7 @@ public class TemplateQueryParser implements QueryParser {
currentFieldName = parser.currentName();
} else if (parameterMap.containsKey(currentFieldName)) {
type = parameterMap.get(currentFieldName);
if (token == XContentParser.Token.START_OBJECT && !parser.hasTextCharacters()) {
if (token == XContentParser.Token.START_OBJECT) {
XContentBuilder builder = XContentBuilder.builder(parser.contentType().xContent());
builder.copyCurrentStructure(parser);
templateNameOrTemplateContent = builder.string();

View File

@ -132,7 +132,7 @@ public final class PhraseSuggestParser implements SuggestContextParser {
fieldName = parser.currentName();
} else if ("query".equals(fieldName) || "filter".equals(fieldName)) {
String templateNameOrTemplateContent;
if (token == XContentParser.Token.START_OBJECT && !parser.hasTextCharacters()) {
if (token == XContentParser.Token.START_OBJECT) {
XContentBuilder builder = XContentBuilder.builder(parser.contentType().xContent());
builder.copyCurrentStructure(parser);
templateNameOrTemplateContent = builder.string();