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

merged 1 commit into from Aug 12, 2016


None yet

4 participants

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...

@kulla kulla tpl: Make absURL and relURL accept anything
CLAassistant commented Aug 12, 2016 edited

CLA assistant check
All committers have signed the CLA.

bep commented Aug 12, 2016


@bep bep commented on the diff Aug 12, 2016
@@ -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))) },
bep Aug 12, 2016 Collaborator

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

moorereason Aug 12, 2016 Collaborator

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

bep Aug 12, 2016 edited Collaborator

@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 spf13:master Aug 12, 2016

4 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
continuous-integration/travis-ci/pr The Travis CI build passed
continuous-integration/wercker Wercker build passed
licence/cla Contributor License Agreement is signed.
bep commented Aug 12, 2016

We'll handle the errors as part of #2354

kulla commented Aug 13, 2016

Thanks 😄

@kulla kulla deleted the kulla:relurl-and-absurl-accept-anything branch Aug 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment