mirror of
https://github.com/metosin/reitit.git
synced 2025-12-29 20:58:26 +00:00
Oh My Java: safe guard against index overflows.
This commit is contained in:
parent
9e58f93cc9
commit
393049a772
2 changed files with 15 additions and 7 deletions
|
|
@ -192,9 +192,12 @@ public class SegmentTrie {
|
|||
|
||||
@Override
|
||||
public Match match(int i, List<String> segments, Match match) {
|
||||
match.params.put(parameter, decode(String.join("/", segments.subList(i, segments.size()))));
|
||||
match.data = data;
|
||||
return match;
|
||||
if (i < segments.size()) {
|
||||
match.params.put(parameter, decode(String.join("/", segments.subList(i, segments.size()))));
|
||||
match.data = data;
|
||||
return match;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -212,9 +215,11 @@ public class SegmentTrie {
|
|||
|
||||
@Override
|
||||
public Match match(int i, List<String> segments, Match match) {
|
||||
final Matcher child = map.get(segments.get(i));
|
||||
if (child != null) {
|
||||
return child.match(i + 1, segments, match);
|
||||
if (i < segments.size()) {
|
||||
final Matcher child = map.get(segments.get(i));
|
||||
if (child != null) {
|
||||
return child.match(i + 1, segments, match);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,8 +74,9 @@
|
|||
["/abba/1" ::abba2]
|
||||
["/:jabba/2" ::jabba2]
|
||||
["/:abba/:dabba/doo" ::doo]
|
||||
["/abba/dabba/boo/baa" ::baa]
|
||||
["/abba/:dabba/boo" ::boo]
|
||||
["/:jabba/:dabba/:doo/*foo" ::wild]]
|
||||
["/:jabba/:dabba/:doo/:daa/*foo" ::wild]]
|
||||
{:router r})
|
||||
matches #(-> router (r/match-by-path %) :data :name)]
|
||||
(is (= ::abba (matches "/abba")))
|
||||
|
|
@ -83,6 +84,8 @@
|
|||
(is (= ::jabba2 (matches "/abba/2")))
|
||||
(is (= ::doo (matches "/abba/1/doo")))
|
||||
(is (= ::boo (matches "/abba/1/boo")))
|
||||
(is (= ::baa (matches "/abba/dabba/boo/baa")))
|
||||
(is (= ::boo (matches "/abba/dabba/boo")))
|
||||
(is (= ::wild (matches "/olipa/kerran/avaruus/vaan/ei/toista/kertaa")))))
|
||||
|
||||
(testing "empty path segments"
|
||||
|
|
|
|||
Loading…
Reference in a new issue