[OLINGO-1356] not supporting alpha numeric characters

This commit is contained in:
ramya vasanth 2019-05-08 11:03:32 +05:30
parent e35f36abc5
commit a9eac6cb0a
2 changed files with 27 additions and 3 deletions

View File

@ -53,6 +53,9 @@ public class SearchTokenizer {
protected static final char CHAR_R = 'R';
protected static final char CHAR_CLOSE = ')';
protected static final char CHAR_OPEN = '(';
protected static final char CHAR_COMMA = ',';
protected static final char CHAR_DOT = '.';
protected static final char CHAR_HYPEN = '-';
public State() {}
@ -120,7 +123,7 @@ public class SearchTokenizer {
static boolean isAllowedWord(final char character) {
return Character.isUnicodeIdentifierStart(character);
}
/**
* <code>
* <b>searchPhrase</b> = quotation-mark 1*qchar-no-AMP-DQUOTE quotation-mark
@ -317,6 +320,14 @@ public class SearchTokenizer {
}
}
/**
*
* As per the updated abnf
* https://github.com/oasis-tcs/odata-abnf/blob/master/abnf/odata-abnf-construction-rules.txt#L332-L356.
* searchWord = 1*( ALPHA / DIGIT / COMMA / "." / "-" / pct-encoded )
* This includes Unicode characters of categories
* L or N using UTF-8 and percent-encoding.
*/
private class SearchWordState extends LiteralState {
public SearchWordState(final char c) throws SearchTokenizerException {
super(Token.WORD, c);
@ -336,7 +347,11 @@ public class SearchTokenizer {
@Override
public State nextChar(final char c) throws SearchTokenizerException {
if (isAllowedWord(c)) {
if (isAllowedWord(c) ||
('0' <= c && c <= '9') ||
(c == CHAR_COMMA) ||
(c == CHAR_DOT) ||
(c == CHAR_HYPEN)) {
return allowed(c);
} else if (c == CHAR_CLOSE) {
finish();

View File

@ -53,8 +53,17 @@ public class SearchTokenizerTest {
assertQuery("A").resultsIn(word("A"));
assertQuery("AN").resultsIn(word("AN"));
assertQuery("O").resultsIn(word("O"));
assertQuery("notAw0rd").resultsIn(word("notAw0rd"));
assertQuery("not,").resultsIn(word("not,"));
assertQuery("not.").resultsIn(word("not."));
assertQuery("B-B").resultsIn(word("B-B"));
assertQuery("Dž").resultsIn(word("Dž"));
// invalid
assertQuery("notAw0rd").resultsIn(SearchTokenizerException.MessageKeys.FORBIDDEN_CHARACTER);
assertQuery("%2F").resultsIn(SearchTokenizerException.MessageKeys.FORBIDDEN_CHARACTER);
assertQuery("%3A").resultsIn(SearchTokenizerException.MessageKeys.FORBIDDEN_CHARACTER);
assertQuery("not%5B").resultsIn(SearchTokenizerException.MessageKeys.FORBIDDEN_CHARACTER);
assertQuery("not%7B").resultsIn(SearchTokenizerException.MessageKeys.FORBIDDEN_CHARACTER);
assertQuery("not%6A").resultsIn(SearchTokenizerException.MessageKeys.FORBIDDEN_CHARACTER);
}
private Validator.Tuple word(final String literal) {