With Sinatra routes, how can there be both a required named parameter and an optional named parameter in the same part of the route.
Optional route parameter works fine here
get '/widgets.?:format?'
But, try to combine a required named paramter, and things break.
get '/widgets/:id.?:format?'
Requests for /widgets/abc.json pass the entire abc.json as the id parameter.
The Sinatra compiled regex is:
/^\/widgets\/([^\/?#]+)(?:\.|%2E)?([^\/?#]+)?$/
I did get past this by going full regex on the route and excluding the "." from the first regex group.
get %r{/widgets\/([^\/?#\.]+)(?:\.|%2E)?([^\/?#]+)?}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With