diff --git a/CHANGELOG.md b/CHANGELOG.md index e59754e9..9086fc55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.2.13 (2019-01-26) + +* Don't throw `StringIndexOutOfBoundsException` with empty path lookup on wildcard paths, fixes [#209](https://github.com/metosin/reitit/issues/209) + ## 0.2.12 (2019-01-18) * fixed reflection & boxed math warnings, fixes [#207](https://github.com/metosin/reitit/issues/207) diff --git a/modules/reitit-core/java-src/reitit/SegmentTrie.java b/modules/reitit-core/java-src/reitit/SegmentTrie.java index 062034e3..d1020b24 100644 --- a/modules/reitit-core/java-src/reitit/SegmentTrie.java +++ b/modules/reitit-core/java-src/reitit/SegmentTrie.java @@ -19,7 +19,9 @@ public class SegmentTrie { start = i + 1; } } - segments.add(path.substring(start, size)); + if (start <= size) { + segments.add(path.substring(start, size)); + } return segments; } diff --git a/test/cljc/reitit/core_test.cljc b/test/cljc/reitit/core_test.cljc index 4905b6f7..12ceee64 100644 --- a/test/cljc/reitit/core_test.cljc +++ b/test/cljc/reitit/core_test.cljc @@ -99,7 +99,8 @@ (is (= nil (matches "/items/"))) (is (= ::item (matches "/items/1"))) (is (= ::deep (matches "/items/1/2"))) - (is (= nil (matches "/items//2")))))) + (is (= nil (matches "/items//2"))) + (is (= nil (matches "")))))) r/linear-router :linear-router r/segment-router :segment-router diff --git a/test/cljc/reitit/segment_test.cljc b/test/cljc/reitit/segment_test.cljc index ca7bd2bf..2be592e1 100644 --- a/test/cljc/reitit/segment_test.cljc +++ b/test/cljc/reitit/segment_test.cljc @@ -18,4 +18,9 @@ (-> (s/insert nil "/foo" {:a 1}) (s/insert "/foo/*bar" {:b 1}) (s/compile) - (s/lookup "/foo/bar"))))) + (s/lookup "/foo/bar")))) + + (is (= (s/->Match {:a 1} {}) + (-> (s/insert nil "" {:a 1}) + (s/compile) + (s/lookup "")))))