weavejester / compojure

A concise routing library for Ring/Clojure
Eclipse Public License 1.0
4.09k stars 256 forks source link

1.4.0: path regexp matches against still-encoded url component #145

Closed hoxu closed 8 years ago

hoxu commented 8 years ago

With compojure 1.4.0 this syntax matches against the encoded url component:

["/:test", :test #"[0-9%F]+"]

/123%2F456 matches this route, and test gets 123/456 assigned.

I would expect the regexp to match against the decoded version of the component - eg. the same string that gets assigned to test. This is how it seemed to work before, at least in compojure 1.1.5.

I would expect the following to work, but it does not:

["/:test", :test #"[0-9/]+"]
hoxu commented 8 years ago

Actually this issue might be invalid. I think I got confused because with Compojure 1.1.5 the URL seemed to be decoded twice, so URLs containing "/" were matched regardless of whether they were urlencoded or not.

Now that I think about it, Compojure 1.4.0 is probably working just right - the regexp must indeed be matched against still-urlencoded path.

Maybe URL decoding and pattern matching should be covered in the wiki in more detail.

weavejester commented 8 years ago

Yes, this is deliberate behaviour. The regular expression matches against the URL itself, not the decoded path. When the URL is decoded, information is lost (e.g. %2F and / both translate to the same thing). This was causing problems for a bunch of things, including the context macro.

hoxu commented 8 years ago

Right! Thanks for the reply, I'm closing this issue.