You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2022/05/09 01:34:51 UTC

[james-project] branch master updated: JAMES-3744 Fixed URI matcher should be more flexible (#991)

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

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git


The following commit(s) were added to refs/heads/master by this push:
     new e5a68b78c6 JAMES-3744 Fixed URI matcher should be more flexible (#991)
e5a68b78c6 is described below

commit e5a68b78c61462c68daf8e4302f709647e23f832
Author: Trần Hồng Quân <55...@users.noreply.github.com>
AuthorDate: Mon May 9 08:34:46 2022 +0700

    JAMES-3744 Fixed URI matcher should be more flexible (#991)
    
    This allows matching routes with query param
---
 .../java/org/apache/james/jmap/UriMatcher.java     |  9 +++-
 .../org/apache/james/jmap/FixedUriMatcherTest.java | 50 ++++++++++++++++++++++
 2 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/UriMatcher.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/UriMatcher.java
index 18b1535f36..96b7c7a3dd 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/UriMatcher.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/UriMatcher.java
@@ -155,6 +155,8 @@ public interface UriMatcher {
     }
 
     class Fixed implements UriMatcher {
+        private static final String QUERY_CHARACTER = "?";
+
         private final String fixedPath;
 
         public Fixed(String fixedPath) {
@@ -163,7 +165,12 @@ public interface UriMatcher {
 
         @Override
         public boolean matches(String uri) {
-            return uri.equals(fixedPath);
+            int indexOfQueryCharacter = uri.indexOf(QUERY_CHARACTER);
+            if (indexOfQueryCharacter != -1) {
+                return uri.substring(0, indexOfQueryCharacter).equals(fixedPath);
+            } else {
+                return uri.equals(fixedPath);
+            }
         }
 
         @Override
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/FixedUriMatcherTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/FixedUriMatcherTest.java
new file mode 100644
index 0000000000..bb6f45f9aa
--- /dev/null
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/FixedUriMatcherTest.java
@@ -0,0 +1,50 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * 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       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.jmap;
+
+import static org.assertj.core.api.Java6Assertions.assertThat;
+
+import org.junit.jupiter.api.Test;
+
+class FixedUriMatcherTest {
+    @Test
+    void fixedMatcherShouldReturnTrueWhenUriHaveNoQueryCharacterAndMatchWithPath() {
+        UriMatcher testee = new UriMatcher.Fixed("path");
+        assertThat(testee.matches("path")).isTrue();
+    }
+
+    @Test
+    void fixedMatcherShouldReturnTrueWhenUriHaveAQueryParamAndTheRestIsMatchWithPath() {
+        UriMatcher testee = new UriMatcher.Fixed("path");
+        assertThat(testee.matches("path?param1=somevalue")).isTrue();
+    }
+
+    @Test
+    void fixedMatcherShouldReturnTrueWhenUriHaveManyQueryParamsAndTheRestIsMatchWithPath() {
+        UriMatcher testee = new UriMatcher.Fixed("path");
+        assertThat(testee.matches("path?param1=1&param2=2")).isTrue();
+    }
+
+    @Test
+    void fixedMatcherShouldReturnFalseWhenNotMatchingUri() {
+        UriMatcher testee = new UriMatcher.Fixed("path");
+        assertThat(testee.matches("anotherPath")).isFalse();
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org