You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2022/08/08 18:12:56 UTC

[olingo-odata4] branch OLINGO-1571 updated (4d257412f -> a93d0a042)

This is an automated email from the ASF dual-hosted git repository.

mibo pushed a change to branch OLINGO-1571
in repository https://gitbox.apache.org/repos/asf/olingo-odata4.git


 discard 4d257412f [OLINGO-1571] Fixed special chars for
     new a93d0a042 [OLINGO-1571] Fixed special chars for search

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (4d257412f)
            \
             N -- N -- N   refs/heads/OLINGO-1571 (a93d0a042)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:


[olingo-odata4] 01/01: [OLINGO-1571] Fixed special chars for search

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mibo pushed a commit to branch OLINGO-1571
in repository https://gitbox.apache.org/repos/asf/olingo-odata4.git

commit a93d0a04241dafb9c289072faf299d4690dea57c
Author: mibo <mi...@apache.org>
AuthorDate: Mon Aug 8 20:06:20 2022 +0200

    [OLINGO-1571] Fixed special chars for search
---
 .../core/uri/parser/search/SearchTokenizer.java    | 44 +++-------------------
 .../uri/parser/search/SearchTokenizerTest.java     | 13 +++++--
 2 files changed, 15 insertions(+), 42 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 6f7e01e70..ae89f9798 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
@@ -166,41 +166,7 @@ public class SearchTokenizer {
      * @return true if character is allowed for a phrase
      */
     static boolean isAllowedPhrase(final char character) {
-      // the '%' is allowed because it is assumed that it was percent encoded and is now decoded
-      return isQCharUnescaped(character) 
-    		  || character == '%' 
-    		  || Character.isUnicodeIdentifierStart(character);
-    }
-
-    /**
-     * qchar-unescaped = unreserved / pct-encoded-unescaped / other-delims / ":" / "@" / "/" / "?" / "$" / "'" / "="
-     * @param character which is checked
-     * @return true if character is allowed
-     */
-    private static boolean isQCharUnescaped(final char character) {
-      return isUnreserved(character)
-          || isOtherDelims(character)
-          || character == ':'
-          || character == '@'
-          || character == '/'
-          || character == '$'
-          || character == '\''
-          || character == '=';
-    }
-
-    /**
-     * other-delims = "!" / "(" / ")" / "*" / "+" / "," / ";"
-     * @param character which is checked
-     * @return true if character is allowed
-     */
-    private static boolean isOtherDelims(final char character) {
-      return character == '!'
-          || character == '('
-          || character == ')'
-          || character == '*'
-          || character == '+'
-          || character == ','
-          || character == ';';
+      return character != '"';
     }
 
     /**
@@ -234,7 +200,7 @@ public class SearchTokenizer {
           || character == '<'
           || character == '`';
     }
-    
+
     /**
      * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
      * @param character which is checked
@@ -355,11 +321,11 @@ public class SearchTokenizer {
   }
 
   /**
-   * 
-   * As per the updated abnf 
+   *
+   * 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 
+   * This includes Unicode characters of categories
    * L or N using UTF-8 and percent-encoding.
    */
   private class SearchWordState extends LiteralState {
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 d8c6a7cc7..cea6d3012 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
@@ -6,9 +6,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License. You may obtain a copy of the License at
- * 
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -107,6 +107,13 @@ public class SearchTokenizerTest {
     assertQuery("abc or \"xyz\"").resultsIn(WORD, WORD, PHRASE);
   }
 
+  @Test
+  public void parsePhrase_decoded() throws Exception {
+    assertQuery("\"a & b\"").resultsIn(PHRASE);
+    assertQuery("\" ! # $ % & ' ( ) * + , / : ; = ? @ [ ] \"").resultsIn(PHRASE);
+    assertQuery("\" - . < > ^ _ ` { | } ~ \"").resultsIn(PHRASE);
+  }
+
   @Test
   public void parseNot() throws Exception {
     assertQuery("NOT").resultsIn(NOT);
@@ -401,4 +408,4 @@ public class SearchTokenizerTest {
       }
     }
   }
-}
\ No newline at end of file
+}