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

Feature-Request: Make absURL and relURL accept anything #2352

Merged
merged 1 commit into from
Aug 12, 2016

Conversation

kulla
Copy link
Contributor

@kulla kulla commented Aug 12, 2016

The template functions relURL and absURL currently only accept strings. However, after #889 many template functions like safeHtml were opened to accept more than strings. So I suggest that also relURL and absURL should share this behavior. For example the following code currently throws an error

{{ .RSSLink | relURL }}

because .RSSLink is of type template.HTML (it throws an error with my version Hugo Static Site Generator v0.16-DEV BuildDate: 2016-02-06T18:14:17+01:00 shipped with Ubuntu 16.04).

I followed 3a2a4c3 . Note that I never programmed in go before, so someone should check my changings :-) I am also not sure whether code injections are possible after the changes in my commit...

@CLAassistant
Copy link

CLAassistant commented Aug 12, 2016

CLA assistant check
All committers have signed the CLA.

@bep
Copy link
Member

bep commented Aug 12, 2016

Agree.

@@ -1803,7 +1803,7 @@ func htmlUnescape(in interface{}) (string, error) {

func init() {
funcMap = template.FuncMap{
"absURL": func(a string) template.HTML { return template.HTML(helpers.AbsURL(a)) },
"absURL": func(a interface{}) template.HTML { return template.HTML(helpers.AbsURL(cast.ToString(a))) },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the ToStringE variant and return any error as second return value from the template func. Same with relURL.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

He learned from the best. 😉 Do the changes in 3a2a4c3 need errors returned, too?

Copy link
Member

@bep bep Aug 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@moorereason please stick to this PR. Taking the entire commit history of Hugo into consideration for this simple change is ... Not fruitful.

@bep bep merged commit 88dcbc6 into gohugoio:master Aug 12, 2016
@bep
Copy link
Member

bep commented Aug 12, 2016

We'll handle the errors as part of #2354

@kulla
Copy link
Contributor Author

kulla commented Aug 13, 2016

Thanks 😄

@kulla kulla deleted the relurl-and-absurl-accept-anything branch August 16, 2016 09:12
@github-actions
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 Feb 21, 2022
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.

4 participants