bidi
bidi copied to clipboard
->Alternates with "" is broken
(def routes-test
["/" {(->Alternates ["xxx" "index" "a"]) :handler}])
(bidi/match-route routes-test "/index")
=> {:handler :handler}
however,
(def routes-test
["/" {(->Alternates ["xxx" "" "index" "a"]) :handler}])
(bidi/match-route routes-test "/index")
=> nil
and,
(bidi/match-route routes-test "/xxx")
=> {:handler :handler}
workaround,
(def routes-test
["/" {(->Alternates ["xxx" #"$" "index" "a"]) :handler}])
(bidi/match-route routes-test "/xxx")
(bidi/match-route routes-test "/index")
(bidi/match-route routes-test "/")
all => {:handler :handler}
The trouble is that Alternates will successfully match on "", even if the resulting Matched returns nil. This is avoided if "" is the last pattern to be specified. I've changed the Alternates implementation to try longer filters first, but I see this only works with strings (which have lengths) rather than any Pattern, so I'll leave this issue open.