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

transform.Plainify should return template.HTML instead of a string #8732

Closed
richtera opened this issue Jul 7, 2021 · 4 comments · Fixed by #12744
Closed

transform.Plainify should return template.HTML instead of a string #8732

richtera opened this issue Jul 7, 2021 · 4 comments · Fixed by #12744
Assignees
Milestone

Comments

@richtera
Copy link
Contributor

richtera commented Jul 7, 2021

What version of Hugo are you using (hugo version)?

$ hugo version
hugo v0.84.0+extended linux/amd64 BuildDate=unknown

Does this issue reproduce with the latest release?

This is the latest release.

When using plainify hugo many times does the wrong thing. I realize that this is a feature, but I wonder if there is a better way to do it. Specifically, if the HTML contains any HTML entities plainify returns the plain HTML with the entities but not marked as a HTML safe string. So the plainify output for HTML like <div>This &amp; that</div> will be This &amp; that. Now it's easy to pipe it through safeHTML or markdownify or htmlUnescape to solve the problem, but it seems plainify should probably include an automatic htmlUnescape or at least mark the output as HTML safe.
This is a petty kind of thing, but in our code, we always must do plainify | htmlUnescape and whenever we forget it the entities are shown on the screen. Seems cumbersome.

@davidsneighbour
Copy link
Contributor

You should open that in the discourse instead of here.

Regarding the issue at hand: I think it's because of the security model of Golang templates. Go expects the developer to make everything safe, so plainify can't just do an html unescape or mark the string as safe. I think it was recently only that script and style tags were removed by plainify. Lot's of hijinks would have been possible if Go just assumes that the string is safe.

See here: https://golang.org/pkg/html/template/#hdr-Security_Model (the whole chapter is an interesting read)

@richtera
Copy link
Contributor Author

richtera commented Jul 7, 2021

Yes I don't like the safeHTML either, maybe to include htmlUnescape would be safer and useful. What is the current use case for plainify? In my code 100% of my plainify calls have to be followed by one of the other filters. Maybe there should be a new method to extract plain text from html and return it as unescaped string rather than messing with plainfy.

@bep bep added this to the v0.88 milestone Jul 30, 2021
@bep bep modified the milestones: v0.88, v0.89 Sep 2, 2021
@bep bep modified the milestones: v0.89, v0.90 Nov 2, 2021
@bep bep modified the milestones: v0.90, v0.91.0 Dec 13, 2021
@bep bep modified the milestones: v0.91.0, v0.92.0 Dec 22, 2021
@bep bep modified the milestones: v0.92.0, v0.93.0 Jan 12, 2022
@bep bep modified the milestones: v0.93.0, v0.94.0 Mar 1, 2022
@bep bep modified the milestones: v0.94.0, v0.95.0, v0.96.0 Mar 9, 2022
@bep bep modified the milestones: v0.96.0, v0.97.0 Mar 24, 2022
@bep bep modified the milestones: v0.97.0, v0.98.0 Apr 13, 2022
@bep bep modified the milestones: v0.98.0, v0.99.0 Apr 28, 2022
@bep bep modified the milestones: v0.99.0, v0.100.0 May 24, 2022
@bep bep modified the milestones: v0.100.0, v0.101.0 May 31, 2022
@jmooring jmooring changed the title Plainify problems (more of an opinion than a real defect) transform.Plainify should return template.HTML instead of a string Apr 29, 2024
@jmooring
Copy link
Member

These transformation functions return template.HTML

  • transform.Emojify
  • transform.Highlight
  • transform.Markdownify

I think it makes sense to add transform.Plainify to the list.

@bep bep added Enhancement and removed Proposal labels Apr 30, 2024
@bep bep modified the milestones: v0.125.0, v0.126.0 Apr 30, 2024
@bep bep modified the milestones: v0.126.0, v0.127.0 May 15, 2024
@bep bep modified the milestones: v0.127.0, v0.128.0 Jun 8, 2024
@bep bep modified the milestones: v0.128.0, v0.129.0 Jun 21, 2024
@bep bep modified the milestones: v0.129.0, v0.131.0 Jul 22, 2024
@bep bep modified the milestones: v0.131.0, v0.133.0 Aug 9, 2024
bep added a commit to bep/hugo that referenced this issue Aug 11, 2024
None of these are useful as plain strings in the templates, which forces the users to do `transform.Plainify "foo" | safeHTML`.

If people have trust issues with the output of these functions, they need to just stop using them.

Closes gohugoio#8732
bep added a commit to bep/hugo that referenced this issue Aug 11, 2024
None of these are useful as plain strings in the templates, which forces the users to do `transform.Plainify "foo" | safeHTML`.

If people have trust issues with the output of these functions, they need to just stop using them.

Closes gohugoio#8732
bep added a commit to bep/hugo that referenced this issue Aug 11, 2024
None of these are useful as plain strings in the templates, which forces the users to do `transform.Plainify "foo" | safeHTML`.

If people have trust issues with the output of these functions, they need to just stop using them.

Closes gohugoio#8732
@bep bep modified the milestones: v0.133.0, v0.132.0 Aug 11, 2024
@bep bep self-assigned this Aug 11, 2024
@bep bep closed this as completed in 946e6af Aug 11, 2024
Copy link

github-actions bot commented Sep 2, 2024

This issue 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 Sep 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants