text/template: Clone() does not clone options like it does for funcs #43022
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
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?
html/template
.Clone()
method will copy the funcmap set with.FuncMap()
over to the cloned template (as mentioned here). However.Clone()
does not seem to copy the options set with.Option()
over to the cloned template. Instead the cloned template reverts back to the default optionmissingkey=invalid
. Example code demonstrating how the funcmap is copied over, but the options are not:https://play.golang.org/p/1M00gykKOkp
What did you expect to see?
What did you see instead?
This behaviour is also observed for text/template, only that text/template outputs
<no value>
instead of an empty string.Currently I am cloning a bunch of templates, and in order to preserve the options I have to store the option string somewhere in a variable and re-configure using
.Option()
on every newly cloned template. Copying options on.Clone()
is not mentioned in the documentation, but it would be nice if it did that. Given that.Clone()
already copies the funcmap, it seems reasonable for it to copy the options as well.The text was updated successfully, but these errors were encountered: