Skip to content

Commit f1a7c98

Browse files
committed
build: more unit test for internal core package;
1 parent a6c6818 commit f1a7c98

2 files changed

Lines changed: 154 additions & 179 deletions

File tree

jooby/src/main/java/io/jooby/internal/Chi.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ void replaceChild(char label, char tail, Node child) {
810810
return;
811811
}
812812
}
813-
throw new IllegalArgumentException("chi: replacing missing child");
813+
throw new IllegalArgumentException("Router: replacing missing child");
814814
}
815815

816816
Node getEdge(int ntyp, char label, char tail, String prefix) {
@@ -1072,9 +1072,22 @@ Segment patNextSegment(String pattern) {
10721072
}
10731073

10741074
// Sanity check
1075-
if (ws >= 0 && ws < ps) {
1076-
throw new IllegalArgumentException(
1077-
"chi: wildcard '*' must be the last pattern in a route, otherwise use a '{param}'");
1075+
if (ws >= 0) {
1076+
// 1. Wildcard cannot appear before a parameter
1077+
if (ws < ps) {
1078+
throw new IllegalArgumentException(
1079+
"Router: wildcard '*' must be the last pattern in a route, otherwise use a"
1080+
+ " '{param}'");
1081+
}
1082+
1083+
// 2. Wildcard cannot have structural segments after it (e.g., /*/bar)
1084+
// Named wildcards (e.g., /*bar) will pass this check because they don't contain a '/'
1085+
if (pattern.indexOf('/', ws) >= 0) {
1086+
throw new IllegalArgumentException(
1087+
"Router: wildcard '*' must be the last element in a route. Found trailing segment in:"
1088+
+ " "
1089+
+ pattern);
1090+
}
10781091
}
10791092

10801093
char tail = '/'; // Default endpoint tail to / byte

0 commit comments

Comments
 (0)