]> Cypherpunks repositories - gostls13.git/commit
html/template: fix Clone so that t.Lookup(t.Name()) yields t
authorCaleb Spare <cespare@gmail.com>
Fri, 14 Oct 2016 07:59:19 +0000 (00:59 -0700)
committerRob Pike <r@golang.org>
Mon, 17 Oct 2016 00:35:20 +0000 (00:35 +0000)
commitcd2c9df7612795cad5b56cabe5ec29c7771db5fe
treec7246b27dc2b0248b4c58d28f157f7e73db9b703
parentd8cbc2c918f68e8ca5992e68fed052a0e52a8e67
html/template: fix Clone so that t.Lookup(t.Name()) yields t

Template.escape makes the assumption that t.Lookup(t.Name()) is t
(escapeTemplate looks up the associated template by name and sets
escapeErr appropriately).

This assumption did not hold for a Cloned template, because the template
associated with t.Name() was a second copy of the original.

Add a test for the assumption that t.Lookup(t.Name()) == t.

One effect of this broken assumption was #16101: parallel Executes
racily accessed the template namespace because each Execute call saw
t.escapeErr == nil and re-escaped the template concurrently with read
accesses occurring outside the namespace mutex.

Add a test for this race.

Related to #12996 and CL 16104.

Fixes #16101

Change-Id: I59831d0847abbabb4ef9135f2912c6ce982f9837
Reviewed-on: https://go-review.googlesource.com/31092
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
src/html/template/clone_test.go
src/html/template/template.go