aboutsummaryrefslogtreecommitdiff
path: root/src/html
AgeCommit message (Collapse)Author
2021-09-09[release-branch.go1.16] text/template: add lock for Template.tmpl to fix ↵Ian Lance Taylor
data race This adds a new lock protecting "tmpl". This is a copy of https://golang.org/cl/257817 by Andreas Fleig, updated for current tip, and updated to start running the html/template TestEscapeRace test. Thanks to @bep for providing the test case. For #39807 Fixes #47042 Change-Id: Ic8874484290283a49116812eeaffb8608346dc70 Reviewed-on: https://go-review.googlesource.com/c/go/+/316669 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> (cherry picked from commit 496d7c691481966fd6ea806205aa025698a172af) Reviewed-on: https://go-review.googlesource.com/c/go/+/348580 Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
2021-01-25html/template: revert "avoid race when escaping updates template"Ian Lance Taylor
This reverts CLs 274450 and 279492, except for the new tests. The new race test is changed to skip, as it now fails. We can try again for 1.17. Original CL descriptions: html/template: attach functions to namespace The text/template functions are stored in a data structure shared by all related templates, so do the same with the original, unwrapped, functions on the html/template side. html/template: avoid race when escaping updates template For #39807 Fixes #43855 Change-Id: I2ce91321ada06ea496a982aefe170eb5af9ba847 Reviewed-on: https://go-review.googlesource.com/c/go/+/285957 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
2021-01-07html/template: attach functions to namespaceIan Lance Taylor
The text/template functions are stored in a data structure shared by all related templates, so do the same with the original, unwrapped, functions on the html/template side. For #39807 Fixes #43295 Change-Id: I9f64a0a601f1151c863a2833b5be2baf649b6cef Reviewed-on: https://go-review.googlesource.com/c/go/+/279492 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
2020-12-17html/template: avoid race when escaping updates templateIan Lance Taylor
Fixes #39807 Change-Id: Icf384f800e2541bc753507daa3a9bc7e5d1c3f79 Reviewed-on: https://go-review.googlesource.com/c/go/+/274450 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Roberto Clapis <roberto@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2020-12-09all: update to use os.ReadFile, os.WriteFile, os.CreateTemp, os.MkdirTempRuss Cox
As part of #42026, these helpers from io/ioutil were moved to os. (ioutil.TempFile and TempDir became os.CreateTemp and MkdirTemp.) Update the Go tree to use the preferred names. As usual, code compiled with the Go 1.4 bootstrap toolchain and code vendored from other sources is excluded. ReadDir changes are in a separate CL, because they are not a simple search and replace. For #42026. Change-Id: If318df0216d57e95ea0c4093b89f65e5b0ababb3 Reviewed-on: https://go-review.googlesource.com/c/go/+/266365 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-12-01encoding/json: revert "add "json: " prefix to SyntaxError messages"Kevin Burke
This reverts commit 6af088bfc66c13143c9ef46b4cf0805df77a8fbe. Reason for revert: Broke many tests inside Google which implies many tests were broken outside of Google as well. The tests may be brittle but still would require work to change and it's not clear it's worth the benefit. Updates #36221 Fixes #42675 Change-Id: Id3a14eb37e7119f5abe50e80dfbf120fdc44db72 Reviewed-on: https://go-review.googlesource.com/c/go/+/273747 Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com> Trust: Joe Tsai <thebrokentoaster@gmail.com>
2020-10-21encoding/json: add "json: " prefix to SyntaxError messagesKevin Burke
The other named errors - UnmarshalTypeError, etc - in this package do the same, so we should prepend the package prefix to error messages for consistency. Add a note to the release docs in case this is interpreted as a breaking change. Fixes #36221. Change-Id: Ie24b532bbf9812e108c259fa377e2a6b64319ed4 Reviewed-on: https://go-review.googlesource.com/c/go/+/263619 Run-TryBot: Kevin Burke <kev@inburke.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Kevin Burke <kev@inburke.com> Trust: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
2020-10-20all: update references to symbols moved from io/ioutil to ioRuss Cox
The old ioutil references are still valid, but update our code to reflect best practices and get used to the new locations. Code compiled with the bootstrap toolchain (cmd/asm, cmd/dist, cmd/compile, debug/elf) must remain Go 1.4-compatible and is excluded. Also excluded vendored code. For #41190. Change-Id: I6d86f2bf7bc37a9d904b6cee3fe0c7af6d94d5b1 Reviewed-on: https://go-review.googlesource.com/c/go/+/263142 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-10-20html/template, text/template: add ParseFSRuss Cox
Now templates can be parsed not just from operating system files but from arbitrary file systems, including zip files. For #41190. Change-Id: I2172001388ddb1f13defa6c5e644e8ec8703ee80 Reviewed-on: https://go-review.googlesource.com/c/go/+/243938 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2020-10-12text/template: allow newlines inside action delimitersRuss Cox
This allows multiline constructs like: {{"hello" | printf}} Now that unclosed actions can span multiple lines, track and report the start of the action when reporting errors. Also clean up a few "unexpected <error message>" to be just "<error message>". Fixes #29770. Change-Id: I54c6c016029a8328b7902a4b6d85eab713ec3285 Reviewed-on: https://go-review.googlesource.com/c/go/+/254257 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2020-08-28text/template: add CommentNode to template parse treeAriel Mashraki
Fixes #34652 Change-Id: Icf6e3eda593fed826736f34f95a9d66f5450cc98 Reviewed-on: https://go-review.googlesource.com/c/go/+/229398 Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-07-14html/template: add tests from text/templateRuss Cox
Copy and adapt tests from text/template, to exercise more of html/template's copy. Various differences in behavior are flagged with NOTE comments or t.Skip and documented in #40075. Many of them are probably bugs. One clarifying test case added to both text/template and html/template. No changes to the package itself. Change-Id: Ifefad83d647db846040d24c2741a0244b00ade82 Reviewed-on: https://go-review.googlesource.com/c/go/+/241084 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2020-06-08all: avoid awkward wording from CL 236857Russ Cox
CL 236857 removed all uses of whitelist/blacklist, which is great. But it substituted awkward phrasing using allowlist/blocklist, especially as verbs or participles. This CL uses more standard English, like "allow the function" or "blocked functions" instead of "allowlist the function" or "blocklisted functions". Change-Id: I9106a2fdbd62751c4cbda3a77181358a8a6d0f13 Reviewed-on: https://go-review.googlesource.com/c/go/+/236917 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-08all: replace usages of whitelist/blacklist and master/slaveFilippo Valsorda
There's been plenty of discussion on the usage of these terms in tech. I'm not trying to have yet another debate. It's clear that there are people who are hurt by them and who are made to feel unwelcome by their use due not to technical reasons but to their historical and social context. That's simply enough reason to replace them. Anyway, allowlist and blocklist are more self-explanatory than whitelist and blacklist, so this change has negative cost. Didn't change vendored, bundled, and minified files. Nearly all changes are tests or comments, with a couple renames in cmd/link and cmd/oldlink which are extremely safe. This should be fine to land during the freeze without even asking for an exception. Change-Id: I8fc54a3c8f9cc1973b710bbb9558a9e45810b896 Reviewed-on: https://go-review.googlesource.com/c/go/+/236857 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Khosrow Moossavi <khos2ow@gmail.com> Reviewed-by: Leigh McCulloch <leighmcc@gmail.com> Reviewed-by: Urban Ishimwe <urbainishimwe@gmail.com>
2020-04-16html/template,text/template: switch to Unicode escapes for JSON compatibilityempijei
The existing implementation is not compatible with JSON escape as it uses hex escaping. Unicode escape, instead, is valid for both JSON and JS. This fix avoids creating a separate escaping context for scripts of type "application/ld+json" and it is more future-proof in case more JSON+JS contexts get added to the platform (e.g. import maps). Fixes #33671 Fixes #37634 Change-Id: Id6f6524b4abc52e81d9d744d46bbe5bf2e081543 Reviewed-on: https://go-review.googlesource.com/c/go/+/226097 Reviewed-by: Carl Johnson <me@carlmjohnson.net> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-01-13html: update URL in commentfujimoto kyosuke
The comment contained a link that had a file name and ID that no longer existed, so change to the URL of the corresponding part of the latest page. Change-Id: I74e0885aabf470facc39b84035f7a83fef9c6a8e GitHub-Last-Rev: 5681c84d9f1029449da6860c65a1d9a128296e85 GitHub-Pull-Request: golang/go#36514 Reviewed-on: https://go-review.googlesource.com/c/go/+/214181 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-11-21text/template: harden JSEscape to also escape ampersand and equalRoberto Clapis
Ampersand and equal are not dangerous in a JS/JSString context but they might cause issues if interpolated in HTML attributes. This change makes it harder to introduce XSS by misusing escaping. Thanks to t1ddl3r <t1ddl3r@gmail.com> for reporting this common misuse scenario. Fixes #35665 Change-Id: Ice6416477bba4cb2ba2fe2cfdc20e027957255c0 Reviewed-on: https://go-review.googlesource.com/c/go/+/207637 Reviewed-by: Filippo Valsorda <filippo@golang.org> Reviewed-by: Mike Samuel <mikesamuel@gmail.com> Reviewed-by: Andrew Bonventre <andybons@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
2019-09-27html/template: document handling of namespaced and data- attributesJustin Nuß
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 <andybons@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Andrew Bonventre <andybons@golang.org>
2019-08-27html/template: micro optimization for isJSTypeDong-hee Na
There is an unnecessary lower operation in isJSType. Simple logic fix can improve tiny performance. name old time/op new time/op delta isJSType-8 152ns ± 0% 58ns ± 7% -61.82% (p=0.001 n=6+8) name old alloc/op new alloc/op delta isJSType-8 32.0B ± 0% 0.0B -100.00% (p=0.000 n=8+8) name old allocs/op new allocs/op delta isJSType-8 1.00 ± 0% 0.00 -100.00% (p=0.000 n=8+8) Change-Id: I281aadf1677d4377920c9649af206381189a27e6 Reviewed-on: https://go-review.googlesource.com/c/go/+/177118 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
2019-06-17html/template, text/template: document glob semanticsAndrew Gerrand
This change updates the doc comments of the various ParseGlob functions and methods to state that they use the semantics of filepath.Match when matching the file name pattern. Fixes #30608 Change-Id: Iee4bdc0a2a2f8647d1f9a910e4d72a5de9204d11 Reviewed-on: https://go-review.googlesource.com/c/go/+/179739 Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2019-06-17html/template: handle nil Error values in context.StringSamuel Tan
Add a special case to print a generic nil error when context.err is nil. Previously, this case was unchecked, leading to a call to (*Error).Error with a nil receiver, which was triggering a nil pointer access. However, this bug was masked by the panic-recovery code in package fmt. I tested this change by running `dlv test` in src/html/template, running the `continue` command, and verifying that no "bad access" errors are returned. Fixes #28854 Change-Id: I0b637b943de003d9efc294f6f1e49b793668d037 Reviewed-on: https://go-review.googlesource.com/c/go/+/181579 Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2019-05-06html/template: add support for JavaScript modulesAndrew Bonventre
html/template does not properly treat JavaScript code as JavaScript when using a <script> tag with "module" set as the type attribute. See also: https://www.w3.org/TR/html5/semantics-scripting.html#element-attrdef-script-type and https://html.spec.whatwg.org/multipage/scripting.html#the-script-element:module-script-2 Original change from tomut at https://golang.org/cl/135417 Fixes #31327 Change-Id: I6239be69cd7994990d091400664e4474124a98fc Reviewed-on: https://go-review.googlesource.com/c/go/+/175218 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-04-30html: add a Fuzz functionRomain Baugue
Adds a sample Fuzz test function to package html based on https://github.com/dvyukov/go-fuzz-corpus/blob/master/stdhtml/main.go Updates #19109 Updates #31309 Change-Id: I8c49fff8f70fc8a8813daf1abf0044752003adbb Reviewed-on: https://go-review.googlesource.com/c/go/+/174301 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-03-02html/template: prevent test from failing with nil pointer dereferenceMarat Khabibullin
The variable err could have nil value when we call err.Error(), because after we check it for nil above we continue the test (t.Errorf doesn't stop the test execution). Updates #30208 Change-Id: I6f7a8609f2453f622a1fa94a50c99d2e04d5fbcd GitHub-Last-Rev: 3a5d9b1e9e202327af17cc1b93bfa69f6701af84 GitHub-Pull-Request: golang/go#30215 Reviewed-on: https://go-review.googlesource.com/c/162477 Reviewed-by: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-02-26html/template: use strings.BuilderJosh Bleecher Snyder
...and size initial buffers more accurately. Easy pickings only. More might remain. name old time/op new time/op delta CSSEscaper-8 1.17µs ± 1% 0.80µs ± 2% -31.55% (p=0.000 n=44+48) CSSEscaperNoSpecials-8 205ns ± 2% 204ns ± 3% -0.73% (p=0.014 n=46+49) DecodeCSS-8 438ns ± 2% 436ns ± 2% ~ (p=0.099 n=48+47) DecodeCSSNoSpecials-8 6.11ns ± 3% 5.93ns ± 3% -2.85% (p=0.000 n=50+48) CSSValueFilter-8 149ns ± 0% 145ns ± 0% -2.68% (p=0.000 n=32+35) CSSValueFilterOk-8 238ns ± 2% 234ns ± 2% -1.40% (p=0.000 n=49+47) EscapedExecute-8 2.53µs ± 2% 2.55µs ± 1% +0.87% (p=0.000 n=48+49) HTMLNospaceEscaper-8 1.35µs ± 2% 0.92µs ± 1% -31.74% (p=0.000 n=48+48) HTMLNospaceEscaperNoSpecials-8 278ns ± 2% 263ns ± 2% -5.17% (p=0.000 n=47+49) StripTags-8 778ns ± 2% 786ns ± 1% +0.96% (p=0.000 n=46+47) StripTagsNoSpecials-8 84.2ns ± 1% 84.1ns ± 1% ~ (p=0.300 n=48+48) JSValEscaperWithNum-8 506ns ± 2% 486ns ± 3% -3.82% (p=0.000 n=47+45) JSValEscaperWithStr-8 1.61µs ± 1% 1.64µs ± 1% +1.75% (p=0.000 n=44+49) JSValEscaperWithStrNoSpecials-8 548ns ± 2% 552ns ± 2% +0.78% (p=0.000 n=48+46) JSValEscaperWithObj-8 1.91µs ± 2% 1.87µs ± 1% -2.08% (p=0.000 n=49+47) JSValEscaperWithObjNoSpecials-8 735ns ± 2% 742ns ± 2% +1.01% (p=0.000 n=47+49) JSStrEscaperNoSpecials-8 228ns ± 4% 211ns ± 3% -7.53% (p=0.000 n=50+49) JSStrEscaper-8 1.11µs ± 1% 0.78µs ± 1% -29.94% (p=0.000 n=48+48) JSRegexpEscaperNoSpecials-8 214ns ± 2% 212ns ± 3% -1.12% (p=0.000 n=50+49) JSRegexpEscaper-8 1.17µs ± 0% 0.79µs ± 1% -31.92% (p=0.000 n=48+47) TemplateSpecialTags-8 172µs ± 1% 172µs ± 1% ~ (p=0.976 n=48+47) URLEscaper-8 1.88µs ± 2% 1.87µs ± 2% -0.56% (p=0.001 n=49+49) URLEscaperNoSpecials-8 162ns ± 1% 169ns ± 1% +3.76% (p=0.000 n=49+50) URLNormalizer-8 1.29µs ± 3% 1.29µs ± 2% -0.37% (p=0.041 n=48+48) URLNormalizerNoSpecials-8 185ns ± 1% 186ns ± 1% +0.15% (p=0.013 n=49+49) SrcsetFilter-8 616ns ± 1% 618ns ± 1% +0.36% (p=0.000 n=46+46) SrcsetFilterNoSpecials-8 359ns ± 0% 352ns ± 0% -1.93% (p=0.000 n=40+43) [Geo mean] 560ns 525ns -6.17% name old alloc/op new alloc/op delta CSSEscaper-8 672B ± 0% 336B ± 0% -50.00% (p=0.000 n=50+50) CSSEscaperNoSpecials-8 0.00B 0.00B ~ (all equal) DecodeCSS-8 160B ± 0% 160B ± 0% ~ (all equal) DecodeCSSNoSpecials-8 0.00B 0.00B ~ (all equal) CSSValueFilter-8 96.0B ± 0% 96.0B ± 0% ~ (all equal) CSSValueFilterOk-8 48.0B ± 0% 48.0B ± 0% ~ (all equal) EscapedExecute-8 688B ± 0% 624B ± 0% -9.30% (p=0.000 n=50+50) HTMLNospaceEscaper-8 752B ± 0% 368B ± 0% -51.06% (p=0.000 n=50+50) HTMLNospaceEscaperNoSpecials-8 48.0B ± 0% 32.0B ± 0% -33.33% (p=0.000 n=50+50) StripTags-8 224B ± 0% 224B ± 0% ~ (all equal) StripTagsNoSpecials-8 112B ± 0% 112B ± 0% ~ (all equal) JSValEscaperWithNum-8 96.0B ± 0% 40.0B ± 0% -58.33% (p=0.000 n=50+50) JSValEscaperWithStr-8 384B ± 0% 384B ± 0% ~ (all equal) JSValEscaperWithStrNoSpecials-8 96.0B ± 0% 96.0B ± 0% ~ (all equal) JSValEscaperWithObj-8 448B ± 0% 448B ± 0% ~ (all equal) JSValEscaperWithObjNoSpecials-8 160B ± 0% 160B ± 0% ~ (all equal) JSStrEscaperNoSpecials-8 0.00B 0.00B ~ (all equal) JSStrEscaper-8 672B ± 0% 336B ± 0% -50.00% (p=0.000 n=50+50) JSRegexpEscaperNoSpecials-8 0.00B 0.00B ~ (all equal) JSRegexpEscaper-8 672B ± 0% 336B ± 0% -50.00% (p=0.000 n=50+50) TemplateSpecialTags-8 48.0kB ± 0% 47.9kB ± 0% -0.13% (p=0.000 n=50+48) URLEscaper-8 336B ± 0% 336B ± 0% ~ (all equal) URLEscaperNoSpecials-8 112B ± 0% 112B ± 0% ~ (all equal) URLNormalizer-8 176B ± 0% 176B ± 0% ~ (all equal) URLNormalizerNoSpecials-8 112B ± 0% 112B ± 0% ~ (all equal) SrcsetFilter-8 160B ± 0% 160B ± 0% ~ (all equal) SrcsetFilterNoSpecials-8 160B ± 0% 160B ± 0% ~ (all equal) [Geo mean] 259B 216B -16.60% name old allocs/op new allocs/op delta CSSEscaper-8 4.00 ± 0% 2.00 ± 0% -50.00% (p=0.000 n=50+50) CSSEscaperNoSpecials-8 0.00 0.00 ~ (all equal) DecodeCSS-8 1.00 ± 0% 1.00 ± 0% ~ (all equal) DecodeCSSNoSpecials-8 0.00 0.00 ~ (all equal) CSSValueFilter-8 2.00 ± 0% 2.00 ± 0% ~ (all equal) CSSValueFilterOk-8 3.00 ± 0% 3.00 ± 0% ~ (all equal) EscapedExecute-8 18.0 ± 0% 18.0 ± 0% ~ (all equal) HTMLNospaceEscaper-8 5.00 ± 0% 3.00 ± 0% -40.00% (p=0.000 n=50+50) HTMLNospaceEscaperNoSpecials-8 1.00 ± 0% 1.00 ± 0% ~ (all equal) StripTags-8 3.00 ± 0% 3.00 ± 0% ~ (all equal) StripTagsNoSpecials-8 2.00 ± 0% 2.00 ± 0% ~ (all equal) JSValEscaperWithNum-8 3.00 ± 0% 3.00 ± 0% ~ (all equal) JSValEscaperWithStr-8 2.00 ± 0% 2.00 ± 0% ~ (all equal) JSValEscaperWithStrNoSpecials-8 2.00 ± 0% 2.00 ± 0% ~ (all equal) JSValEscaperWithObj-8 3.00 ± 0% 3.00 ± 0% ~ (all equal) JSValEscaperWithObjNoSpecials-8 3.00 ± 0% 3.00 ± 0% ~ (all equal) JSStrEscaperNoSpecials-8 0.00 0.00 ~ (all equal) JSStrEscaper-8 4.00 ± 0% 2.00 ± 0% -50.00% (p=0.000 n=50+50) JSRegexpEscaperNoSpecials-8 0.00 0.00 ~ (all equal) JSRegexpEscaper-8 4.00 ± 0% 2.00 ± 0% -50.00% (p=0.000 n=50+50) TemplateSpecialTags-8 185 ± 0% 185 ± 0% ~ (all equal) URLEscaper-8 4.00 ± 0% 4.00 ± 0% ~ (all equal) URLEscaperNoSpecials-8 2.00 ± 0% 2.00 ± 0% ~ (all equal) URLNormalizer-8 3.00 ± 0% 3.00 ± 0% ~ (all equal) URLNormalizerNoSpecials-8 2.00 ± 0% 2.00 ± 0% ~ (all equal) SrcsetFilter-8 3.00 ± 0% 3.00 ± 0% ~ (all equal) SrcsetFilterNoSpecials-8 3.00 ± 0% 3.00 ± 0% ~ (all equal) [Geo mean] 3.41 3.05 -10.65% Change-Id: I809ea56495ce1881656af7e24621448ab64b449a Reviewed-on: https://go-review.googlesource.com/c/155919 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-02-26text/template: accept new number syntaxRuss Cox
This CL updates text/template's scanner to accept the new number syntaxes: - Hexadecimal floating-point values. - Digit-separating underscores. - Leading 0b and 0o prefixes. See golang.org/design/19308-number-literals for background. For #12711. For #19308. For #28493. For #29008. Change-Id: I68c16ea35c3f506701063781388de72bafee6b8d Reviewed-on: https://go-review.googlesource.com/c/160248 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2018-12-13text/html: escape MIME type "application/ld+json" as JavaScriptEvan Klitzke
Fixes #26053 Change-Id: Ic2052b1d0d4e0826a217a520c83d7bb0995ea72a GitHub-Last-Rev: 5a3eea3dd22b0a194591ce2294b88cb340df1e8d GitHub-Pull-Request: golang/go#26054 Reviewed-on: https://go-review.googlesource.com/c/120835 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2018-11-02all: use "reports whether" consistently in the few places that didn'tBrad Fitzpatrick
Go documentation style for boolean funcs is to say: // Foo reports whether ... func Foo() bool (rather than "returns true if") This CL also replaces 4 uses of "iff" with the same "reports whether" wording, which doesn't lose any meaning, and will prevent people from sending typo fixes when they don't realize it's "if and only if". In the past I think we've had the typo CLs updated to just say "reports whether". So do them all at once. (Inspired by the addition of another "returns true if" in CL 146938 in fd_plan9.go) Created with: $ perl -i -npe 's/returns true if/reports whether/' $(git grep -l "returns true iff" | grep -v vendor) $ perl -i -npe 's/returns true if/reports whether/' $(git grep -l "returns true if" | grep -v vendor) Change-Id: Ided502237f5ab0d25cb625dbab12529c361a8b9f Reviewed-on: https://go-review.googlesource.com/c/147037 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-09-26all: use strings.ReplaceAll and bytes.ReplaceAll where applicableBrad Fitzpatrick
I omitted vendor directories and anything necessary for bootstrapping. (Tested by bootstrapping with Go 1.4) Updates #27864 Change-Id: I7d9b68d0372d3a34dee22966cca323513ece7e8a Reviewed-on: https://go-review.googlesource.com/137856 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-08-30html/template: add an example for the Delims methodDmitry Neverov
Change-Id: I7ba55e3f6ebbaae41188316a66a40f994c037ad9 Reviewed-on: https://go-review.googlesource.com/132240 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-08-22html/template: use named consts instead of their valuesIskander Sharipov
Use defined named constants instead of 0 literal in comparisons. Found using https://go-critic.github.io/overview.html#namedConst-ref Change-Id: Ic075cece248f6e51db0b3d9d9eaba7d6409c9eef Reviewed-on: https://go-review.googlesource.com/123376 Run-TryBot: Iskander Sharipov <iskander.sharipov@intel.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-07-31html: lazily populate Unescape tablesBrad Fitzpatrick
Saves ~105KB of heap for callers who don't use html.UnescapeString. (EscapeString is much more common). Also saves 70KB of binary size, because now the linker can do dead code elimination. (because #2559 is still open and global maps always generate init code) Fixes #26727 Updates #6853 Change-Id: I18fe9a273097e2c7e0cb7f88205cae1bb60fa89b Reviewed-on: https://go-review.googlesource.com/127075 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-07-09html/template: ignore untyped nil arguments to default escapersIan Lance Taylor
CL 95215 changed text/template so that untyped nil arguments were no longer ignored, but were instead passed to functions as expected. This had an unexpected effect on html/template, where all data is implicitly passed to functions: originally untyped nil arguments were not passed and were thus effectively ignored, but after CL 95215 they were passed and were printed, typically as an escaped version of "<nil>". This CL restores some of the behavior of html/template by ignoring untyped nil arguments passed implicitly to escaper functions. While eliminating one change to html/template relative to earlier releases, this unfortunately introduces a different one: originally values of interface type with the value nil were printed as an escaped version of "<nil>". With this CL they are ignored as though they were untyped nil values. My judgement is that this is a less common case. We'll see. This CL adds some tests of typed and untyped nil values to html/template and text/template to capture the current behavior. Updates #18716 Fixes #25875 Change-Id: I5912983ca32b31ece29e929e72d503b54d7b0cac Reviewed-on: https://go-review.googlesource.com/121815 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-06-22text/template/parse: undo breaking API changesDaniel Theophanes
golang.org/cl/84480 altered the API for the parse package for clarity and consistency. However, the changes also broke the API for consumers of the package. This CL reverts the API to the previous spelling, adding only a single new exported symbol. Fixes #25968 Change-Id: Ieb81054b61eeac7df3bc3864ef446df43c26b80f Reviewed-on: https://go-review.googlesource.com/120355 Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Rob Pike <r@golang.org> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-06-01all: update comment URLs from HTTP to HTTPS, where possibleTim Cooper
Each URL was manually verified to ensure it did not serve up incorrect content. Change-Id: I4dc846227af95a73ee9a3074d0c379ff0fa955df Reviewed-on: https://go-review.googlesource.com/115798 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org>
2018-05-09html/template: always write untyped nil as JS nullDaniel Martí
text/template recently added support for passing untyped nil as function call arguments, as those would be mixed up with "missing argument" values before. See CL 95215. html/template now needs a small change to adapt to that new possibility. In particular, when printing values as JS bytes, its code was written under the assumption that the values would never be untyped nil - that is, the reflect.Value would always be valid. Short-circuit indirectToJSONMarshaler on an untyped nil, to avoid the panic and fall back to the existing " null " output. Before this change and on 1.10, printing a typed nil and an untyped nil resulted in: null "" After this change, one will get: null null Fixes #24717. Change-Id: I03cd10ef64b96e837bacc9ccf4cf25624d80de1c Reviewed-on: https://go-review.googlesource.com/109215 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rhys Hiltner <rhys@justin.tv> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-04-10text/template: copy Decl field when copying PipeNodeIan Lance Taylor
Fixes #24791 Change-Id: I62ac17313e6e09796586911d88191a36d67f9aa1 Reviewed-on: https://go-review.googlesource.com/106115 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-04-06html/template: grow srcset buffer in proportion to needRhys Hiltner
In particular, avoid exponential memory usage from growing it in proportion to its current size. Fixes #24731 Change-Id: I277d2fbac2ef7b00ae4b83d6d1dcd7f2e630a5cd Reviewed-on: https://go-review.googlesource.com/105155 Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-04-04go/printer, gofmt: tuned table alignment for better resultsRobert Griesemer
The go/printer (and thus gofmt) uses a heuristic to determine whether to break alignment between elements of an expression list which is spread across multiple lines. The heuristic only kicked in if the entry sizes (character length) was above a certain threshold (20) and the ratio between the previous and current entry size was above a certain value (4). This heuristic worked reasonably most of the time, but also led to unfortunate breaks in many cases where a single entry was suddenly much smaller (or larger) then the previous one. The behavior of gofmt was sufficiently mysterious in some of these situations that many issues were filed against it. The simplest solution to address this problem is to remove the heuristic altogether and have a programmer introduce empty lines to force different alignments if it improves readability. The problem with that approach is that the places where it really matters, very long tables with many (hundreds, or more) entries, may be machine-generated and not "post-processed" by a human (e.g., unicode/utf8/tables.go). If a single one of those entries is overlong, the result would be that the alignment would force all comments or values in key:value pairs to be adjusted to that overlong value, making the table hard to read (e.g., that entry may not even be visible on screen and all other entries seem spaced out too wide). Instead, we opted for a slightly improved heuristic that behaves much better for "normal", human-written code. 1) The threshold is increased from 20 to 40. This disables the heuristic for many common cases yet even if the alignment is not "ideal", 40 is not that many characters per line with todays screens, making it very likely that the entire line remains "visible" in an editor. 2) Changed the heuristic to not simply look at the size ratio between current and previous line, but instead considering the geometric mean of the sizes of the previous (aligned) lines. This emphasizes the "overall picture" of the previous lines, rather than a single one (which might be an outlier). 3) Changed the ratio from 4 to 2.5. Now that we ignore sizes below 40, a ratio of 4 would mean that a new entry would have to be 4 times bigger (160) or smaller (10) before alignment would be broken. A ratio of 2.5 seems more sensible. Applied updated gofmt to all of src and misc. Also tested against several former issues that complained about this and verified that the output for the given examples is satisfactory (added respective test cases). Some of the files changed because they were not gofmt-ed in the first place. For #644. For #7335. For #10392. (and probably more related issues) Fixes #22852. Change-Id: I5e48b3d3b157a5cf2d649833b7297b33f43a6f6e
2018-04-04text/template: add variable assignmentsDaniel Martí
Variables can be declared and shadowing is supported, but modifying existing variables via assignments was not available. This meant that modifying a variable from a nested block was not possible: {{ $v := "init" }} {{ if true }} {{ $v := "changed" }} {{ end }} v: {{ $v }} {{/* "init" */}} Introduce the "=" assignment token, such that one can now do: {{ $v := "init" }} {{ if true }} {{ $v = "changed" }} {{ end }} v: {{ $v }} {{/* "changed" */}} To avoid confusion, rename PipeNode.Decl to PipeNode.Vars, as the variables may not always be declared after this change. Also change a few other names to better reflect the added ambiguity of variables in pipelines. Modifying the text/template/parse package in a backwards incompatible manner is acceptable, given that the package godoc clearly states that it isn't intended for general use. It's the equivalent of an internal package, back when internal packages didn't exist yet. To make the changes to the parse package sit well with the cmd/api test, update except.txt with the changes that we aren't worried about. Fixes #10608. Change-Id: I1f83a4297ee093fd45f9993cebb78fc9a9e81295 Reviewed-on: https://go-review.googlesource.com/84480 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2018-03-30html/template: fix one more lint naming errorSamuel Tan
Change-Id: I629d89d5065271f3b92dde8b12f0e743c9bde8f0 Reviewed-on: https://go-review.googlesource.com/103595 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-03-29html/template: fix lint errorsSamuel Tan
Change-Id: If56bd72917a9cbf5920ae8b5a36dc67f10959b94 Reviewed-on: https://go-review.googlesource.com/103175 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
2018-02-20all: fix misspellingsShawn Smith
GitHub-Last-Rev: 468df242d07419c228656985702325aa78952d99 GitHub-Pull-Request: golang/go#23935 Change-Id: If751ce3ffa3a4d5e00a3138211383d12cb6b23fc Reviewed-on: https://go-review.googlesource.com/95577 Run-TryBot: Andrew Bonventre <andybons@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Andrew Bonventre <andybons@golang.org>
2018-02-20all: remove duplicate word "the"Ryuma Yoshida
Change-Id: Ia5908e94a6bd362099ca3c63f6ffb7e94457131d GitHub-Last-Rev: 545a40571a912f433546d8c94a9d63459313515d GitHub-Pull-Request: golang/go#23942 Reviewed-on: https://go-review.googlesource.com/95435 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-02-20html/template: make more use of stringerDaniel Martí
The code was maintaining manual versions of it in multiple places - replace all of them. Change-Id: I04c3063877b05ba914de9f5dddb33ffe09f308fe Reviewed-on: https://go-review.googlesource.com/95356 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-02-19all: add more uses of stringerDaniel Martí
By grepping for ]string{$, one can find many manual implementations of stringer. The debug/dwarf ones needed the new -trimprefix flag, too. html/template was fairly simple, just implementing the fallback as stringer would. The changes there are trivial. The ones in debug/dwarf needed a bit of extra logic since the GoString wants to use its own format, depending on whether or not the value is one of the known constants. Change-Id: I501ea7deaa538fa425c8e9c2bb895f480169273f Reviewed-on: https://go-review.googlesource.com/77253 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-02-19html/template: remove unused funcDaniel Martí
Noticed while reading some code. Change-Id: I63f8c7a453d4895583a8ffc13bec57385b6944aa Reviewed-on: https://go-review.googlesource.com/95195 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-01-10html/template: check for duplicates when inserting escapersSamuel Tan
Ensure that we do not insert any escapers into pipelines that already contain an equivalent escaper. This prevents overescaping from occuring even when an aliased parse tree that has already been escaped is escaped again. Fixes #21844 Change-Id: Ic00d5e01c97ef09a4e49407009cf71b0d07f5c0e Reviewed-on: https://go-review.googlesource.com/83920 Reviewed-by: Russ Cox <rsc@golang.org>
2018-01-09Revert "html/template: prevent aliasing of parse Trees via AddParseTree"Samuel Tan
This reverts commit cd0a5f08293e1bf1fac41ae6438d495318cd52fb, which unnecessarily restricts the use of AddParseTree. Change-Id: I1155214a20ba08981d604404e79fff54874fd8e4 Reviewed-on: https://go-review.googlesource.com/83919 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2017-12-14html/template: add srcset content typeMike Samuel
Srcset is largely the same as a URL, but is escaped in URL contexts. Inside a srcset attribute, URLs have their commas percent-escaped to avoid having the URL be interpreted as multiple URLs. Srcset is placed in a srcset attribute literally. Fixes #17441 Change-Id: I676b544784c7e54954ddb91eeff242cab25d02c4 Reviewed-on: https://go-review.googlesource.com/38324 Reviewed-by: Kunpei Sakai <namusyaka@gmail.com> Reviewed-by: Mike Samuel <mikesamuel@gmail.com> Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>