PuerkitoBio / purell

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

Use net/url .String() #40

Open natasha-jarus opened 6 months ago

natasha-jarus commented 6 months ago

This PR gets most tests to pass using net/url.String() for url escaping. The only failing tests are for EncodeNecessaryEscapes and DecodeUnnecessaryEscapes, which rely on implementation details of net/url and urlesc.

It is remarkably difficult to avoid net/url's escaping logic, especially if you try to hold it "right" by using .String(), .EscapedPath(), PathJoin(), &c. My opinion is that net/url has had this escaping logic for years at this point and likely folks should be OK with it at this point.

In addition, the TestEncodeNecessaryEscapesAll is vague; as written, it tests not only the path but also query and fragment escaping, since the url string contains ? and #. It is unclear to me if we want to just test path escaping or if we care about query and fragment escaping too?

Resolves #14 unsatisfactorily.