LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package template | 5 package template |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "encoding/json" | 9 "encoding/json" |
10 "fmt" | 10 "fmt" |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 `¡<b class="foo">Hello</b>, <textarea>O'World</tex
tarea>!`, | 531 `¡<b class="foo">Hello</b>, <textarea>O'World</tex
tarea>!`, |
532 }, | 532 }, |
533 { | 533 { |
534 "typed HTML in attribute", | 534 "typed HTML in attribute", |
535 `<div title="{{.W}}">`, | 535 `<div title="{{.W}}">`, |
536 `<div title="¡Hello, O'World!">`, | 536 `<div title="¡Hello, O'World!">`, |
537 }, | 537 }, |
538 { | 538 { |
539 "typed HTML in script", | 539 "typed HTML in script", |
540 `<button onclick="alert({{.W}})">`, | 540 `<button onclick="alert({{.W}})">`, |
541 » » » `<button onclick="alert("&iexcl;\u003cb class=\&
#34;foo\"\u003eHello\u003c/b\u003e, \u003ctextarea\u003eO'World\u003c/te
xtarea\u003e!")">`, | 541 » » » `<button onclick="alert("\u0026iexcl;\u003cb class=\
"foo\"\u003eHello\u003c/b\u003e, \u003ctextarea\u003eO'World\u003c/t
extarea\u003e!")">`, |
542 }, | 542 }, |
543 { | 543 { |
544 "typed HTML in RCDATA", | 544 "typed HTML in RCDATA", |
545 `<textarea>{{.W}}</textarea>`, | 545 `<textarea>{{.W}}</textarea>`, |
546 `<textarea>¡<b class="foo">Hello<
/b>, <textarea>O'World</textarea>!</textarea>`, | 546 `<textarea>¡<b class="foo">Hello<
/b>, <textarea>O'World</textarea>!</textarea>`, |
547 }, | 547 }, |
548 { | 548 { |
549 "range in textarea", | 549 "range in textarea", |
550 "<textarea>{{range .A}}{{.}}{{end}}</textarea>", | 550 "<textarea>{{range .A}}{{.}}{{end}}</textarea>", |
551 "<textarea><a><b></textarea>", | 551 "<textarea><a><b></textarea>", |
(...skipping 1090 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1642 | 1642 |
1643 func BenchmarkEscapedExecute(b *testing.B) { | 1643 func BenchmarkEscapedExecute(b *testing.B) { |
1644 tmpl := Must(New("t").Parse(`<a onclick="alert('{{.}}')">{{.}}</a>`)) | 1644 tmpl := Must(New("t").Parse(`<a onclick="alert('{{.}}')">{{.}}</a>`)) |
1645 var buf bytes.Buffer | 1645 var buf bytes.Buffer |
1646 b.ResetTimer() | 1646 b.ResetTimer() |
1647 for i := 0; i < b.N; i++ { | 1647 for i := 0; i < b.N; i++ { |
1648 tmpl.Execute(&buf, "foo & 'bar' & baz") | 1648 tmpl.Execute(&buf, "foo & 'bar' & baz") |
1649 buf.Reset() | 1649 buf.Reset() |
1650 } | 1650 } |
1651 } | 1651 } |
LEFT | RIGHT |