Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helpers: Improve schema detection when creating relative URLs #11081

Merged
merged 1 commit into from
Jun 12, 2023

Conversation

jmooring
Copy link
Member

Fixes #11080

@jmooring jmooring force-pushed the fix/relURL-relLangURL-11080 branch from 117a794 to 8fdbfc5 Compare June 10, 2023 17:34
@bep
Copy link
Member

bep commented Jun 12, 2023

With the very basic benchmark in 5db215d

BenchmarkRelURL-10    	 6678015	       174.5 ns/op	     144 B/op	       1 allocs/op
BenchmarkRelURL-10    	 7588068	       161.8 ns/op	     144 B/op	       1 allocs/op
BenchmarkRelURL-10    	 7505914	       158.2 ns/op	     144 B/op	       1 allocs/op
BenchmarkRelURL-10    	 7570666	       157.2 ns/op	     144 B/op	       1 allocs/op
PASS
ok  	github.com/gohugoio/hugo/helpers	5.807s


name       old time/op    new time/op    delta
RelURL-10    14.6ns ± 2%   162.9ns ± 7%  +1012.50%  (p=0.029 n=4+4)

name       old alloc/op   new alloc/op   delta
RelURL-10     0.00B        144.00B ± 0%      +Inf%  (p=0.029 n=4+4)

name       old allocs/op  new allocs/op  delta
RelURL-10      0.00           1.00 ± 0%      +Inf%  (p=0.029 n=4+4)

I agree that we need to fix this, but I suggest that you do some basic prefix checking before falling back to the "slow path" using url.Parse.

@jmooring
Copy link
Member Author

OK, but this change was modeled after:
https://github.com/gohugoio/hugo/blob/master/helpers/url.go#L106

Would you like me to change that too?

@bep bep merged commit e1d4302 into gohugoio:master Jun 12, 2023
@bep
Copy link
Member

bep commented Jun 12, 2023

Never mind, I'll take a look at both of them.

@jmooring jmooring deleted the fix/relURL-relLangURL-11080 branch June 12, 2023 13:04
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

relURL and relLangURL ignore schemas other than http/https
2 participants