bidi icon indicating copy to clipboard operation
bidi copied to clipboard

->Alternates with "" is broken

Open davesann opened this issue 11 years ago • 1 comments

(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}

davesann avatar May 25 '14 04:05 davesann

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.

malcolmsparks avatar Feb 01 '15 16:02 malcolmsparks