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

database/sql: converting Exec argument #0's type: unsupported type template.HTML, a string #14343

Closed
danhardman opened this issue Feb 15, 2016 · 3 comments
Milestone

Comments

@danhardman
Copy link

I have a struct with string fields that I want outputted in HTML. As they are of type string, they're not showing unescaped so when I do {{ .Post.Title }} in the template I get outputs like: Dan's post!.

I have added <DOCTYPE html> to try and fix it but it doesn't work.

I've found that I should make the fields of type template.HTML, ensuring that it is properly sanitised before outputting. However, I want to store it in a database and when I try, I get the error:

sql: converting Exec argument #0's type: unsupported type template.HTML, a string

Any ideas?

@robpike robpike assigned robpike and adg and unassigned robpike Feb 16, 2016
@ianlancetaylor ianlancetaylor changed the title sql: converting Exec argument #0's type: unsupported type template.HTML, a string database/sql: converting Exec argument #0's type: unsupported type template.HTML, a string Feb 16, 2016
@ianlancetaylor ianlancetaylor added this to the Go1.7 milestone Feb 16, 2016
@adg
Copy link
Contributor

adg commented Feb 16, 2016

@bradfitz should database/sql handle string types that aren't named string?

@bradfitz
Copy link
Contributor

I dunno. Maybe? I have no strong opinions.

@danhardman
Copy link
Author

In the IRC I went with the consensus that template.HTML stuff should be isolated in whatever code handles the templating and it shouldn't affect other packages.

So instead of attempting to store template.HTML fields in the database, I stick to storing them as strings and I add a method on the struct that returns the string values as type template.HTML once it has sanitised the string and everything.

@golang golang locked and limited conversation to collaborators Feb 28, 2017
@rsc rsc unassigned adg Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants