diff --git a/src/html/template/context.go b/src/html/template/context.go
index 59e794d686..c90fc1fda5 100644
--- a/src/html/template/context.go
+++ b/src/html/template/context.go
@@ -310,7 +310,8 @@ func (e element) String() string {
return fmt.Sprintf("illegal element %d", int(e))
}
-// attr identifies the most recent HTML attribute when inside a start tag.
+// attr identifies the current HTML attribute when inside the attribute,
+// that is, starting from stateAttrName until stateTag/stateText (exclusive).
type attr uint8
const (
diff --git a/src/html/template/escape_test.go b/src/html/template/escape_test.go
index bea2d133c3..707394e3b0 100644
--- a/src/html/template/escape_test.go
+++ b/src/html/template/escape_test.go
@@ -1054,7 +1054,7 @@ func TestEscapeText(t *testing.T) {
},
{
``,
+ context{},
},
}
diff --git a/src/html/template/transition.go b/src/html/template/transition.go
index d2e028741a..aefe0355af 100644
--- a/src/html/template/transition.go
+++ b/src/html/template/transition.go
@@ -169,7 +169,7 @@ func tBeforeValue(c context, s []byte) (context, int) {
case '"':
delim, i = delimDoubleQuote, i+1
}
- c.state, c.delim, c.attr = attrStartStates[c.attr], delim, attrNone
+ c.state, c.delim = attrStartStates[c.attr], delim
return c, i
}