PuerkitoBio / purell

tiny Go library to normalize URLs
BSD 3-Clause "New" or "Revised" License
468 stars 59 forks source link

Return same url.URL struct instead of string #18

Closed xeoncross closed 7 years ago

xeoncross commented 7 years ago

Why does the NormalizeURL() function take a url.URL but return a string? There are already functions for dealing with string URL's.

mna commented 7 years ago

Hello David,

Typically this is passed to http.Get or http.NewRequest, and the url.URL is a pointer, so the URL you passed in is modified and normalized in-place, no need to return it. If you need the url.URL, you can just use the one you passed in. (There's a minor caveat to this regarding the urlesc package which doesn't escape in-place)

Martin

xeoncross commented 7 years ago

So since the urlesc.Escape() method simply returns a string, then if I don't pass the result of NormalizeURL() back to url.Parse() then I'll lose some of the proper escaping done by urlesc and possibly end up with a less-than-normalized URL.

mna commented 7 years ago

Recent versions of Go properly escape, so that call to urlesc should not be necessary now. So your url.URL would be ok (see #14 that I haven't had time to address yet).