From: Justin Nuß Date: Sun, 26 Nov 2017 10:05:53 +0000 (+0100) Subject: html/template: document handling of namespaced and data- attributes X-Git-Tag: go1.14beta1~933 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=683ef8c8441d100590f5ed5c9d662e217a7130ce;p=gostls13.git html/template: document handling of namespaced and data- attributes Attributes with a namespace or a data- prefix are handled as if they had no namespace/data- prefix. There is also a special case, where attributes with a "xmlns" namespace are always treated as containing URLs. This could surprise users of the package, since this behaviour was not documented anywhere, so this change adds some documentation for all three cases. Fixes #12648 Change-Id: If57a2ec49fec91a330fc04795726e8cffa9b75c0 Reviewed-on: https://go-review.googlesource.com/c/go/+/79895 Run-TryBot: Andrew Bonventre TryBot-Result: Gobot Gobot Reviewed-by: Andrew Bonventre --- diff --git a/src/html/template/doc.go b/src/html/template/doc.go index 290ec81b96..650e7147a3 100644 --- a/src/html/template/doc.go +++ b/src/html/template/doc.go @@ -73,6 +73,51 @@ functions. For these internal escaping functions, if an action pipeline evaluates to a nil interface value, it is treated as though it were an empty string. +Namespaced and data- attributes + +Attributes with a namespace are treated as if they had no namespace. +Given the excerpt + + + +At parse time the attribute will be treated as if it were just "href". +So at parse time the template becomes: + + + +Similarly to attributes with namespaces, attributes with a "data-" prefix are +treated as if they had no "data-" prefix. So given + + + +At parse time this becomes + + + +If an attribute has both a namespace and a "data-" prefix, only the namespace +will be removed when determining the context. For example + + + +This is handled as if "my:data-href" was just "data-href" and not "href" as +it would be if the "data-" prefix were to be ignored too. Thus at parse +time this becomes just + + + +As a special case, attributes with the namespace "xmlns" are always treated +as containing URLs. Given the excerpts + + + + + +At parse time they become: + + + + + Errors See the documentation of ErrorCode for details.