I've found this question on Stack Overflow that indicates that it was different. The code listed in the answer there was removed in 167a712, and checked for an empty interface{} vs an interface that had methods, right? I hope to have time next weekend to try out some older Go versions.
Apart from how older versions behaved, it's weird to explicitly pass an interface as data to a template and see it being ignored and the underlying type used instead. It could even be a security issue, as templates have access to more than was intended. (The html/template documentation states "this package assumes that template authors are trusted", but the text/template documentation does not.)
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I executed a
text/template.Template
with an interface as data.Example code
On play: https://play.golang.org/p/YgMyBPie8kw
What did you expect to see?
My template is using functions that don't exist in the interface, thus I was expecting an error.
What did you see instead?
The template is able to execute functions on the underlying type, exposing functionality I don't want to expose.
I believe the
text/template
package actually behaved as I would expect in the past. I think the functionality was changed in 167a712.The text was updated successfully, but these errors were encountered: