1
0
mirror of https://github.com/golang/go synced 2024-10-03 22:21:22 -06:00
Commit Graph

172 Commits

Author SHA1 Message Date
Andrew Gerrand
c022943449 html/template: remove noescape support
This was never documented or properly implemented.

Fixes #3528.

R=mikesamuel, rsc
CC=golang-dev
https://golang.org/cl/7142048
2013-01-18 10:30:12 +11:00
Francesc Campoy
1590be9e6f html/template: Clarifying references to "text/template" in the documentation.
Fixes #4634.

R=adg, kevlar
CC=golang-dev
https://golang.org/cl/7066053
2013-01-14 12:11:22 +00:00
Shenghou Ma
42c8904fe1 all: fix the the typos
Fixes #4420.

R=golang-dev, rsc, remyoudompheng
CC=golang-dev
https://golang.org/cl/6854080
2012-11-22 02:58:24 +08:00
Robert Griesemer
465b9c35e5 gofmt: apply gofmt -w src misc
Remove trailing whitespace in comments.
No other changes.

R=r
CC=golang-dev
https://golang.org/cl/6815053
2012-10-30 13:38:01 -07:00
Robert Griesemer
af79568fde gofmt: apply gofmt -w -s src misc
Preparation for forthcoming CL 6624051: Will make it
easier to see if/what changes are incurred by it.

The alignment changes in this CL are due to CL 6610051
(fix to alignment heuristic) where it appears that an
old version of gofmt was run (and thus the correct
alignment updates were not done).

R=r
CC=golang-dev
https://golang.org/cl/6639044
2012-10-09 17:01:28 -07:00
Rob Pike
7f4b4c0c00 text/template: better error messages during execution,
They now show the correct name, the byte offset on the line, and context for the failed evaluation.
Before:
        template: three:7: error calling index: index out of range: 5
After:
        template: top:7:20: executing "three" at <index "hi" $>: error calling index: index out of range: 5
Here top is the template that was parsed to create the set, and the error appears with the action
starting at byte 20 of line 7 of "top", inside the template called "three", evaluating the expression
<index "hi" $>.

Also fix a bug in index: it didn't work on strings. Ouch.

Also fix bug in error for index: was showing type of index not slice.
The real previous error was:
        template: three:7: error calling index: can't index item of type int
The html/template package's errors can be improved by building on this;
I'll do that in a separate pass.

Extends the API for text/template/parse but only by addition of a field and method. The
old API still works.

Fixes #3188.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/6576058
2012-10-03 12:02:13 +10:00
Rob Pike
9050550c12 text/template: allow .Field access to parenthesized expressions
Change the grammar so that field access is a proper operator.
This introduces a new node, ChainNode, into the public (but
actually internal) API of text/template/parse. For
compatibility, we only use the new node type for the specific
construct, which was not parseable before. Therefore this
should be backward-compatible.

Before, .X.Y was a token in the lexer; this CL breaks it out
into .Y applied to .X. But for compatibility we mush them
back together before delivering. One day we might remove
that hack; it's the simple TODO in parse.go/operand.

This change also provides grammatical distinction between
        f
and
        (f)
which might permit function values later, but not now.

Fixes #3999.

R=golang-dev, dsymonds, gri, rsc, mikesamuel
CC=golang-dev
https://golang.org/cl/6494119
2012-09-24 13:23:15 +10:00
Russ Cox
37721cc1ce html/template: fix URL doc
This is the easy part of issue 3528.
(What to do about "noescape" is the hard part, left open.)

Update #3528.

R=mikesamuel, r, dsymonds
CC=golang-dev
https://golang.org/cl/6493113
2012-09-13 10:53:00 -04:00
David G. Andersen
e66d29cdcf pkg: Removing duplicated words ("of of", etc.), mostly from comments.
Ran 'double.pl' on the pkg tree to identify doubled words.
One change to an error string return in x509;  the rest are in comments.
Thanks to Matt Jibson for the idea.

R=golang-dev, bsiegert
CC=golang-dev
https://golang.org/cl/6344089
2012-07-09 09:16:10 +10:00
Nigel Tao
6277656d69 html, exp/html: escape ' and " as &#39; and &#34;, since IE8 and
below do not support &apos;.

This makes package html consistent with package text/template's
HTMLEscape function.

Fixes #3489.

R=rsc, mikesamuel, dsymonds
CC=golang-dev
https://golang.org/cl/5992071
2012-04-12 09:35:43 +10:00
David Symonds
4a59be0091 html/template: fix typo and make grammar consistent in comments.
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5866044
2012-03-21 10:10:44 +11:00
Rob Pike
49be7f7d0d html/template: add Templates and *Escape functions
to bring it in line with text/template's interface.
Fixes #3296.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/5843066
2012-03-20 14:38:07 +11:00
Rob Pike
214a1ca3c5 html/template: fix nil pointer bug
Fixes #3272.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5819046
2012-03-14 15:08:54 +11:00
Brad Fitzpatrick
5f32c8b88b html/template: fix panic on Clone
Fixes #3281

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5819044
2012-03-13 16:55:43 -07:00
Russ Cox
4084f08401 html/template: doc nit
Execute's data is untrusted regardless of package.

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/5797062
2012-03-12 14:26:10 -04:00
Scott Lawrence
30f9c99e3e html/template: fix comment typo
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5730051
2012-03-05 10:58:43 +11:00
David Symonds
289a1638aa html/template: encoding/json does more escaping now, so update the html/template test that uses it.
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5714052
2012-03-01 17:52:05 +11:00
Mike Rosset
4762e9d98c html/template: use correct method signature, in introduction example.
R=golang-dev, nigeltao
CC=golang-dev
https://golang.org/cl/5695067
2012-02-27 11:31:38 +11:00
Scott Lawrence
c05c3a9d11 html/template: make doctype check case-insensitive
Fixes #3094.

R=golang-dev, rsc, nigeltao
CC=golang-dev
https://golang.org/cl/5687065
2012-02-24 11:32:33 +11:00
Rob Pike
0ce6c87004 html/template: don't indirect past a Stringer
While we're here, get rid of the old names for the escaping functions.

Fixes #3073.

R=golang-dev, dsymonds, rsc
CC=golang-dev
https://golang.org/cl/5685049
2012-02-20 14:23:45 +11:00
David Symonds
bcb7a85334 html/template: minor tweak to docs to improve HTML typography.
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5684046
2012-02-20 11:43:34 +11:00
Rob Pike
701fb580bd html/template: replace obsolete reference to template.Set
Fixes #3053.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/5656094
2012-02-18 16:02:51 +11:00
Rob Pike
dfef0c2dcc html/template: clone is implemented elsewhere, so delete this implementation
R=golang-dev, nigeltao
CC=golang-dev
https://golang.org/cl/5676064
2012-02-16 17:36:06 +11:00
Nigel Tao
0c5239410e html/template: add Clone and AddParseTree. Make text/template's Clone
return (*Template, error), not just *Template.

Fixes #2757.

R=r
CC=golang-dev
https://golang.org/cl/5665044
2012-02-15 16:16:30 +11:00
Bjorn Tipling
5b663057b7 html/template: Added more explicit wording about examples and documentation.
R=golang-dev, r, r
CC=golang-dev
https://golang.org/cl/5654062
2012-02-12 12:18:00 +11:00
Rob Pike
5be24046c7 all: avoid bytes.NewBuffer(nil)
The practice encourages people to think this is the way to
create a bytes.Buffer when new(bytes.Buffer) or
just var buf bytes.Buffer work fine.
(html/token.go was missing the point altogether.)

R=golang-dev, bradfitz, r
CC=golang-dev
https://golang.org/cl/5637043
2012-02-06 14:09:00 +11:00
Nigel Tao
e066db3acb html: add package doc.
Fixes #2857.

R=r, adg
CC=golang-dev
https://golang.org/cl/5635046
2012-02-06 13:24:45 +11:00
Nigel Tao
102638cb53 std: add struct field tags to untagged literals.
R=rsc, dsymonds, bsiegert, rogpeppe
CC=golang-dev
https://golang.org/cl/5619052
2012-02-03 10:12:25 +11:00
Robert Griesemer
f3f5239d1e all packages: fix various typos
Detected semi-automatically. There are probably more.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/5620046
2012-02-01 16:19:36 -08:00
Russ Cox
2050a9e478 build: remove Make.pkg, Make.tool
Consequently, remove many package Makefiles,
and shorten the few that remain.

gomake becomes 'go tool make'.

Turn off test phases of run.bash that do not work,
flagged with $BROKEN.  Future CLs will restore these,
but this seemed like a big enough CL already.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5601057
2012-01-30 23:43:46 -05:00
Nigel Tao
324513bc5f html: move the HTML parser to an exp/html package. The parser is a
work in progress, and we are not ready to freeze its API for Go 1.

Package html still exists, containing just two functions: EscapeString
and UnescapeString.

Both the packages at exp/html and html are "package html". The former
is a superset of the latter.

At some point in the future, the exp/html code will move back into
html, once we have finalized the parser API.

R=rsc, dsymonds
CC=golang-dev
https://golang.org/cl/5571059
2012-01-25 10:54:59 +11:00
Gustavo Niemeyer
369454d7b2 html/template: fix docs after API changes
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5528109
2012-01-19 21:49:28 -02:00
Rob Pike
c837e612bd text/template/parse: use human error prints
The previous version of all the node.String methods printed the parse
tree and was useful for developing the parse tree code. Now that that's done,
we might as well print the nodes using the standard template syntax.
It's much easier to read and makes error reporting look more natural.

Helps issue 2644.

R=rsc, n13m3y3r
CC=golang-dev
https://golang.org/cl/5553066
2012-01-19 13:51:37 -08:00
Nigel Tao
b4829c1de6 html: in foreign content, check for HTML integration points in breakout
elements.

Pass tests10.dat, test 33:
<!DOCTYPE html><svg><desc><svg><ul>a

| <!DOCTYPE html>
| <html>
|   <head>
|   <body>
|     <svg svg>
|       <svg desc>
|         <svg svg>
|         <ul>
|           "a"

Also pass test 34:
<!DOCTYPE html><p><svg><desc><p>

R=andybalholm, dsymonds
CC=golang-dev
https://golang.org/cl/5536048
2012-01-19 17:41:10 +11:00
Mike Samuel
b1d6fa517c html/template: reenable testcases and fix mis-escaped sequences.
Tighter octal parsing broke some tests and were disabled in
https://golang.org/cl/5530051

Those tests were broken.  The CSS decoder was supposed to see CSS
hex escape sequences of the form '\' <hex>+, but those escape
sequences were instead being consumed by the template parser.

This change properly escapes those escape sequences, and uses
proper escaping for NULs.

R=golang-dev, rsc, nigeltao
CC=golang-dev
https://golang.org/cl/5529073
2012-01-11 18:47:03 -05:00
Nigel Tao
aa033c20b3 html: propagate foreign namespaces only when adding foreign content.
Pass tests10.dat, test 31:
<div><svg><path><foreignObject><p></div>a

| <html>
|   <head>
|   <body>
|     <div>
|       <svg svg>
|         <svg path>
|           <svg foreignObject>
|             <p>
|               "a"

Also pass test 32:
<!DOCTYPE html><svg><desc><div><svg><ul>a

R=andybalholm
CC=golang-dev
https://golang.org/cl/5527064
2012-01-11 10:15:40 +11:00
Sameer Ajmani
cbf4f4b8d0 strconv: return ErrSyntax when unquoting illegal octal sequences. This
is consistent with what the Go compiler returns when such sequences
appear in string literals.

Fixes #2658.

R=golang-dev, rsc, r, r, nigeltao
CC=golang-dev
https://golang.org/cl/5530051
2012-01-09 19:55:18 -05:00
Nigel Tao
748fab9d11 html: foreign element HTML integration points, tag name adjustment,
shorten the MathML namespace abbreviation from "mathml" to "math".
Python's html5lib uses "mathml", but I think that that is an internal
implementation detail; the test cases use "math".

Pass tests10.dat, test 30:
<div><svg><path><foreignObject><math></div>a

| <html>
|   <head>
|   <body>
|     <div>
|       <svg svg>
|         <svg path>
|           <svg foreignObject>
|             <math math>
|               "a"

R=andybalholm
CC=golang-dev
https://golang.org/cl/5529044
2012-01-10 11:06:09 +11:00
Andrew Balholm
99fed2be27 html: parse <frameset> inside body
Pass tests6.dat, test 47:
<param><frameset></frameset>

| <html>
|   <head>
|   <frameset>

Also pass remaining tests in tests6.dat.

R=nigeltao
CC=golang-dev
https://golang.org/cl/5489136
2012-01-04 09:51:15 +11:00
Nigel Tao
d5e45e3a8a html: adjust foreign attributes.
Pass tests10.dat, test 22:
<!DOCTYPE html><body xlink:href=foo><svg xlink:href=foo></svg>

| <!DOCTYPE html>
| <html>
|   <head>
|   <body>
|     xlink:href="foo"
|     <svg svg>
|       xlink href="foo"

Also pass tests through test 29:
<div><svg><path></svg><path>

R=andybalholm
CC=golang-dev
https://golang.org/cl/5489117
2011-12-25 12:42:47 +11:00
Andrew Balholm
b28f017537 html: "in select in table" insertion mode.
Pass tests10.dat, test 16:
<!DOCTYPE
html><body><table><tr><td><select><svg><g>foo</g><g>bar</g><p>baz</table><p>quux

| <!DOCTYPE html>
| <html>
|   <head>
|   <body>
|     <table>
|       <tbody>
|         <tr>
|           <td>
|             <select>
|               "foobarbaz"
|     <p>
|       "quux"

Also pass tests through test 21:
<!DOCTYPE html><frameset></frameset><svg><g></g><g></g><p><span>

R=nigeltao
CC=golang-dev
https://golang.org/cl/5505069
2011-12-24 11:07:14 +11:00
Andrew Balholm
4a8ea4ae94 html: Don't ignore whitespace in "after after frameset" mode.
Pass tests6.dat, test 46:
<html><frameset></frameset></html>

| <html>
|   <head>
|   <frameset>
|   " "

R=nigeltao
CC=golang-dev
https://golang.org/cl/5505065
2011-12-23 11:07:11 +11:00
Nigel Tao
fe28d1aacf html: handle breakout tags in foreign content.
Also recognize that, in the latest version of the HTML5 spec,
foreign content is not an insertion mode, but a separate concern.

Pass tests10.dat, test 13:
<!DOCTYPE html><body><table><caption><svg><g>foo</g><g>bar</g><p>baz</table><p>quux

| <!DOCTYPE html>
| <html>
|   <head>
|   <body>
|     <table>
|       <caption>
|         <svg svg>
|           <svg g>
|             "foo"
|           <svg g>
|             "bar"
|         <p>
|           "baz"
|     <p>
|       "quux"

Also pass tests through test 15:
<!DOCTYPE html><body><table><colgroup><svg><g>foo</g><g>bar</g><p>baz</table><p>quux

R=andybalholm
CC=golang-dev
https://golang.org/cl/5494078
2011-12-21 10:00:41 +11:00
Rob Pike
4869996b92 template: better error message for empty templates
New("x").ParseFiles("y") can result in an empty "x" template.
Make the message clearer that this is the problem. The error
returns from both template packages in this case were
confusing.

I considered making the method use "x" instead of "y" in
this case, but that just made other situations confusing
and harder to explain.

Fixes #2594.

R=golang-dev, rsc, r
CC=golang-dev
https://golang.org/cl/5498048
2011-12-20 12:58:23 -08:00
Rob Pike
6b772462e4 panics: use the new facilities of testing.B instead
Lots of panics go away.
Also fix a name error in html/template.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5498045
2011-12-20 10:36:25 -08:00
Andrew Balholm
a0bd46e70f html: ignore <caption>, <col>, <tbody> etc. when parsing table fragments
Pass tests6.dat, test 36:
<caption><col><colgroup><tbody><tfoot><thead><tr>

| <tr>

Pass tests through test 44:
<body></body></html>

R=nigeltao
CC=golang-dev
https://golang.org/cl/5494055
2011-12-20 10:57:06 +11:00
Nigel Tao
18e8441476 html: handle text nodes in foreign content.
Passes tests10.dat, test 6:
<!DOCTYPE html><body><table><svg><g>foo</g></svg></table>

| <!DOCTYPE html>
| <html>
|   <head>
|   <body>
|     <svg svg>
|       <svg g>
|         "foo"
|     <table>

Also pass tests through test 12:
<!DOCTYPE html><body><table><caption><svg><g>foo</g><g>bar</g></svg><p>baz</caption></table>

R=andybalholm
CC=golang-dev
https://golang.org/cl/5495061
2011-12-19 12:20:00 +11:00
Nigel Tao
a369004e23 html: handle end tags in foreign objects.
I'm not 100% sure I get all the corner cases right, for end tags, but
I'll let the test suite smoke it out.

Pass tests10.dat, test 1:
<!DOCTYPE html><svg></svg><![CDATA[a]]>

| <!DOCTYPE html>
| <html>
|   <head>
|   <body>
|     <svg svg>
|     <!-- [CDATA[a]] -->

Also pass tests through test 5:
<!DOCTYPE html><body><table><svg></svg></table>

R=andybalholm
CC=golang-dev
https://golang.org/cl/5495044
2011-12-16 09:36:50 +11:00
Andrew Balholm
85fdd68bd9 html: don't leave "in column group" mode when ignoring a token
Pass tests6.dat, test 26:
foo<col>

| <col>

Also pass tests through test 35:
<table><tr><div><td>

R=nigeltao
CC=golang-dev
https://golang.org/cl/5482074
2011-12-15 10:45:19 +11:00
Rob Pike
1402d1a686 html/template: define the FuncMap type locally
This redefinition means that the public signature of html/template
does not refer to text/template.

Fixes #2546.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5487083
2011-12-14 11:22:17 -08:00