Skip to content

Commit

Permalink
Merge pull request #271 from fintechworks/feature/add_support_for_dot…
Browse files Browse the repository at this point in the history
…_in_url_param

feat: Add support for '.' on qrest path parameter
  • Loading branch information
ar authored Nov 28, 2022
2 parents 958fe41 + 3acc7e4 commit 098dfbc
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/qrest/src/main/java/org/jpos/qrest/Route.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
40 changes: 40 additions & 0 deletions modules/qrest/src/test/java/org/jpos/qrest/RouteTest.java
Original file line number Diff line number Diff line change
@@ -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<String, Object> params = path.parameters(uri);
assertEquals(2, params.size());
assertEquals("2.1", params.get("version"));
assertEquals("21.001.001", params.get("code"));
}

private static Route<String> buildRoute(String path) {
return new Route<>(path, "GET", (r, p) -> "");
}
}

0 comments on commit 098dfbc

Please # to comment.