michaelklishin / urly

A tiny Clojure library that parses and attempts to unify URIs, URLs and relative values found in real world HTML anchors
116 stars 10 forks source link

(url-like "#some-fragment") adds an absolute path (i.e., #<UrlLike /#some-fragment>) #5

Open rbp opened 11 years ago

rbp commented 11 years ago

I bumped into the following inconsistency:

user=> (java.net.URI. "#fragment")
#<URI #fragment>
user=> (.toURI (urly/url-like "#fragment"))
#<URI /#fragment>

And indeed (which is what actually bit me):

user=> (urly/url-like "#fragment")
#<UrlLike /#fragment>

Investigating, it turns out that UrlLike.fromURI doesn't seem prepared to deal with a url that's only an anchor (such as you'd have to navigate within the same page). It basically returns

new UrlLike(lowerCaseOrNull(uri.getScheme()), uri.getUserInfo(), uri.getHost(), uri.getAuthority(), uri.getPort(), pathOrDefault(uri.getPath()), uri.getQuery(), uri.getFragment());

which, in the case of a url consisting solely of of a fragment, uses a default path of "/".

Now, I'm happy to produce a pull request. I just want to make sure that this is not by design or something.

michaelklishin commented 11 years ago

Yes, it's because there is a default path. It's not a common issue but if all other tests still pass after getting rid of the default path, I'd accept a pull request.