Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for '.' on qrest path parameter #271

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) -> "");
}
}