scotty-web / scotty

Haskell web framework inspired by Ruby's Sinatra, using WAI and Warp (Official Repository)
http://hackage.haskell.org/package/scotty
BSD 3-Clause "New" or "Revised" License
1.72k stars 134 forks source link

Using the exact name and syntax of a URL capture causes a runtime error #291

Closed techninja1008 closed 8 months ago

techninja1008 commented 1 year ago

Minimal reproduction:

module Main (main) where

import Web.Scotty

main :: IO ()
main = scotty 3000 $
  get "/:some_named_capture" $ do
    val <- param "some_named_capture"
    text val

When requesting the url "/:some_named_capture" exactly, the value is not captured at all as it matches literally. This results in the param call failing.

I actually discovered this whilst reading through scotty's source and noticing the order of the guards in the go function within matchRoute. Specifically, the equal literals case is checked before the p is a capture case, which should probably be first for the expected behaviour.

jfraudeau commented 11 months ago

I noticed the same issue, will create a pull request.