URI Template Matching Regex Min,Max #5252
Replies: 8 comments 1 reply
-
|
Same problem here. |
Beta Was this translation helpful? Give feedback.
-
|
same here |
Beta Was this translation helpful? Give feedback.
-
|
Not currently, you can apply a |
Beta Was this translation helpful? Give feedback.
-
|
+1 |
Beta Was this translation helpful? Give feedback.
-
|
+1 I want the micronaut be able to distinguish the correct root when long id or uuid is in path |
Beta Was this translation helpful? Give feedback.
-
|
+1 |
Beta Was this translation helpful? Give feedback.
-
|
We have this same problem. At the very least the docs should specify that only a subset of regex is supported. |
Beta Was this translation helpful? Give feedback.
-
|
The issue: curly braces
Most annotation processors (Spring, JAX-RS, etc.) cannot distinguish between them, causing a parsing error. Solutions1. Simple and universal solution: validate inside the controller methodInstead of putting the length constraint in the mapping regex, declare the parameter without a regex and validate the length manually. Spring MVC: @GetMapping("/bar/{foo}")
public String getBar(@PathVariable String foo) {
// Explicit validation
if (foo == null || !foo.matches("[a-zA-Z0-9]+") || foo.length() < 1 || foo.length() > 35) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Invalid foo");
}
// continue...
return "ok";
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
Is there a way to define a {min,max} size when using a regex with a path parameter?
Something like:
/bar/{foo:[a-zA-Z0-9]{1,35}}The '{' and '}' characters are breaking the annotation processor.
Beta Was this translation helpful? Give feedback.
All reactions