Skip to content

Commit

Permalink
Remove some unused code and add more tests
Browse files Browse the repository at this point in the history
The removed code does not actually seem to affect the logic. Also, I
want to be 100% sure that every call to parseToken is guaranteed to
call parser.nextToken() at some point.

Signed-off-by: Michael Froh <[email protected]>
  • Loading branch information
msfroh committed Sep 19, 2024
1 parent 8e4efce commit 18cfd45
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ setup:
},
"required_matches": 1
}
# The following document is invalid.
# The following documents are invalid.
- do:
catch: /parsing_exception/
index:
Expand All @@ -73,7 +73,36 @@ setup:
"catalog": ["Arrays in Action"],
"required_matches": 1
}

- do:
catch: /parsing_exception/
index:
index: test
id: 3
body: {
"ISBN13": "V12154942123242",
"catalog": "Strings in Action",
"required_matches": 1
}
- do:
catch: /parsing_exception/
index:
index: test
id: 3
body: {
"ISBN13": "V12154942123242",
"catalog": 12345,
"required_matches": 1
}
- do:
catch: /parsing_exception/
index:
index: test
id: 3
body: {
"ISBN13": "V12154942123242",
"catalog": [ 12345 ],
"required_matches": 1
}
# Do index refresh
- do:
indices.refresh:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ public XContentParser parseObject() throws IOException {
* @return true if the child object contains no_null value, false otherwise
*/
private boolean parseToken(Deque<String> path, String currentFieldName) throws IOException {
if (path.size() == 1 && processNoNestedValue()) {
return true;
}
boolean isChildrenValueValid = false;
boolean visitFieldName = false;
if (this.parser.currentToken() == Token.FIELD_NAME) {
Expand Down Expand Up @@ -147,21 +144,6 @@ public void removeKeyOfNullValue() {
this.keyList.remove(keyList.size() - 1);
}

private boolean processNoNestedValue() throws IOException {
if (parser.currentToken() == Token.VALUE_NULL) {
return true;
} else if (this.parser.currentToken() == Token.VALUE_STRING
|| this.parser.currentToken() == Token.VALUE_NUMBER
|| this.parser.currentToken() == Token.VALUE_BOOLEAN) {
String value = this.parser.textOrNull();
if (value != null) {
this.valueList.add(value);
}
return true;
}
return false;
}

private String parseValue() throws IOException {
switch (this.parser.currentToken()) {
case VALUE_BOOLEAN:
Expand Down

0 comments on commit 18cfd45

Please sign in to comment.