cfssl icon indicating copy to clipboard operation
cfssl copied to clipboard

Replace normalizeURL with urlx.Parse

Open jayme-github opened this issue 3 years ago • 3 comments

normalizeURL used to break URLs with path by rewriting their host part and it would also panic on "IP:Port" strings.

I've refactored that to utilize urlx.Parse and also added a couple of test cases.

jayme-github avatar Dec 20 '21 17:12 jayme-github

normalizeURL used to break URLs with path by rewriting their host part

Do you have an example / test-case that would show the URLs that would break? This is adding 8K lines of code (as dependency) to parse an URL, which seems a lot for just this, so wondering if the problem could be solved in another way.

thaJeztah avatar Nov 22 '22 00:11 thaJeztah

normalizeURL used to break URLs with path by rewriting their host part

Do you have an example / test-case that would show the URLs that would break? This is adding 8K lines of code (as dependency) to parse an URL, which seems a lot for just this, so wondering if the problem could be solved in another way.

Given this was some time ago I'm no longer sure but I strongly suppose I put them in the tests.

jayme-github avatar Nov 22 '22 10:11 jayme-github

Thanks! I think the reason url.Parse() may fail for some of those is that, if no scheme is provided, some results may be ambiguous.

The code I tried above avoids that situation by checking if a scheme is present and if not, to prepend the default scheme;

if strings.Index(addr, "://") == -1 {
	// use http:// if no scheme is provided
	addr = "http://" + addr
}

Of course it's possible that urlx handles more esoteric cases besides those, but (and I'm not a maintainer, just a passer-by! 😅) I wonder if that's enough to warrant the larger number of lines imported from the additional dependency.

thaJeztah avatar Nov 22 '22 12:11 thaJeztah