From 1df2f4aa67e9ed5c3cc10f3abc65f9e1fd7ee042 Mon Sep 17 00:00:00 2001 From: ramya vasanth Date: Tue, 14 Jan 2020 14:57:02 +0530 Subject: [PATCH] [OLINGO-1417]Serach query to support + --- .../uri/parser/search/SearchTokenizer.java | 35 ++++++++++++------- .../parser/search/SearchTokenizerTest.java | 1 + 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizer.java index 6a40e003b..f89eca048 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizer.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizer.java @@ -54,9 +54,6 @@ 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() {} @@ -123,10 +120,8 @@ public class SearchTokenizer { static boolean isAllowedWord(final char character) { return Character.isUnicodeIdentifierStart(character) - || Character.DASH_PUNCTUATION == Character.getType(character) - || Character.DECIMAL_DIGIT_NUMBER == Character.getType(character) - || (Character.OTHER_PUNCTUATION == Character.getType(character) && - (character != ';' && character != '"')); + || isUnreserved(character) + || isOtherDelimsForWord(character); } /** @@ -206,6 +201,26 @@ public class SearchTokenizer { || character == ';'; } + /** + * other-delims = "!" / "(" / ")" / "*" / "+" / "," / ";" + * @param character which is checked + * @return true if character is allowed + */ + private static boolean isOtherDelimsForWord(final char character) { + return character == '!' + || character == '*' + || character == '+' + || character == ',' + || character == ':' + || character == '@' + || character == '/' + || character == '?' + || character == '$' + || character == '=' + || character == '%' + || character == '\''; + } + /** * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" * @param character which is checked @@ -352,11 +367,7 @@ public class SearchTokenizer { @Override public State nextChar(final char c) throws SearchTokenizerException { - if (isAllowedWord(c) || - ('0' <= c && c <= '9') || - (c == CHAR_COMMA) || - (c == CHAR_DOT) || - (c == CHAR_HYPEN)) { + if (isAllowedWord(c)) { return allowed(c); } else if (c == CHAR_CLOSE) { finish(); diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizerTest.java index 216323de2..47ac3340d 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizerTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizerTest.java @@ -45,6 +45,7 @@ public class SearchTokenizerTest { @Test public void parseWords() throws Exception { + assertQuery("C++%20=$@:,*!/?'%27").resultsIn(WORD); assertQuery("somesimpleword").resultsIn(WORD); assertQuery("anotherWord\u1234").resultsIn(WORD); // special