Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Should WebMock compress multiple path separators (forward slashes) when matching URLs?

33 views
Skip to first unread message

rfichoke

unread,
Dec 5, 2011, 1:21:33 PM12/5/11
to webmoc...@googlegroups.com
It's easy to end up with multiple path separators in a URL when you build it from components:

server = "www.example.com"
root = "/some/directory"


Net::HTTP.get(URI.parse("http://#{server}/#{root}/file.html"))

If you stub a request for http://example.com/some/directory/file.html, it fails because the URLs don't match.  Should it?

Bartosz Blimke

unread,
Dec 5, 2011, 4:51:26 PM12/5/11
to webmoc...@googlegroups.com
I had to check on my own as I never tried this scenario.
It looks like Addressable doesn't treat these two uri's as equal and Webmock depends on Addressable,
when comparing uri's.

rfc 2396 states that "The path may consist of a sequence of path segments separated by a single slash "/" character."

It wouldn't really be a problem to add logic to Webmock which would remove double slashes.
Not sure if it should either. 

Bartosz

2011/12/5 rfichoke <rfic...@gmail.com>

James Conroy-Finn

unread,
Dec 5, 2011, 5:36:37 PM12/5/11
to webmoc...@googlegroups.com
If I end up with a bug in production because WebMock fixes my URLs I'd probably be a bit annoyed once I realised why I'd missed the issue.

I think cleaning up URLs would be unexpected behaviour. It's a request mocking library as opposed to an opinionated/helpful HTTP library after all.

Just my two cents.

rfichoke

unread,
Dec 6, 2011, 12:43:55 PM12/6/11
to webmoc...@googlegroups.com
If the RFC says "single slash," then WebMock should definitely treat the addresses as different.  Furthermore, after looking at section 5, it seems there's actually a (rare) use for double-slashes as "network-path relative URIs." You learn something new every day. :-)

And James' point makes sense too.  According to the README, WebMock does normalize URLs already which might cause problems in rare situations, I guess.
Reply all
Reply to author
Forward
0 new messages