diff --git a/modules/qrest/src/main/java/org/jpos/qrest/Route.java b/modules/qrest/src/main/java/org/jpos/qrest/Route.java index 2efd1bb1f4..626f276748 100644 --- a/modules/qrest/src/main/java/org/jpos/qrest/Route.java +++ b/modules/qrest/src/main/java/org/jpos/qrest/Route.java @@ -89,7 +89,7 @@ private Pattern buildPathPattern(String path) { String name = m.group(i); params.add(name); s = m.replaceFirst( - String.format("(?<%s>[^\\/.]*)", name) + String.format("(?<%s>[^\\/]*)", name) ); m.reset(s); } diff --git a/modules/qrest/src/test/java/org/jpos/qrest/RouteTest.java b/modules/qrest/src/test/java/org/jpos/qrest/RouteTest.java new file mode 100644 index 0000000000..f675a590ef --- /dev/null +++ b/modules/qrest/src/test/java/org/jpos/qrest/RouteTest.java @@ -0,0 +1,40 @@ +package org.jpos.qrest; + +import org.junit.jupiter.api.Test; + +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * @author Arturo Volpe + * @since 2022-11-27 + */ +class RouteTest { + + @Test + void matches() { + + + assertTrue(buildRoute("/simple").matches("/simple")); + assertTrue(buildRoute("/simpleWithSlash/").matches("/simpleWithSlash/")); + assertTrue(buildRoute("/withParam/{param1}/").matches("/withParam/1234/")); + + // test path with dot + assertTrue(buildRoute("/{org}/{repo}/blob/{branch}/{file}").matches("/jpos/jPOS-EE/blob/master/README.md")); + + // test path with dot (for example for version) + Route path = buildRoute("/{version}/accounts/{code}"); + String uri = "/2.1/accounts/21.001.001"; + assertTrue(path.matches(uri)); + Map params = path.parameters(uri); + assertEquals(2, params.size()); + assertEquals("2.1", params.get("version")); + assertEquals("21.001.001", params.get("code")); + } + + private static Route buildRoute(String path) { + return new Route<>(path, "GET", (r, p) -> ""); + } +}