Browse Source

Added vendor directory containing HTML parser

Wirecog 6 years ago
parent
commit
88f8e4fc9a
100 changed files with 26404 additions and 0 deletions
  1. 10
    0
      vendor/golang.org/x/net/.gitattributes
  2. 2
    0
      vendor/golang.org/x/net/.gitignore
  3. 3
    0
      vendor/golang.org/x/net/AUTHORS
  4. 31
    0
      vendor/golang.org/x/net/CONTRIBUTING.md
  5. 3
    0
      vendor/golang.org/x/net/CONTRIBUTORS
  6. 27
    0
      vendor/golang.org/x/net/LICENSE
  7. 22
    0
      vendor/golang.org/x/net/PATENTS
  8. 3
    0
      vendor/golang.org/x/net/README
  9. 41
    0
      vendor/golang.org/x/net/bpf/asm.go
  10. 218
    0
      vendor/golang.org/x/net/bpf/constants.go
  11. 82
    0
      vendor/golang.org/x/net/bpf/doc.go
  12. 704
    0
      vendor/golang.org/x/net/bpf/instructions.go
  13. 525
    0
      vendor/golang.org/x/net/bpf/instructions_test.go
  14. 10
    0
      vendor/golang.org/x/net/bpf/setter.go
  15. 1
    0
      vendor/golang.org/x/net/bpf/testdata/all_instructions.bpf
  16. 79
    0
      vendor/golang.org/x/net/bpf/testdata/all_instructions.txt
  17. 140
    0
      vendor/golang.org/x/net/bpf/vm.go
  18. 512
    0
      vendor/golang.org/x/net/bpf/vm_aluop_test.go
  19. 192
    0
      vendor/golang.org/x/net/bpf/vm_bpf_test.go
  20. 49
    0
      vendor/golang.org/x/net/bpf/vm_extension_test.go
  21. 174
    0
      vendor/golang.org/x/net/bpf/vm_instructions.go
  22. 380
    0
      vendor/golang.org/x/net/bpf/vm_jump_test.go
  23. 246
    0
      vendor/golang.org/x/net/bpf/vm_load_test.go
  24. 115
    0
      vendor/golang.org/x/net/bpf/vm_ret_test.go
  25. 247
    0
      vendor/golang.org/x/net/bpf/vm_scratch_test.go
  26. 144
    0
      vendor/golang.org/x/net/bpf/vm_test.go
  27. 1
    0
      vendor/golang.org/x/net/codereview.cfg
  28. 54
    0
      vendor/golang.org/x/net/context/context.go
  29. 583
    0
      vendor/golang.org/x/net/context/context_test.go
  30. 74
    0
      vendor/golang.org/x/net/context/ctxhttp/ctxhttp.go
  31. 29
    0
      vendor/golang.org/x/net/context/ctxhttp/ctxhttp_17_test.go
  32. 147
    0
      vendor/golang.org/x/net/context/ctxhttp/ctxhttp_pre17.go
  33. 79
    0
      vendor/golang.org/x/net/context/ctxhttp/ctxhttp_pre17_test.go
  34. 105
    0
      vendor/golang.org/x/net/context/ctxhttp/ctxhttp_test.go
  35. 72
    0
      vendor/golang.org/x/net/context/go17.go
  36. 20
    0
      vendor/golang.org/x/net/context/go19.go
  37. 300
    0
      vendor/golang.org/x/net/context/pre_go17.go
  38. 109
    0
      vendor/golang.org/x/net/context/pre_go19.go
  39. 31
    0
      vendor/golang.org/x/net/context/withtimeout_test.go
  40. 210
    0
      vendor/golang.org/x/net/dict/dict.go
  41. 132
    0
      vendor/golang.org/x/net/dns/dnsmessage/example_test.go
  42. 1997
    0
      vendor/golang.org/x/net/dns/dnsmessage/message.go
  43. 1116
    0
      vendor/golang.org/x/net/dns/dnsmessage/message_test.go
  44. 78
    0
      vendor/golang.org/x/net/html/atom/atom.go
  45. 109
    0
      vendor/golang.org/x/net/html/atom/atom_test.go
  46. 648
    0
      vendor/golang.org/x/net/html/atom/gen.go
  47. 713
    0
      vendor/golang.org/x/net/html/atom/table.go
  48. 351
    0
      vendor/golang.org/x/net/html/atom/table_test.go
  49. 257
    0
      vendor/golang.org/x/net/html/charset/charset.go
  50. 237
    0
      vendor/golang.org/x/net/html/charset/charset_test.go
  51. 48
    0
      vendor/golang.org/x/net/html/charset/testdata/HTTP-charset.html
  52. 48
    0
      vendor/golang.org/x/net/html/charset/testdata/HTTP-vs-UTF-8-BOM.html
  53. 49
    0
      vendor/golang.org/x/net/html/charset/testdata/HTTP-vs-meta-charset.html
  54. 49
    0
      vendor/golang.org/x/net/html/charset/testdata/HTTP-vs-meta-content.html
  55. 47
    0
      vendor/golang.org/x/net/html/charset/testdata/No-encoding-declaration.html
  56. 9
    0
      vendor/golang.org/x/net/html/charset/testdata/README
  57. BIN
      vendor/golang.org/x/net/html/charset/testdata/UTF-16BE-BOM.html
  58. BIN
      vendor/golang.org/x/net/html/charset/testdata/UTF-16LE-BOM.html
  59. 49
    0
      vendor/golang.org/x/net/html/charset/testdata/UTF-8-BOM-vs-meta-charset.html
  60. 48
    0
      vendor/golang.org/x/net/html/charset/testdata/UTF-8-BOM-vs-meta-content.html
  61. 48
    0
      vendor/golang.org/x/net/html/charset/testdata/meta-charset-attribute.html
  62. 48
    0
      vendor/golang.org/x/net/html/charset/testdata/meta-content-attribute.html
  63. 102
    0
      vendor/golang.org/x/net/html/const.go
  64. 106
    0
      vendor/golang.org/x/net/html/doc.go
  65. 156
    0
      vendor/golang.org/x/net/html/doctype.go
  66. 2253
    0
      vendor/golang.org/x/net/html/entity.go
  67. 29
    0
      vendor/golang.org/x/net/html/entity_test.go
  68. 258
    0
      vendor/golang.org/x/net/html/escape.go
  69. 97
    0
      vendor/golang.org/x/net/html/escape_test.go
  70. 40
    0
      vendor/golang.org/x/net/html/example_test.go
  71. 226
    0
      vendor/golang.org/x/net/html/foreign.go
  72. 193
    0
      vendor/golang.org/x/net/html/node.go
  73. 146
    0
      vendor/golang.org/x/net/html/node_test.go
  74. 10
    0
      vendor/golang.org/x/net/html/offset.go
  75. 2094
    0
      vendor/golang.org/x/net/html/parse.go
  76. 388
    0
      vendor/golang.org/x/net/html/parse_test.go
  77. 271
    0
      vendor/golang.org/x/net/html/render.go
  78. 156
    0
      vendor/golang.org/x/net/html/render_test.go
  79. 2237
    0
      vendor/golang.org/x/net/html/testdata/go1.html
  80. 28
    0
      vendor/golang.org/x/net/html/testdata/webkit/README
  81. 194
    0
      vendor/golang.org/x/net/html/testdata/webkit/adoption01.dat
  82. 31
    0
      vendor/golang.org/x/net/html/testdata/webkit/adoption02.dat
  83. 135
    0
      vendor/golang.org/x/net/html/testdata/webkit/comments01.dat
  84. 370
    0
      vendor/golang.org/x/net/html/testdata/webkit/doctype01.dat
  85. 603
    0
      vendor/golang.org/x/net/html/testdata/webkit/entities01.dat
  86. 249
    0
      vendor/golang.org/x/net/html/testdata/webkit/entities02.dat
  87. 246
    0
      vendor/golang.org/x/net/html/testdata/webkit/html5test-com.dat
  88. 43
    0
      vendor/golang.org/x/net/html/testdata/webkit/inbody01.dat
  89. 40
    0
      vendor/golang.org/x/net/html/testdata/webkit/isindex.dat
  90. BIN
      vendor/golang.org/x/net/html/testdata/webkit/pending-spec-changes-plain-text-unsafe.dat
  91. 52
    0
      vendor/golang.org/x/net/html/testdata/webkit/pending-spec-changes.dat
  92. BIN
      vendor/golang.org/x/net/html/testdata/webkit/plain-text-unsafe.dat
  93. 308
    0
      vendor/golang.org/x/net/html/testdata/webkit/scriptdata01.dat
  94. 15
    0
      vendor/golang.org/x/net/html/testdata/webkit/scripted/adoption01.dat
  95. 28
    0
      vendor/golang.org/x/net/html/testdata/webkit/scripted/webkit01.dat
  96. 212
    0
      vendor/golang.org/x/net/html/testdata/webkit/tables01.dat
  97. 1952
    0
      vendor/golang.org/x/net/html/testdata/webkit/tests1.dat
  98. 799
    0
      vendor/golang.org/x/net/html/testdata/webkit/tests10.dat
  99. 482
    0
      vendor/golang.org/x/net/html/testdata/webkit/tests11.dat
  100. 0
    0
      vendor/golang.org/x/net/html/testdata/webkit/tests12.dat

+ 10
- 0
vendor/golang.org/x/net/.gitattributes View File

@@ -0,0 +1,10 @@
1
+# Treat all files in this repo as binary, with no git magic updating
2
+# line endings. Windows users contributing to Go will need to use a
3
+# modern version of git and editors capable of LF line endings.
4
+#
5
+# We'll prevent accidental CRLF line endings from entering the repo
6
+# via the git-review gofmt checks.
7
+#
8
+# See golang.org/issue/9281
9
+
10
+* -text

+ 2
- 0
vendor/golang.org/x/net/.gitignore View File

@@ -0,0 +1,2 @@
1
+# Add no patterns to .hgignore except for files generated by the build.
2
+last-change

+ 3
- 0
vendor/golang.org/x/net/AUTHORS View File

@@ -0,0 +1,3 @@
1
+# This source code refers to The Go Authors for copyright purposes.
2
+# The master list of authors is in the main Go distribution,
3
+# visible at http://tip.golang.org/AUTHORS.

+ 31
- 0
vendor/golang.org/x/net/CONTRIBUTING.md View File

@@ -0,0 +1,31 @@
1
+# Contributing to Go
2
+
3
+Go is an open source project.
4
+
5
+It is the work of hundreds of contributors. We appreciate your help!
6
+
7
+
8
+## Filing issues
9
+
10
+When [filing an issue](https://golang.org/issue/new), make sure to answer these five questions:
11
+
12
+1. What version of Go are you using (`go version`)?
13
+2. What operating system and processor architecture are you using?
14
+3. What did you do?
15
+4. What did you expect to see?
16
+5. What did you see instead?
17
+
18
+General questions should go to the [golang-nuts mailing list](https://groups.google.com/group/golang-nuts) instead of the issue tracker.
19
+The gophers there will answer or ask you to file an issue if you've tripped over a bug.
20
+
21
+## Contributing code
22
+
23
+Please read the [Contribution Guidelines](https://golang.org/doc/contribute.html)
24
+before sending patches.
25
+
26
+**We do not accept GitHub pull requests**
27
+(we use [Gerrit](https://code.google.com/p/gerrit/) instead for code review).
28
+
29
+Unless otherwise noted, the Go source files are distributed under
30
+the BSD-style license found in the LICENSE file.
31
+

+ 3
- 0
vendor/golang.org/x/net/CONTRIBUTORS View File

@@ -0,0 +1,3 @@
1
+# This source code was written by the Go contributors.
2
+# The master list of contributors is in the main Go distribution,
3
+# visible at http://tip.golang.org/CONTRIBUTORS.

+ 27
- 0
vendor/golang.org/x/net/LICENSE View File

@@ -0,0 +1,27 @@
1
+Copyright (c) 2009 The Go Authors. All rights reserved.
2
+
3
+Redistribution and use in source and binary forms, with or without
4
+modification, are permitted provided that the following conditions are
5
+met:
6
+
7
+   * Redistributions of source code must retain the above copyright
8
+notice, this list of conditions and the following disclaimer.
9
+   * Redistributions in binary form must reproduce the above
10
+copyright notice, this list of conditions and the following disclaimer
11
+in the documentation and/or other materials provided with the
12
+distribution.
13
+   * Neither the name of Google Inc. nor the names of its
14
+contributors may be used to endorse or promote products derived from
15
+this software without specific prior written permission.
16
+
17
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ 22
- 0
vendor/golang.org/x/net/PATENTS View File

@@ -0,0 +1,22 @@
1
+Additional IP Rights Grant (Patents)
2
+
3
+"This implementation" means the copyrightable works distributed by
4
+Google as part of the Go project.
5
+
6
+Google hereby grants to You a perpetual, worldwide, non-exclusive,
7
+no-charge, royalty-free, irrevocable (except as stated in this section)
8
+patent license to make, have made, use, offer to sell, sell, import,
9
+transfer and otherwise run, modify and propagate the contents of this
10
+implementation of Go, where such license applies only to those patent
11
+claims, both currently owned or controlled by Google and acquired in
12
+the future, licensable by Google that are necessarily infringed by this
13
+implementation of Go.  This grant does not include claims that would be
14
+infringed only as a consequence of further modification of this
15
+implementation.  If you or your agent or exclusive licensee institute or
16
+order or agree to the institution of patent litigation against any
17
+entity (including a cross-claim or counterclaim in a lawsuit) alleging
18
+that this implementation of Go or any code incorporated within this
19
+implementation of Go constitutes direct or contributory patent
20
+infringement, or inducement of patent infringement, then any patent
21
+rights granted to you under this License for this implementation of Go
22
+shall terminate as of the date such litigation is filed.

+ 3
- 0
vendor/golang.org/x/net/README View File

@@ -0,0 +1,3 @@
1
+This repository holds supplementary Go networking libraries.
2
+
3
+To submit changes to this repository, see http://golang.org/doc/contribute.html.

+ 41
- 0
vendor/golang.org/x/net/bpf/asm.go View File

@@ -0,0 +1,41 @@
1
+// Copyright 2016 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package bpf
6
+
7
+import "fmt"
8
+
9
+// Assemble converts insts into raw instructions suitable for loading
10
+// into a BPF virtual machine.
11
+//
12
+// Currently, no optimization is attempted, the assembled program flow
13
+// is exactly as provided.
14
+func Assemble(insts []Instruction) ([]RawInstruction, error) {
15
+	ret := make([]RawInstruction, len(insts))
16
+	var err error
17
+	for i, inst := range insts {
18
+		ret[i], err = inst.Assemble()
19
+		if err != nil {
20
+			return nil, fmt.Errorf("assembling instruction %d: %s", i+1, err)
21
+		}
22
+	}
23
+	return ret, nil
24
+}
25
+
26
+// Disassemble attempts to parse raw back into
27
+// Instructions. Unrecognized RawInstructions are assumed to be an
28
+// extension not implemented by this package, and are passed through
29
+// unchanged to the output. The allDecoded value reports whether insts
30
+// contains no RawInstructions.
31
+func Disassemble(raw []RawInstruction) (insts []Instruction, allDecoded bool) {
32
+	insts = make([]Instruction, len(raw))
33
+	allDecoded = true
34
+	for i, r := range raw {
35
+		insts[i] = r.Disassemble()
36
+		if _, ok := insts[i].(RawInstruction); ok {
37
+			allDecoded = false
38
+		}
39
+	}
40
+	return insts, allDecoded
41
+}

+ 218
- 0
vendor/golang.org/x/net/bpf/constants.go View File

@@ -0,0 +1,218 @@
1
+// Copyright 2016 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package bpf
6
+
7
+// A Register is a register of the BPF virtual machine.
8
+type Register uint16
9
+
10
+const (
11
+	// RegA is the accumulator register. RegA is always the
12
+	// destination register of ALU operations.
13
+	RegA Register = iota
14
+	// RegX is the indirection register, used by LoadIndirect
15
+	// operations.
16
+	RegX
17
+)
18
+
19
+// An ALUOp is an arithmetic or logic operation.
20
+type ALUOp uint16
21
+
22
+// ALU binary operation types.
23
+const (
24
+	ALUOpAdd ALUOp = iota << 4
25
+	ALUOpSub
26
+	ALUOpMul
27
+	ALUOpDiv
28
+	ALUOpOr
29
+	ALUOpAnd
30
+	ALUOpShiftLeft
31
+	ALUOpShiftRight
32
+	aluOpNeg // Not exported because it's the only unary ALU operation, and gets its own instruction type.
33
+	ALUOpMod
34
+	ALUOpXor
35
+)
36
+
37
+// A JumpTest is a comparison operator used in conditional jumps.
38
+type JumpTest uint16
39
+
40
+// Supported operators for conditional jumps.
41
+const (
42
+	// K == A
43
+	JumpEqual JumpTest = iota
44
+	// K != A
45
+	JumpNotEqual
46
+	// K > A
47
+	JumpGreaterThan
48
+	// K < A
49
+	JumpLessThan
50
+	// K >= A
51
+	JumpGreaterOrEqual
52
+	// K <= A
53
+	JumpLessOrEqual
54
+	// K & A != 0
55
+	JumpBitsSet
56
+	// K & A == 0
57
+	JumpBitsNotSet
58
+)
59
+
60
+// An Extension is a function call provided by the kernel that
61
+// performs advanced operations that are expensive or impossible
62
+// within the BPF virtual machine.
63
+//
64
+// Extensions are only implemented by the Linux kernel.
65
+//
66
+// TODO: should we prune this list? Some of these extensions seem
67
+// either broken or near-impossible to use correctly, whereas other
68
+// (len, random, ifindex) are quite useful.
69
+type Extension int
70
+
71
+// Extension functions available in the Linux kernel.
72
+const (
73
+	// extOffset is the negative maximum number of instructions used
74
+	// to load instructions by overloading the K argument.
75
+	extOffset = -0x1000
76
+	// ExtLen returns the length of the packet.
77
+	ExtLen Extension = 1
78
+	// ExtProto returns the packet's L3 protocol type.
79
+	ExtProto Extension = 0
80
+	// ExtType returns the packet's type (skb->pkt_type in the kernel)
81
+	//
82
+	// TODO: better documentation. How nice an API do we want to
83
+	// provide for these esoteric extensions?
84
+	ExtType Extension = 4
85
+	// ExtPayloadOffset returns the offset of the packet payload, or
86
+	// the first protocol header that the kernel does not know how to
87
+	// parse.
88
+	ExtPayloadOffset Extension = 52
89
+	// ExtInterfaceIndex returns the index of the interface on which
90
+	// the packet was received.
91
+	ExtInterfaceIndex Extension = 8
92
+	// ExtNetlinkAttr returns the netlink attribute of type X at
93
+	// offset A.
94
+	ExtNetlinkAttr Extension = 12
95
+	// ExtNetlinkAttrNested returns the nested netlink attribute of
96
+	// type X at offset A.
97
+	ExtNetlinkAttrNested Extension = 16
98
+	// ExtMark returns the packet's mark value.
99
+	ExtMark Extension = 20
100
+	// ExtQueue returns the packet's assigned hardware queue.
101
+	ExtQueue Extension = 24
102
+	// ExtLinkLayerType returns the packet's hardware address type
103
+	// (e.g. Ethernet, Infiniband).
104
+	ExtLinkLayerType Extension = 28
105
+	// ExtRXHash returns the packets receive hash.
106
+	//
107
+	// TODO: figure out what this rxhash actually is.
108
+	ExtRXHash Extension = 32
109
+	// ExtCPUID returns the ID of the CPU processing the current
110
+	// packet.
111
+	ExtCPUID Extension = 36
112
+	// ExtVLANTag returns the packet's VLAN tag.
113
+	ExtVLANTag Extension = 44
114
+	// ExtVLANTagPresent returns non-zero if the packet has a VLAN
115
+	// tag.
116
+	//
117
+	// TODO: I think this might be a lie: it reads bit 0x1000 of the
118
+	// VLAN header, which changed meaning in recent revisions of the
119
+	// spec - this extension may now return meaningless information.
120
+	ExtVLANTagPresent Extension = 48
121
+	// ExtVLANProto returns 0x8100 if the frame has a VLAN header,
122
+	// 0x88a8 if the frame has a "Q-in-Q" double VLAN header, or some
123
+	// other value if no VLAN information is present.
124
+	ExtVLANProto Extension = 60
125
+	// ExtRand returns a uniformly random uint32.
126
+	ExtRand Extension = 56
127
+)
128
+
129
+// The following gives names to various bit patterns used in opcode construction.
130
+
131
+const (
132
+	opMaskCls uint16 = 0x7
133
+	// opClsLoad masks
134
+	opMaskLoadDest  = 0x01
135
+	opMaskLoadWidth = 0x18
136
+	opMaskLoadMode  = 0xe0
137
+	// opClsALU
138
+	opMaskOperandSrc = 0x08
139
+	opMaskOperator   = 0xf0
140
+	// opClsJump
141
+	opMaskJumpConst = 0x0f
142
+	opMaskJumpCond  = 0xf0
143
+)
144
+
145
+const (
146
+	// +---------------+-----------------+---+---+---+
147
+	// | AddrMode (3b) | LoadWidth (2b)  | 0 | 0 | 0 |
148
+	// +---------------+-----------------+---+---+---+
149
+	opClsLoadA uint16 = iota
150
+	// +---------------+-----------------+---+---+---+
151
+	// | AddrMode (3b) | LoadWidth (2b)  | 0 | 0 | 1 |
152
+	// +---------------+-----------------+---+---+---+
153
+	opClsLoadX
154
+	// +---+---+---+---+---+---+---+---+
155
+	// | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
156
+	// +---+---+---+---+---+---+---+---+
157
+	opClsStoreA
158
+	// +---+---+---+---+---+---+---+---+
159
+	// | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 |
160
+	// +---+---+---+---+---+---+---+---+
161
+	opClsStoreX
162
+	// +---------------+-----------------+---+---+---+
163
+	// | Operator (4b) | OperandSrc (1b) | 1 | 0 | 0 |
164
+	// +---------------+-----------------+---+---+---+
165
+	opClsALU
166
+	// +-----------------------------+---+---+---+---+
167
+	// |      TestOperator (4b)      | 0 | 1 | 0 | 1 |
168
+	// +-----------------------------+---+---+---+---+
169
+	opClsJump
170
+	// +---+-------------------------+---+---+---+---+
171
+	// | 0 | 0 | 0 |   RetSrc (1b)   | 0 | 1 | 1 | 0 |
172
+	// +---+-------------------------+---+---+---+---+
173
+	opClsReturn
174
+	// +---+-------------------------+---+---+---+---+
175
+	// | 0 | 0 | 0 |  TXAorTAX (1b)  | 0 | 1 | 1 | 1 |
176
+	// +---+-------------------------+---+---+---+---+
177
+	opClsMisc
178
+)
179
+
180
+const (
181
+	opAddrModeImmediate uint16 = iota << 5
182
+	opAddrModeAbsolute
183
+	opAddrModeIndirect
184
+	opAddrModeScratch
185
+	opAddrModePacketLen // actually an extension, not an addressing mode.
186
+	opAddrModeMemShift
187
+)
188
+
189
+const (
190
+	opLoadWidth4 uint16 = iota << 3
191
+	opLoadWidth2
192
+	opLoadWidth1
193
+)
194
+
195
+// Operator defined by ALUOp*
196
+
197
+const (
198
+	opALUSrcConstant uint16 = iota << 3
199
+	opALUSrcX
200
+)
201
+
202
+const (
203
+	opJumpAlways = iota << 4
204
+	opJumpEqual
205
+	opJumpGT
206
+	opJumpGE
207
+	opJumpSet
208
+)
209
+
210
+const (
211
+	opRetSrcConstant uint16 = iota << 4
212
+	opRetSrcA
213
+)
214
+
215
+const (
216
+	opMiscTAX = 0x00
217
+	opMiscTXA = 0x80
218
+)

+ 82
- 0
vendor/golang.org/x/net/bpf/doc.go View File

@@ -0,0 +1,82 @@
1
+// Copyright 2016 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+/*
6
+
7
+Package bpf implements marshaling and unmarshaling of programs for the
8
+Berkeley Packet Filter virtual machine, and provides a Go implementation
9
+of the virtual machine.
10
+
11
+BPF's main use is to specify a packet filter for network taps, so that
12
+the kernel doesn't have to expensively copy every packet it sees to
13
+userspace. However, it's been repurposed to other areas where running
14
+user code in-kernel is needed. For example, Linux's seccomp uses BPF
15
+to apply security policies to system calls. For simplicity, this
16
+documentation refers only to packets, but other uses of BPF have their
17
+own data payloads.
18
+
19
+BPF programs run in a restricted virtual machine. It has almost no
20
+access to kernel functions, and while conditional branches are
21
+allowed, they can only jump forwards, to guarantee that there are no
22
+infinite loops.
23
+
24
+The virtual machine
25
+
26
+The BPF VM is an accumulator machine. Its main register, called
27
+register A, is an implicit source and destination in all arithmetic
28
+and logic operations. The machine also has 16 scratch registers for
29
+temporary storage, and an indirection register (register X) for
30
+indirect memory access. All registers are 32 bits wide.
31
+
32
+Each run of a BPF program is given one packet, which is placed in the
33
+VM's read-only "main memory". LoadAbsolute and LoadIndirect
34
+instructions can fetch up to 32 bits at a time into register A for
35
+examination.
36
+
37
+The goal of a BPF program is to produce and return a verdict (uint32),
38
+which tells the kernel what to do with the packet. In the context of
39
+packet filtering, the returned value is the number of bytes of the
40
+packet to forward to userspace, or 0 to ignore the packet. Other
41
+contexts like seccomp define their own return values.
42
+
43
+In order to simplify programs, attempts to read past the end of the
44
+packet terminate the program execution with a verdict of 0 (ignore
45
+packet). This means that the vast majority of BPF programs don't need
46
+to do any explicit bounds checking.
47
+
48
+In addition to the bytes of the packet, some BPF programs have access
49
+to extensions, which are essentially calls to kernel utility
50
+functions. Currently, the only extensions supported by this package
51
+are the Linux packet filter extensions.
52
+
53
+Examples
54
+
55
+This packet filter selects all ARP packets.
56
+
57
+	bpf.Assemble([]bpf.Instruction{
58
+		// Load "EtherType" field from the ethernet header.
59
+		bpf.LoadAbsolute{Off: 12, Size: 2},
60
+		// Skip over the next instruction if EtherType is not ARP.
61
+		bpf.JumpIf{Cond: bpf.JumpNotEqual, Val: 0x0806, SkipTrue: 1},
62
+		// Verdict is "send up to 4k of the packet to userspace."
63
+		bpf.RetConstant{Val: 4096},
64
+		// Verdict is "ignore packet."
65
+		bpf.RetConstant{Val: 0},
66
+	})
67
+
68
+This packet filter captures a random 1% sample of traffic.
69
+
70
+	bpf.Assemble([]bpf.Instruction{
71
+		// Get a 32-bit random number from the Linux kernel.
72
+		bpf.LoadExtension{Num: bpf.ExtRand},
73
+		// 1% dice roll?
74
+		bpf.JumpIf{Cond: bpf.JumpLessThan, Val: 2^32/100, SkipFalse: 1},
75
+		// Capture.
76
+		bpf.RetConstant{Val: 4096},
77
+		// Ignore.
78
+		bpf.RetConstant{Val: 0},
79
+	})
80
+
81
+*/
82
+package bpf // import "golang.org/x/net/bpf"

+ 704
- 0
vendor/golang.org/x/net/bpf/instructions.go View File

@@ -0,0 +1,704 @@
1
+// Copyright 2016 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package bpf
6
+
7
+import "fmt"
8
+
9
+// An Instruction is one instruction executed by the BPF virtual
10
+// machine.
11
+type Instruction interface {
12
+	// Assemble assembles the Instruction into a RawInstruction.
13
+	Assemble() (RawInstruction, error)
14
+}
15
+
16
+// A RawInstruction is a raw BPF virtual machine instruction.
17
+type RawInstruction struct {
18
+	// Operation to execute.
19
+	Op uint16
20
+	// For conditional jump instructions, the number of instructions
21
+	// to skip if the condition is true/false.
22
+	Jt uint8
23
+	Jf uint8
24
+	// Constant parameter. The meaning depends on the Op.
25
+	K uint32
26
+}
27
+
28
+// Assemble implements the Instruction Assemble method.
29
+func (ri RawInstruction) Assemble() (RawInstruction, error) { return ri, nil }
30
+
31
+// Disassemble parses ri into an Instruction and returns it. If ri is
32
+// not recognized by this package, ri itself is returned.
33
+func (ri RawInstruction) Disassemble() Instruction {
34
+	switch ri.Op & opMaskCls {
35
+	case opClsLoadA, opClsLoadX:
36
+		reg := Register(ri.Op & opMaskLoadDest)
37
+		sz := 0
38
+		switch ri.Op & opMaskLoadWidth {
39
+		case opLoadWidth4:
40
+			sz = 4
41
+		case opLoadWidth2:
42
+			sz = 2
43
+		case opLoadWidth1:
44
+			sz = 1
45
+		default:
46
+			return ri
47
+		}
48
+		switch ri.Op & opMaskLoadMode {
49
+		case opAddrModeImmediate:
50
+			if sz != 4 {
51
+				return ri
52
+			}
53
+			return LoadConstant{Dst: reg, Val: ri.K}
54
+		case opAddrModeScratch:
55
+			if sz != 4 || ri.K > 15 {
56
+				return ri
57
+			}
58
+			return LoadScratch{Dst: reg, N: int(ri.K)}
59
+		case opAddrModeAbsolute:
60
+			if ri.K > extOffset+0xffffffff {
61
+				return LoadExtension{Num: Extension(-extOffset + ri.K)}
62
+			}
63
+			return LoadAbsolute{Size: sz, Off: ri.K}
64
+		case opAddrModeIndirect:
65
+			return LoadIndirect{Size: sz, Off: ri.K}
66
+		case opAddrModePacketLen:
67
+			if sz != 4 {
68
+				return ri
69
+			}
70
+			return LoadExtension{Num: ExtLen}
71
+		case opAddrModeMemShift:
72
+			return LoadMemShift{Off: ri.K}
73
+		default:
74
+			return ri
75
+		}
76
+
77
+	case opClsStoreA:
78
+		if ri.Op != opClsStoreA || ri.K > 15 {
79
+			return ri
80
+		}
81
+		return StoreScratch{Src: RegA, N: int(ri.K)}
82
+
83
+	case opClsStoreX:
84
+		if ri.Op != opClsStoreX || ri.K > 15 {
85
+			return ri
86
+		}
87
+		return StoreScratch{Src: RegX, N: int(ri.K)}
88
+
89
+	case opClsALU:
90
+		switch op := ALUOp(ri.Op & opMaskOperator); op {
91
+		case ALUOpAdd, ALUOpSub, ALUOpMul, ALUOpDiv, ALUOpOr, ALUOpAnd, ALUOpShiftLeft, ALUOpShiftRight, ALUOpMod, ALUOpXor:
92
+			if ri.Op&opMaskOperandSrc != 0 {
93
+				return ALUOpX{Op: op}
94
+			}
95
+			return ALUOpConstant{Op: op, Val: ri.K}
96
+		case aluOpNeg:
97
+			return NegateA{}
98
+		default:
99
+			return ri
100
+		}
101
+
102
+	case opClsJump:
103
+		if ri.Op&opMaskJumpConst != opClsJump {
104
+			return ri
105
+		}
106
+		switch ri.Op & opMaskJumpCond {
107
+		case opJumpAlways:
108
+			return Jump{Skip: ri.K}
109
+		case opJumpEqual:
110
+			if ri.Jt == 0 {
111
+				return JumpIf{
112
+					Cond:      JumpNotEqual,
113
+					Val:       ri.K,
114
+					SkipTrue:  ri.Jf,
115
+					SkipFalse: 0,
116
+				}
117
+			}
118
+			return JumpIf{
119
+				Cond:      JumpEqual,
120
+				Val:       ri.K,
121
+				SkipTrue:  ri.Jt,
122
+				SkipFalse: ri.Jf,
123
+			}
124
+		case opJumpGT:
125
+			if ri.Jt == 0 {
126
+				return JumpIf{
127
+					Cond:      JumpLessOrEqual,
128
+					Val:       ri.K,
129
+					SkipTrue:  ri.Jf,
130
+					SkipFalse: 0,
131
+				}
132
+			}
133
+			return JumpIf{
134
+				Cond:      JumpGreaterThan,
135
+				Val:       ri.K,
136
+				SkipTrue:  ri.Jt,
137
+				SkipFalse: ri.Jf,
138
+			}
139
+		case opJumpGE:
140
+			if ri.Jt == 0 {
141
+				return JumpIf{
142
+					Cond:      JumpLessThan,
143
+					Val:       ri.K,
144
+					SkipTrue:  ri.Jf,
145
+					SkipFalse: 0,
146
+				}
147
+			}
148
+			return JumpIf{
149
+				Cond:      JumpGreaterOrEqual,
150
+				Val:       ri.K,
151
+				SkipTrue:  ri.Jt,
152
+				SkipFalse: ri.Jf,
153
+			}
154
+		case opJumpSet:
155
+			return JumpIf{
156
+				Cond:      JumpBitsSet,
157
+				Val:       ri.K,
158
+				SkipTrue:  ri.Jt,
159
+				SkipFalse: ri.Jf,
160
+			}
161
+		default:
162
+			return ri
163
+		}
164
+
165
+	case opClsReturn:
166
+		switch ri.Op {
167
+		case opClsReturn | opRetSrcA:
168
+			return RetA{}
169
+		case opClsReturn | opRetSrcConstant:
170
+			return RetConstant{Val: ri.K}
171
+		default:
172
+			return ri
173
+		}
174
+
175
+	case opClsMisc:
176
+		switch ri.Op {
177
+		case opClsMisc | opMiscTAX:
178
+			return TAX{}
179
+		case opClsMisc | opMiscTXA:
180
+			return TXA{}
181
+		default:
182
+			return ri
183
+		}
184
+
185
+	default:
186
+		panic("unreachable") // switch is exhaustive on the bit pattern
187
+	}
188
+}
189
+
190
+// LoadConstant loads Val into register Dst.
191
+type LoadConstant struct {
192
+	Dst Register
193
+	Val uint32
194
+}
195
+
196
+// Assemble implements the Instruction Assemble method.
197
+func (a LoadConstant) Assemble() (RawInstruction, error) {
198
+	return assembleLoad(a.Dst, 4, opAddrModeImmediate, a.Val)
199
+}
200
+
201
+// String returns the the instruction in assembler notation.
202
+func (a LoadConstant) String() string {
203
+	switch a.Dst {
204
+	case RegA:
205
+		return fmt.Sprintf("ld #%d", a.Val)
206
+	case RegX:
207
+		return fmt.Sprintf("ldx #%d", a.Val)
208
+	default:
209
+		return fmt.Sprintf("unknown instruction: %#v", a)
210
+	}
211
+}
212
+
213
+// LoadScratch loads scratch[N] into register Dst.
214
+type LoadScratch struct {
215
+	Dst Register
216
+	N   int // 0-15
217
+}
218
+
219
+// Assemble implements the Instruction Assemble method.
220
+func (a LoadScratch) Assemble() (RawInstruction, error) {
221
+	if a.N < 0 || a.N > 15 {
222
+		return RawInstruction{}, fmt.Errorf("invalid scratch slot %d", a.N)
223
+	}
224
+	return assembleLoad(a.Dst, 4, opAddrModeScratch, uint32(a.N))
225
+}
226
+
227
+// String returns the the instruction in assembler notation.
228
+func (a LoadScratch) String() string {
229
+	switch a.Dst {
230
+	case RegA:
231
+		return fmt.Sprintf("ld M[%d]", a.N)
232
+	case RegX:
233
+		return fmt.Sprintf("ldx M[%d]", a.N)
234
+	default:
235
+		return fmt.Sprintf("unknown instruction: %#v", a)
236
+	}
237
+}
238
+
239
+// LoadAbsolute loads packet[Off:Off+Size] as an integer value into
240
+// register A.
241
+type LoadAbsolute struct {
242
+	Off  uint32
243
+	Size int // 1, 2 or 4
244
+}
245
+
246
+// Assemble implements the Instruction Assemble method.
247
+func (a LoadAbsolute) Assemble() (RawInstruction, error) {
248
+	return assembleLoad(RegA, a.Size, opAddrModeAbsolute, a.Off)
249
+}
250
+
251
+// String returns the the instruction in assembler notation.
252
+func (a LoadAbsolute) String() string {
253
+	switch a.Size {
254
+	case 1: // byte
255
+		return fmt.Sprintf("ldb [%d]", a.Off)
256
+	case 2: // half word
257
+		return fmt.Sprintf("ldh [%d]", a.Off)
258
+	case 4: // word
259
+		if a.Off > extOffset+0xffffffff {
260
+			return LoadExtension{Num: Extension(a.Off + 0x1000)}.String()
261
+		}
262
+		return fmt.Sprintf("ld [%d]", a.Off)
263
+	default:
264
+		return fmt.Sprintf("unknown instruction: %#v", a)
265
+	}
266
+}
267
+
268
+// LoadIndirect loads packet[X+Off:X+Off+Size] as an integer value
269
+// into register A.
270
+type LoadIndirect struct {
271
+	Off  uint32
272
+	Size int // 1, 2 or 4
273
+}
274
+
275
+// Assemble implements the Instruction Assemble method.
276
+func (a LoadIndirect) Assemble() (RawInstruction, error) {
277
+	return assembleLoad(RegA, a.Size, opAddrModeIndirect, a.Off)
278
+}
279
+
280
+// String returns the the instruction in assembler notation.
281
+func (a LoadIndirect) String() string {
282
+	switch a.Size {
283
+	case 1: // byte
284
+		return fmt.Sprintf("ldb [x + %d]", a.Off)
285
+	case 2: // half word
286
+		return fmt.Sprintf("ldh [x + %d]", a.Off)
287
+	case 4: // word
288
+		return fmt.Sprintf("ld [x + %d]", a.Off)
289
+	default:
290
+		return fmt.Sprintf("unknown instruction: %#v", a)
291
+	}
292
+}
293
+
294
+// LoadMemShift multiplies the first 4 bits of the byte at packet[Off]
295
+// by 4 and stores the result in register X.
296
+//
297
+// This instruction is mainly useful to load into X the length of an
298
+// IPv4 packet header in a single instruction, rather than have to do
299
+// the arithmetic on the header's first byte by hand.
300
+type LoadMemShift struct {
301
+	Off uint32
302
+}
303
+
304
+// Assemble implements the Instruction Assemble method.
305
+func (a LoadMemShift) Assemble() (RawInstruction, error) {
306
+	return assembleLoad(RegX, 1, opAddrModeMemShift, a.Off)
307
+}
308
+
309
+// String returns the the instruction in assembler notation.
310
+func (a LoadMemShift) String() string {
311
+	return fmt.Sprintf("ldx 4*([%d]&0xf)", a.Off)
312
+}
313
+
314
+// LoadExtension invokes a linux-specific extension and stores the
315
+// result in register A.
316
+type LoadExtension struct {
317
+	Num Extension
318
+}
319
+
320
+// Assemble implements the Instruction Assemble method.
321
+func (a LoadExtension) Assemble() (RawInstruction, error) {
322
+	if a.Num == ExtLen {
323
+		return assembleLoad(RegA, 4, opAddrModePacketLen, 0)
324
+	}
325
+	return assembleLoad(RegA, 4, opAddrModeAbsolute, uint32(extOffset+a.Num))
326
+}
327
+
328
+// String returns the the instruction in assembler notation.
329
+func (a LoadExtension) String() string {
330
+	switch a.Num {
331
+	case ExtLen:
332
+		return "ld #len"
333
+	case ExtProto:
334
+		return "ld #proto"
335
+	case ExtType:
336
+		return "ld #type"
337
+	case ExtPayloadOffset:
338
+		return "ld #poff"
339
+	case ExtInterfaceIndex:
340
+		return "ld #ifidx"
341
+	case ExtNetlinkAttr:
342
+		return "ld #nla"
343
+	case ExtNetlinkAttrNested:
344
+		return "ld #nlan"
345
+	case ExtMark:
346
+		return "ld #mark"
347
+	case ExtQueue:
348
+		return "ld #queue"
349
+	case ExtLinkLayerType:
350
+		return "ld #hatype"
351
+	case ExtRXHash:
352
+		return "ld #rxhash"
353
+	case ExtCPUID:
354
+		return "ld #cpu"
355
+	case ExtVLANTag:
356
+		return "ld #vlan_tci"
357
+	case ExtVLANTagPresent:
358
+		return "ld #vlan_avail"
359
+	case ExtVLANProto:
360
+		return "ld #vlan_tpid"
361
+	case ExtRand:
362
+		return "ld #rand"
363
+	default:
364
+		return fmt.Sprintf("unknown instruction: %#v", a)
365
+	}
366
+}
367
+
368
+// StoreScratch stores register Src into scratch[N].
369
+type StoreScratch struct {
370
+	Src Register
371
+	N   int // 0-15
372
+}
373
+
374
+// Assemble implements the Instruction Assemble method.
375
+func (a StoreScratch) Assemble() (RawInstruction, error) {
376
+	if a.N < 0 || a.N > 15 {
377
+		return RawInstruction{}, fmt.Errorf("invalid scratch slot %d", a.N)
378
+	}
379
+	var op uint16
380
+	switch a.Src {
381
+	case RegA:
382
+		op = opClsStoreA
383
+	case RegX:
384
+		op = opClsStoreX
385
+	default:
386
+		return RawInstruction{}, fmt.Errorf("invalid source register %v", a.Src)
387
+	}
388
+
389
+	return RawInstruction{
390
+		Op: op,
391
+		K:  uint32(a.N),
392
+	}, nil
393
+}
394
+
395
+// String returns the the instruction in assembler notation.
396
+func (a StoreScratch) String() string {
397
+	switch a.Src {
398
+	case RegA:
399
+		return fmt.Sprintf("st M[%d]", a.N)
400
+	case RegX:
401
+		return fmt.Sprintf("stx M[%d]", a.N)
402
+	default:
403
+		return fmt.Sprintf("unknown instruction: %#v", a)
404
+	}
405
+}
406
+
407
+// ALUOpConstant executes A = A <Op> Val.
408
+type ALUOpConstant struct {
409
+	Op  ALUOp
410
+	Val uint32
411
+}
412
+
413
+// Assemble implements the Instruction Assemble method.
414
+func (a ALUOpConstant) Assemble() (RawInstruction, error) {
415
+	return RawInstruction{
416
+		Op: opClsALU | opALUSrcConstant | uint16(a.Op),
417
+		K:  a.Val,
418
+	}, nil
419
+}
420
+
421
+// String returns the the instruction in assembler notation.
422
+func (a ALUOpConstant) String() string {
423
+	switch a.Op {
424
+	case ALUOpAdd:
425
+		return fmt.Sprintf("add #%d", a.Val)
426
+	case ALUOpSub:
427
+		return fmt.Sprintf("sub #%d", a.Val)
428
+	case ALUOpMul:
429
+		return fmt.Sprintf("mul #%d", a.Val)
430
+	case ALUOpDiv:
431
+		return fmt.Sprintf("div #%d", a.Val)
432
+	case ALUOpMod:
433
+		return fmt.Sprintf("mod #%d", a.Val)
434
+	case ALUOpAnd:
435
+		return fmt.Sprintf("and #%d", a.Val)
436
+	case ALUOpOr:
437
+		return fmt.Sprintf("or #%d", a.Val)
438
+	case ALUOpXor:
439
+		return fmt.Sprintf("xor #%d", a.Val)
440
+	case ALUOpShiftLeft:
441
+		return fmt.Sprintf("lsh #%d", a.Val)
442
+	case ALUOpShiftRight:
443
+		return fmt.Sprintf("rsh #%d", a.Val)
444
+	default:
445
+		return fmt.Sprintf("unknown instruction: %#v", a)
446
+	}
447
+}
448
+
449
+// ALUOpX executes A = A <Op> X
450
+type ALUOpX struct {
451
+	Op ALUOp
452
+}
453
+
454
+// Assemble implements the Instruction Assemble method.
455
+func (a ALUOpX) Assemble() (RawInstruction, error) {
456
+	return RawInstruction{
457
+		Op: opClsALU | opALUSrcX | uint16(a.Op),
458
+	}, nil
459
+}
460
+
461
+// String returns the the instruction in assembler notation.
462
+func (a ALUOpX) String() string {
463
+	switch a.Op {
464
+	case ALUOpAdd:
465
+		return "add x"
466
+	case ALUOpSub:
467
+		return "sub x"
468
+	case ALUOpMul:
469
+		return "mul x"
470
+	case ALUOpDiv:
471
+		return "div x"
472
+	case ALUOpMod:
473
+		return "mod x"
474
+	case ALUOpAnd:
475
+		return "and x"
476
+	case ALUOpOr:
477
+		return "or x"
478
+	case ALUOpXor:
479
+		return "xor x"
480
+	case ALUOpShiftLeft:
481
+		return "lsh x"
482
+	case ALUOpShiftRight:
483
+		return "rsh x"
484
+	default:
485
+		return fmt.Sprintf("unknown instruction: %#v", a)
486
+	}
487
+}
488
+
489
+// NegateA executes A = -A.
490
+type NegateA struct{}
491
+
492
+// Assemble implements the Instruction Assemble method.
493
+func (a NegateA) Assemble() (RawInstruction, error) {
494
+	return RawInstruction{
495
+		Op: opClsALU | uint16(aluOpNeg),
496
+	}, nil
497
+}
498
+
499
+// String returns the the instruction in assembler notation.
500
+func (a NegateA) String() string {
501
+	return fmt.Sprintf("neg")
502
+}
503
+
504
+// Jump skips the following Skip instructions in the program.
505
+type Jump struct {
506
+	Skip uint32
507
+}
508
+
509
+// Assemble implements the Instruction Assemble method.
510
+func (a Jump) Assemble() (RawInstruction, error) {
511
+	return RawInstruction{
512
+		Op: opClsJump | opJumpAlways,
513
+		K:  a.Skip,
514
+	}, nil
515
+}
516
+
517
+// String returns the the instruction in assembler notation.
518
+func (a Jump) String() string {
519
+	return fmt.Sprintf("ja %d", a.Skip)
520
+}
521
+
522
+// JumpIf skips the following Skip instructions in the program if A
523
+// <Cond> Val is true.
524
+type JumpIf struct {
525
+	Cond      JumpTest
526
+	Val       uint32
527
+	SkipTrue  uint8
528
+	SkipFalse uint8
529
+}
530
+
531
+// Assemble implements the Instruction Assemble method.
532
+func (a JumpIf) Assemble() (RawInstruction, error) {
533
+	var (
534
+		cond uint16
535
+		flip bool
536
+	)
537
+	switch a.Cond {
538
+	case JumpEqual:
539
+		cond = opJumpEqual
540
+	case JumpNotEqual:
541
+		cond, flip = opJumpEqual, true
542
+	case JumpGreaterThan:
543
+		cond = opJumpGT
544
+	case JumpLessThan:
545
+		cond, flip = opJumpGE, true
546
+	case JumpGreaterOrEqual:
547
+		cond = opJumpGE
548
+	case JumpLessOrEqual:
549
+		cond, flip = opJumpGT, true
550
+	case JumpBitsSet:
551
+		cond = opJumpSet
552
+	case JumpBitsNotSet:
553
+		cond, flip = opJumpSet, true
554
+	default:
555
+		return RawInstruction{}, fmt.Errorf("unknown JumpTest %v", a.Cond)
556
+	}
557
+	jt, jf := a.SkipTrue, a.SkipFalse
558
+	if flip {
559
+		jt, jf = jf, jt
560
+	}
561
+	return RawInstruction{
562
+		Op: opClsJump | cond,
563
+		Jt: jt,
564
+		Jf: jf,
565
+		K:  a.Val,
566
+	}, nil
567
+}
568
+
569
+// String returns the the instruction in assembler notation.
570
+func (a JumpIf) String() string {
571
+	switch a.Cond {
572
+	// K == A
573
+	case JumpEqual:
574
+		return conditionalJump(a, "jeq", "jneq")
575
+	// K != A
576
+	case JumpNotEqual:
577
+		return fmt.Sprintf("jneq #%d,%d", a.Val, a.SkipTrue)
578
+	// K > A
579
+	case JumpGreaterThan:
580
+		return conditionalJump(a, "jgt", "jle")
581
+	// K < A
582
+	case JumpLessThan:
583
+		return fmt.Sprintf("jlt #%d,%d", a.Val, a.SkipTrue)
584
+	// K >= A
585
+	case JumpGreaterOrEqual:
586
+		return conditionalJump(a, "jge", "jlt")
587
+	// K <= A
588
+	case JumpLessOrEqual:
589
+		return fmt.Sprintf("jle #%d,%d", a.Val, a.SkipTrue)
590
+	// K & A != 0
591
+	case JumpBitsSet:
592
+		if a.SkipFalse > 0 {
593
+			return fmt.Sprintf("jset #%d,%d,%d", a.Val, a.SkipTrue, a.SkipFalse)
594
+		}
595
+		return fmt.Sprintf("jset #%d,%d", a.Val, a.SkipTrue)
596
+	// K & A == 0, there is no assembler instruction for JumpBitNotSet, use JumpBitSet and invert skips
597
+	case JumpBitsNotSet:
598
+		return JumpIf{Cond: JumpBitsSet, SkipTrue: a.SkipFalse, SkipFalse: a.SkipTrue, Val: a.Val}.String()
599
+	default:
600
+		return fmt.Sprintf("unknown instruction: %#v", a)
601
+	}
602
+}
603
+
604
+func conditionalJump(inst JumpIf, positiveJump, negativeJump string) string {
605
+	if inst.SkipTrue > 0 {
606
+		if inst.SkipFalse > 0 {
607
+			return fmt.Sprintf("%s #%d,%d,%d", positiveJump, inst.Val, inst.SkipTrue, inst.SkipFalse)
608
+		}
609
+		return fmt.Sprintf("%s #%d,%d", positiveJump, inst.Val, inst.SkipTrue)
610
+	}
611
+	return fmt.Sprintf("%s #%d,%d", negativeJump, inst.Val, inst.SkipFalse)
612
+}
613
+
614
+// RetA exits the BPF program, returning the value of register A.
615
+type RetA struct{}
616
+
617
+// Assemble implements the Instruction Assemble method.
618
+func (a RetA) Assemble() (RawInstruction, error) {
619
+	return RawInstruction{
620
+		Op: opClsReturn | opRetSrcA,
621
+	}, nil
622
+}
623
+
624
+// String returns the the instruction in assembler notation.
625
+func (a RetA) String() string {
626
+	return fmt.Sprintf("ret a")
627
+}
628
+
629
+// RetConstant exits the BPF program, returning a constant value.
630
+type RetConstant struct {
631
+	Val uint32
632
+}
633
+
634
+// Assemble implements the Instruction Assemble method.
635
+func (a RetConstant) Assemble() (RawInstruction, error) {
636
+	return RawInstruction{
637
+		Op: opClsReturn | opRetSrcConstant,
638
+		K:  a.Val,
639
+	}, nil
640
+}
641
+
642
+// String returns the the instruction in assembler notation.
643
+func (a RetConstant) String() string {
644
+	return fmt.Sprintf("ret #%d", a.Val)
645
+}
646
+
647
+// TXA copies the value of register X to register A.
648
+type TXA struct{}
649
+
650
+// Assemble implements the Instruction Assemble method.
651
+func (a TXA) Assemble() (RawInstruction, error) {
652
+	return RawInstruction{
653
+		Op: opClsMisc | opMiscTXA,
654
+	}, nil
655
+}
656
+
657
+// String returns the the instruction in assembler notation.
658
+func (a TXA) String() string {
659
+	return fmt.Sprintf("txa")
660
+}
661
+
662
+// TAX copies the value of register A to register X.
663
+type TAX struct{}
664
+
665
+// Assemble implements the Instruction Assemble method.
666
+func (a TAX) Assemble() (RawInstruction, error) {
667
+	return RawInstruction{
668
+		Op: opClsMisc | opMiscTAX,
669
+	}, nil
670
+}
671
+
672
+// String returns the the instruction in assembler notation.
673
+func (a TAX) String() string {
674
+	return fmt.Sprintf("tax")
675
+}
676
+
677
+func assembleLoad(dst Register, loadSize int, mode uint16, k uint32) (RawInstruction, error) {
678
+	var (
679
+		cls uint16
680
+		sz  uint16
681
+	)
682
+	switch dst {
683
+	case RegA:
684
+		cls = opClsLoadA
685
+	case RegX:
686
+		cls = opClsLoadX
687
+	default:
688
+		return RawInstruction{}, fmt.Errorf("invalid target register %v", dst)
689
+	}
690
+	switch loadSize {
691
+	case 1:
692
+		sz = opLoadWidth1
693
+	case 2:
694
+		sz = opLoadWidth2
695
+	case 4:
696
+		sz = opLoadWidth4
697
+	default:
698
+		return RawInstruction{}, fmt.Errorf("invalid load byte length %d", sz)
699
+	}
700
+	return RawInstruction{
701
+		Op: cls | sz | mode,
702
+		K:  k,
703
+	}, nil
704
+}

+ 525
- 0
vendor/golang.org/x/net/bpf/instructions_test.go View File

@@ -0,0 +1,525 @@
1
+// Copyright 2016 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package bpf
6
+
7
+import (
8
+	"fmt"
9
+	"io/ioutil"
10
+	"reflect"
11
+	"strconv"
12
+	"strings"
13
+	"testing"
14
+)
15
+
16
+// This is a direct translation of the program in
17
+// testdata/all_instructions.txt.
18
+var allInstructions = []Instruction{
19
+	LoadConstant{Dst: RegA, Val: 42},
20
+	LoadConstant{Dst: RegX, Val: 42},
21
+
22
+	LoadScratch{Dst: RegA, N: 3},
23
+	LoadScratch{Dst: RegX, N: 3},
24
+
25
+	LoadAbsolute{Off: 42, Size: 1},
26
+	LoadAbsolute{Off: 42, Size: 2},
27
+	LoadAbsolute{Off: 42, Size: 4},
28
+
29
+	LoadIndirect{Off: 42, Size: 1},
30
+	LoadIndirect{Off: 42, Size: 2},
31
+	LoadIndirect{Off: 42, Size: 4},
32
+
33
+	LoadMemShift{Off: 42},
34
+
35
+	LoadExtension{Num: ExtLen},
36
+	LoadExtension{Num: ExtProto},
37
+	LoadExtension{Num: ExtType},
38
+	LoadExtension{Num: ExtRand},
39
+
40
+	StoreScratch{Src: RegA, N: 3},
41
+	StoreScratch{Src: RegX, N: 3},
42
+
43
+	ALUOpConstant{Op: ALUOpAdd, Val: 42},
44
+	ALUOpConstant{Op: ALUOpSub, Val: 42},
45
+	ALUOpConstant{Op: ALUOpMul, Val: 42},
46
+	ALUOpConstant{Op: ALUOpDiv, Val: 42},
47
+	ALUOpConstant{Op: ALUOpOr, Val: 42},
48
+	ALUOpConstant{Op: ALUOpAnd, Val: 42},
49
+	ALUOpConstant{Op: ALUOpShiftLeft, Val: 42},
50
+	ALUOpConstant{Op: ALUOpShiftRight, Val: 42},
51
+	ALUOpConstant{Op: ALUOpMod, Val: 42},
52
+	ALUOpConstant{Op: ALUOpXor, Val: 42},
53
+
54
+	ALUOpX{Op: ALUOpAdd},
55
+	ALUOpX{Op: ALUOpSub},
56
+	ALUOpX{Op: ALUOpMul},
57
+	ALUOpX{Op: ALUOpDiv},
58
+	ALUOpX{Op: ALUOpOr},
59
+	ALUOpX{Op: ALUOpAnd},
60
+	ALUOpX{Op: ALUOpShiftLeft},
61
+	ALUOpX{Op: ALUOpShiftRight},
62
+	ALUOpX{Op: ALUOpMod},
63
+	ALUOpX{Op: ALUOpXor},
64
+
65
+	NegateA{},
66
+
67
+	Jump{Skip: 10},
68
+	JumpIf{Cond: JumpEqual, Val: 42, SkipTrue: 8, SkipFalse: 9},
69
+	JumpIf{Cond: JumpNotEqual, Val: 42, SkipTrue: 8},
70
+	JumpIf{Cond: JumpLessThan, Val: 42, SkipTrue: 7},
71
+	JumpIf{Cond: JumpLessOrEqual, Val: 42, SkipTrue: 6},
72
+	JumpIf{Cond: JumpGreaterThan, Val: 42, SkipTrue: 4, SkipFalse: 5},
73
+	JumpIf{Cond: JumpGreaterOrEqual, Val: 42, SkipTrue: 3, SkipFalse: 4},
74
+	JumpIf{Cond: JumpBitsSet, Val: 42, SkipTrue: 2, SkipFalse: 3},
75
+
76
+	TAX{},
77
+	TXA{},
78
+
79
+	RetA{},
80
+	RetConstant{Val: 42},
81
+}
82
+var allInstructionsExpected = "testdata/all_instructions.bpf"
83
+
84
+// Check that we produce the same output as the canonical bpf_asm
85
+// linux kernel tool.
86
+func TestInterop(t *testing.T) {
87
+	out, err := Assemble(allInstructions)
88
+	if err != nil {
89
+		t.Fatalf("assembly of allInstructions program failed: %s", err)
90
+	}
91
+	t.Logf("Assembled program is %d instructions long", len(out))
92
+
93
+	bs, err := ioutil.ReadFile(allInstructionsExpected)
94
+	if err != nil {
95
+		t.Fatalf("reading %s: %s", allInstructionsExpected, err)
96
+	}
97
+	// First statement is the number of statements, last statement is
98
+	// empty. We just ignore both and rely on slice length.
99
+	stmts := strings.Split(string(bs), ",")
100
+	if len(stmts)-2 != len(out) {
101
+		t.Fatalf("test program lengths don't match: %s has %d, Go implementation has %d", allInstructionsExpected, len(stmts)-2, len(allInstructions))
102
+	}
103
+
104
+	for i, stmt := range stmts[1 : len(stmts)-2] {
105
+		nums := strings.Split(stmt, " ")
106
+		if len(nums) != 4 {
107
+			t.Fatalf("malformed instruction %d in %s: %s", i+1, allInstructionsExpected, stmt)
108
+		}
109
+
110
+		actual := out[i]
111
+
112
+		op, err := strconv.ParseUint(nums[0], 10, 16)
113
+		if err != nil {
114
+			t.Fatalf("malformed opcode %s in instruction %d of %s", nums[0], i+1, allInstructionsExpected)
115
+		}
116
+		if actual.Op != uint16(op) {
117
+			t.Errorf("opcode mismatch on instruction %d (%#v): got 0x%02x, want 0x%02x", i+1, allInstructions[i], actual.Op, op)
118
+		}
119
+
120
+		jt, err := strconv.ParseUint(nums[1], 10, 8)
121
+		if err != nil {
122
+			t.Fatalf("malformed jt offset %s in instruction %d of %s", nums[1], i+1, allInstructionsExpected)
123
+		}
124
+		if actual.Jt != uint8(jt) {
125
+			t.Errorf("jt mismatch on instruction %d (%#v): got %d, want %d", i+1, allInstructions[i], actual.Jt, jt)
126
+		}
127
+
128
+		jf, err := strconv.ParseUint(nums[2], 10, 8)
129
+		if err != nil {
130
+			t.Fatalf("malformed jf offset %s in instruction %d of %s", nums[2], i+1, allInstructionsExpected)
131
+		}
132
+		if actual.Jf != uint8(jf) {
133
+			t.Errorf("jf mismatch on instruction %d (%#v): got %d, want %d", i+1, allInstructions[i], actual.Jf, jf)
134
+		}
135
+
136
+		k, err := strconv.ParseUint(nums[3], 10, 32)
137
+		if err != nil {
138
+			t.Fatalf("malformed constant %s in instruction %d of %s", nums[3], i+1, allInstructionsExpected)
139
+		}
140
+		if actual.K != uint32(k) {
141
+			t.Errorf("constant mismatch on instruction %d (%#v): got %d, want %d", i+1, allInstructions[i], actual.K, k)
142
+		}
143
+	}
144
+}
145
+
146
+// Check that assembly and disassembly match each other.
147
+func TestAsmDisasm(t *testing.T) {
148
+	prog1, err := Assemble(allInstructions)
149
+	if err != nil {
150
+		t.Fatalf("assembly of allInstructions program failed: %s", err)
151
+	}
152
+	t.Logf("Assembled program is %d instructions long", len(prog1))
153
+
154
+	got, allDecoded := Disassemble(prog1)
155
+	if !allDecoded {
156
+		t.Errorf("Disassemble(Assemble(allInstructions)) produced unrecognized instructions:")
157
+		for i, inst := range got {
158
+			if r, ok := inst.(RawInstruction); ok {
159
+				t.Logf("  insn %d, %#v --> %#v", i+1, allInstructions[i], r)
160
+			}
161
+		}
162
+	}
163
+
164
+	if len(allInstructions) != len(got) {
165
+		t.Fatalf("disassembly changed program size: %d insns before, %d insns after", len(allInstructions), len(got))
166
+	}
167
+	if !reflect.DeepEqual(allInstructions, got) {
168
+		t.Errorf("program mutated by disassembly:")
169
+		for i := range got {
170
+			if !reflect.DeepEqual(allInstructions[i], got[i]) {
171
+				t.Logf("  insn %d, s: %#v, p1: %#v, got: %#v", i+1, allInstructions[i], prog1[i], got[i])
172
+			}
173
+		}
174
+	}
175
+}
176
+
177
+type InvalidInstruction struct{}
178
+
179
+func (a InvalidInstruction) Assemble() (RawInstruction, error) {
180
+	return RawInstruction{}, fmt.Errorf("Invalid Instruction")
181
+}
182
+
183
+func (a InvalidInstruction) String() string {
184
+	return fmt.Sprintf("unknown instruction: %#v", a)
185
+}
186
+
187
+func TestString(t *testing.T) {
188
+	testCases := []struct {
189
+		instruction Instruction
190
+		assembler   string
191
+	}{
192
+		{
193
+			instruction: LoadConstant{Dst: RegA, Val: 42},
194
+			assembler:   "ld #42",
195
+		},
196
+		{
197
+			instruction: LoadConstant{Dst: RegX, Val: 42},
198
+			assembler:   "ldx #42",
199
+		},
200
+		{
201
+			instruction: LoadConstant{Dst: 0xffff, Val: 42},
202
+			assembler:   "unknown instruction: bpf.LoadConstant{Dst:0xffff, Val:0x2a}",
203
+		},
204
+		{
205
+			instruction: LoadScratch{Dst: RegA, N: 3},
206
+			assembler:   "ld M[3]",
207
+		},
208
+		{
209
+			instruction: LoadScratch{Dst: RegX, N: 3},
210
+			assembler:   "ldx M[3]",
211
+		},
212
+		{
213
+			instruction: LoadScratch{Dst: 0xffff, N: 3},
214
+			assembler:   "unknown instruction: bpf.LoadScratch{Dst:0xffff, N:3}",
215
+		},
216
+		{
217
+			instruction: LoadAbsolute{Off: 42, Size: 1},
218
+			assembler:   "ldb [42]",
219
+		},
220
+		{
221
+			instruction: LoadAbsolute{Off: 42, Size: 2},
222
+			assembler:   "ldh [42]",
223
+		},
224
+		{
225
+			instruction: LoadAbsolute{Off: 42, Size: 4},
226
+			assembler:   "ld [42]",
227
+		},
228
+		{
229
+			instruction: LoadAbsolute{Off: 42, Size: -1},
230
+			assembler:   "unknown instruction: bpf.LoadAbsolute{Off:0x2a, Size:-1}",
231
+		},
232
+		{
233
+			instruction: LoadIndirect{Off: 42, Size: 1},
234
+			assembler:   "ldb [x + 42]",
235
+		},
236
+		{
237
+			instruction: LoadIndirect{Off: 42, Size: 2},
238
+			assembler:   "ldh [x + 42]",
239
+		},
240
+		{
241
+			instruction: LoadIndirect{Off: 42, Size: 4},
242
+			assembler:   "ld [x + 42]",
243
+		},
244
+		{
245
+			instruction: LoadIndirect{Off: 42, Size: -1},
246
+			assembler:   "unknown instruction: bpf.LoadIndirect{Off:0x2a, Size:-1}",
247
+		},
248
+		{
249
+			instruction: LoadMemShift{Off: 42},
250
+			assembler:   "ldx 4*([42]&0xf)",
251
+		},
252
+		{
253
+			instruction: LoadExtension{Num: ExtLen},
254
+			assembler:   "ld #len",
255
+		},
256
+		{
257
+			instruction: LoadExtension{Num: ExtProto},
258
+			assembler:   "ld #proto",
259
+		},
260
+		{
261
+			instruction: LoadExtension{Num: ExtType},
262
+			assembler:   "ld #type",
263
+		},
264
+		{
265
+			instruction: LoadExtension{Num: ExtPayloadOffset},
266
+			assembler:   "ld #poff",
267
+		},
268
+		{
269
+			instruction: LoadExtension{Num: ExtInterfaceIndex},
270
+			assembler:   "ld #ifidx",
271
+		},
272
+		{
273
+			instruction: LoadExtension{Num: ExtNetlinkAttr},
274
+			assembler:   "ld #nla",
275
+		},
276
+		{
277
+			instruction: LoadExtension{Num: ExtNetlinkAttrNested},
278
+			assembler:   "ld #nlan",
279
+		},
280
+		{
281
+			instruction: LoadExtension{Num: ExtMark},
282
+			assembler:   "ld #mark",
283
+		},
284
+		{
285
+			instruction: LoadExtension{Num: ExtQueue},
286
+			assembler:   "ld #queue",
287
+		},
288
+		{
289
+			instruction: LoadExtension{Num: ExtLinkLayerType},
290
+			assembler:   "ld #hatype",
291
+		},
292
+		{
293
+			instruction: LoadExtension{Num: ExtRXHash},
294
+			assembler:   "ld #rxhash",
295
+		},
296
+		{
297
+			instruction: LoadExtension{Num: ExtCPUID},
298
+			assembler:   "ld #cpu",
299
+		},
300
+		{
301
+			instruction: LoadExtension{Num: ExtVLANTag},
302
+			assembler:   "ld #vlan_tci",
303
+		},
304
+		{
305
+			instruction: LoadExtension{Num: ExtVLANTagPresent},
306
+			assembler:   "ld #vlan_avail",
307
+		},
308
+		{
309
+			instruction: LoadExtension{Num: ExtVLANProto},
310
+			assembler:   "ld #vlan_tpid",
311
+		},
312
+		{
313
+			instruction: LoadExtension{Num: ExtRand},
314
+			assembler:   "ld #rand",
315
+		},
316
+		{
317
+			instruction: LoadAbsolute{Off: 0xfffff038, Size: 4},
318
+			assembler:   "ld #rand",
319
+		},
320
+		{
321
+			instruction: LoadExtension{Num: 0xfff},
322
+			assembler:   "unknown instruction: bpf.LoadExtension{Num:4095}",
323
+		},
324
+		{
325
+			instruction: StoreScratch{Src: RegA, N: 3},
326
+			assembler:   "st M[3]",
327
+		},
328
+		{
329
+			instruction: StoreScratch{Src: RegX, N: 3},
330
+			assembler:   "stx M[3]",
331
+		},
332
+		{
333
+			instruction: StoreScratch{Src: 0xffff, N: 3},
334
+			assembler:   "unknown instruction: bpf.StoreScratch{Src:0xffff, N:3}",
335
+		},
336
+		{
337
+			instruction: ALUOpConstant{Op: ALUOpAdd, Val: 42},
338
+			assembler:   "add #42",
339
+		},
340
+		{
341
+			instruction: ALUOpConstant{Op: ALUOpSub, Val: 42},
342
+			assembler:   "sub #42",
343
+		},
344
+		{
345
+			instruction: ALUOpConstant{Op: ALUOpMul, Val: 42},
346
+			assembler:   "mul #42",
347
+		},
348
+		{
349
+			instruction: ALUOpConstant{Op: ALUOpDiv, Val: 42},
350
+			assembler:   "div #42",
351
+		},
352
+		{
353
+			instruction: ALUOpConstant{Op: ALUOpOr, Val: 42},
354
+			assembler:   "or #42",
355
+		},
356
+		{
357
+			instruction: ALUOpConstant{Op: ALUOpAnd, Val: 42},
358
+			assembler:   "and #42",
359
+		},
360
+		{
361
+			instruction: ALUOpConstant{Op: ALUOpShiftLeft, Val: 42},
362
+			assembler:   "lsh #42",
363
+		},
364
+		{
365
+			instruction: ALUOpConstant{Op: ALUOpShiftRight, Val: 42},
366
+			assembler:   "rsh #42",
367
+		},
368
+		{
369
+			instruction: ALUOpConstant{Op: ALUOpMod, Val: 42},
370
+			assembler:   "mod #42",
371
+		},
372
+		{
373
+			instruction: ALUOpConstant{Op: ALUOpXor, Val: 42},
374
+			assembler:   "xor #42",
375
+		},
376
+		{
377
+			instruction: ALUOpConstant{Op: 0xffff, Val: 42},
378
+			assembler:   "unknown instruction: bpf.ALUOpConstant{Op:0xffff, Val:0x2a}",
379
+		},
380
+		{
381
+			instruction: ALUOpX{Op: ALUOpAdd},
382
+			assembler:   "add x",
383
+		},
384
+		{
385
+			instruction: ALUOpX{Op: ALUOpSub},
386
+			assembler:   "sub x",
387
+		},
388
+		{
389
+			instruction: ALUOpX{Op: ALUOpMul},
390
+			assembler:   "mul x",
391
+		},
392
+		{
393
+			instruction: ALUOpX{Op: ALUOpDiv},
394
+			assembler:   "div x",
395
+		},
396
+		{
397
+			instruction: ALUOpX{Op: ALUOpOr},
398
+			assembler:   "or x",
399
+		},
400
+		{
401
+			instruction: ALUOpX{Op: ALUOpAnd},
402
+			assembler:   "and x",
403
+		},
404
+		{
405
+			instruction: ALUOpX{Op: ALUOpShiftLeft},
406
+			assembler:   "lsh x",
407
+		},
408
+		{
409
+			instruction: ALUOpX{Op: ALUOpShiftRight},
410
+			assembler:   "rsh x",
411
+		},
412
+		{
413
+			instruction: ALUOpX{Op: ALUOpMod},
414
+			assembler:   "mod x",
415
+		},
416
+		{
417
+			instruction: ALUOpX{Op: ALUOpXor},
418
+			assembler:   "xor x",
419
+		},
420
+		{
421
+			instruction: ALUOpX{Op: 0xffff},
422
+			assembler:   "unknown instruction: bpf.ALUOpX{Op:0xffff}",
423
+		},
424
+		{
425
+			instruction: NegateA{},
426
+			assembler:   "neg",
427
+		},
428
+		{
429
+			instruction: Jump{Skip: 10},
430
+			assembler:   "ja 10",
431
+		},
432
+		{
433
+			instruction: JumpIf{Cond: JumpEqual, Val: 42, SkipTrue: 8, SkipFalse: 9},
434
+			assembler:   "jeq #42,8,9",
435
+		},
436
+		{
437
+			instruction: JumpIf{Cond: JumpEqual, Val: 42, SkipTrue: 8},
438
+			assembler:   "jeq #42,8",
439
+		},
440
+		{
441
+			instruction: JumpIf{Cond: JumpEqual, Val: 42, SkipFalse: 8},
442
+			assembler:   "jneq #42,8",
443
+		},
444
+		{
445
+			instruction: JumpIf{Cond: JumpNotEqual, Val: 42, SkipTrue: 8},
446
+			assembler:   "jneq #42,8",
447
+		},
448
+		{
449
+			instruction: JumpIf{Cond: JumpLessThan, Val: 42, SkipTrue: 7},
450
+			assembler:   "jlt #42,7",
451
+		},
452
+		{
453
+			instruction: JumpIf{Cond: JumpLessOrEqual, Val: 42, SkipTrue: 6},
454
+			assembler:   "jle #42,6",
455
+		},
456
+		{
457
+			instruction: JumpIf{Cond: JumpGreaterThan, Val: 42, SkipTrue: 4, SkipFalse: 5},
458
+			assembler:   "jgt #42,4,5",
459
+		},
460
+		{
461
+			instruction: JumpIf{Cond: JumpGreaterThan, Val: 42, SkipTrue: 4},
462
+			assembler:   "jgt #42,4",
463
+		},
464
+		{
465
+			instruction: JumpIf{Cond: JumpGreaterOrEqual, Val: 42, SkipTrue: 3, SkipFalse: 4},
466
+			assembler:   "jge #42,3,4",
467
+		},
468
+		{
469
+			instruction: JumpIf{Cond: JumpGreaterOrEqual, Val: 42, SkipTrue: 3},
470
+			assembler:   "jge #42,3",
471
+		},
472
+		{
473
+			instruction: JumpIf{Cond: JumpBitsSet, Val: 42, SkipTrue: 2, SkipFalse: 3},
474
+			assembler:   "jset #42,2,3",
475
+		},
476
+		{
477
+			instruction: JumpIf{Cond: JumpBitsSet, Val: 42, SkipTrue: 2},
478
+			assembler:   "jset #42,2",
479
+		},
480
+		{
481
+			instruction: JumpIf{Cond: JumpBitsNotSet, Val: 42, SkipTrue: 2, SkipFalse: 3},
482
+			assembler:   "jset #42,3,2",
483
+		},
484
+		{
485
+			instruction: JumpIf{Cond: JumpBitsNotSet, Val: 42, SkipTrue: 2},
486
+			assembler:   "jset #42,0,2",
487
+		},
488
+		{
489
+			instruction: JumpIf{Cond: 0xffff, Val: 42, SkipTrue: 1, SkipFalse: 2},
490
+			assembler:   "unknown instruction: bpf.JumpIf{Cond:0xffff, Val:0x2a, SkipTrue:0x1, SkipFalse:0x2}",
491
+		},
492
+		{
493
+			instruction: TAX{},
494
+			assembler:   "tax",
495
+		},
496
+		{
497
+			instruction: TXA{},
498
+			assembler:   "txa",
499
+		},
500
+		{
501
+			instruction: RetA{},
502
+			assembler:   "ret a",
503
+		},
504
+		{
505
+			instruction: RetConstant{Val: 42},
506
+			assembler:   "ret #42",
507
+		},
508
+		// Invalid instruction
509
+		{
510
+			instruction: InvalidInstruction{},
511
+			assembler:   "unknown instruction: bpf.InvalidInstruction{}",
512
+		},
513
+	}
514
+
515
+	for _, testCase := range testCases {
516
+		if input, ok := testCase.instruction.(fmt.Stringer); ok {
517
+			got := input.String()
518
+			if got != testCase.assembler {
519
+				t.Errorf("String did not return expected assembler notation, expected: %s, got: %s", testCase.assembler, got)
520
+			}
521
+		} else {
522
+			t.Errorf("Instruction %#v is not a fmt.Stringer", testCase.instruction)
523
+		}
524
+	}
525
+}

+ 10
- 0
vendor/golang.org/x/net/bpf/setter.go View File

@@ -0,0 +1,10 @@
1
+// Copyright 2017 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package bpf
6
+
7
+// A Setter is a type which can attach a compiled BPF filter to itself.
8
+type Setter interface {
9
+	SetBPF(filter []RawInstruction) error
10
+}

+ 1
- 0
vendor/golang.org/x/net/bpf/testdata/all_instructions.bpf View File

@@ -0,0 +1 @@
1
+50,0 0 0 42,1 0 0 42,96 0 0 3,97 0 0 3,48 0 0 42,40 0 0 42,32 0 0 42,80 0 0 42,72 0 0 42,64 0 0 42,177 0 0 42,128 0 0 0,32 0 0 4294963200,32 0 0 4294963204,32 0 0 4294963256,2 0 0 3,3 0 0 3,4 0 0 42,20 0 0 42,36 0 0 42,52 0 0 42,68 0 0 42,84 0 0 42,100 0 0 42,116 0 0 42,148 0 0 42,164 0 0 42,12 0 0 0,28 0 0 0,44 0 0 0,60 0 0 0,76 0 0 0,92 0 0 0,108 0 0 0,124 0 0 0,156 0 0 0,172 0 0 0,132 0 0 0,5 0 0 10,21 8 9 42,21 0 8 42,53 0 7 42,37 0 6 42,37 4 5 42,53 3 4 42,69 2 3 42,7 0 0 0,135 0 0 0,22 0 0 0,6 0 0 0,

+ 79
- 0
vendor/golang.org/x/net/bpf/testdata/all_instructions.txt View File

@@ -0,0 +1,79 @@
1
+# This filter is compiled to all_instructions.bpf by the `bpf_asm`
2
+# tool, which can be found in the linux kernel source tree under
3
+# tools/net.
4
+
5
+# Load immediate
6
+ld #42
7
+ldx #42
8
+
9
+# Load scratch
10
+ld M[3]
11
+ldx M[3]
12
+
13
+# Load absolute
14
+ldb [42]
15
+ldh [42]
16
+ld [42]
17
+
18
+# Load indirect
19
+ldb [x + 42]
20
+ldh [x + 42]
21
+ld [x + 42]
22
+
23
+# Load IPv4 header length
24
+ldx 4*([42]&0xf)
25
+
26
+# Run extension function
27
+ld #len
28
+ld #proto
29
+ld #type
30
+ld #rand
31
+
32
+# Store scratch
33
+st M[3]
34
+stx M[3]
35
+
36
+# A <op> constant
37
+add #42
38
+sub #42
39
+mul #42
40
+div #42
41
+or #42
42
+and #42
43
+lsh #42
44
+rsh #42
45
+mod #42
46
+xor #42
47
+
48
+# A <op> X
49
+add x
50
+sub x
51
+mul x
52
+div x
53
+or x
54
+and x
55
+lsh x
56
+rsh x
57
+mod x
58
+xor x
59
+
60
+# !A
61
+neg
62
+
63
+# Jumps
64
+ja end
65
+jeq #42,prev,end
66
+jne #42,end
67
+jlt #42,end
68
+jle #42,end
69
+jgt #42,prev,end
70
+jge #42,prev,end
71
+jset #42,prev,end
72
+
73
+# Register transfers
74
+tax
75
+txa
76
+
77
+# Returns
78
+prev: ret a
79
+end: ret #42

+ 140
- 0
vendor/golang.org/x/net/bpf/vm.go View File

@@ -0,0 +1,140 @@
1
+// Copyright 2016 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package bpf
6
+
7
+import (
8
+	"errors"
9
+	"fmt"
10
+)
11
+
12
+// A VM is an emulated BPF virtual machine.
13
+type VM struct {
14
+	filter []Instruction
15
+}
16
+
17
+// NewVM returns a new VM using the input BPF program.
18
+func NewVM(filter []Instruction) (*VM, error) {
19
+	if len(filter) == 0 {
20
+		return nil, errors.New("one or more Instructions must be specified")
21
+	}
22
+
23
+	for i, ins := range filter {
24
+		check := len(filter) - (i + 1)
25
+		switch ins := ins.(type) {
26
+		// Check for out-of-bounds jumps in instructions
27
+		case Jump:
28
+			if check <= int(ins.Skip) {
29
+				return nil, fmt.Errorf("cannot jump %d instructions; jumping past program bounds", ins.Skip)
30
+			}
31
+		case JumpIf:
32
+			if check <= int(ins.SkipTrue) {
33
+				return nil, fmt.Errorf("cannot jump %d instructions in true case; jumping past program bounds", ins.SkipTrue)
34
+			}
35
+			if check <= int(ins.SkipFalse) {
36
+				return nil, fmt.Errorf("cannot jump %d instructions in false case; jumping past program bounds", ins.SkipFalse)
37
+			}
38
+		// Check for division or modulus by zero
39
+		case ALUOpConstant:
40
+			if ins.Val != 0 {
41
+				break
42
+			}
43
+
44
+			switch ins.Op {
45
+			case ALUOpDiv, ALUOpMod:
46
+				return nil, errors.New("cannot divide by zero using ALUOpConstant")
47
+			}
48
+		// Check for unknown extensions
49
+		case LoadExtension:
50
+			switch ins.Num {
51
+			case ExtLen:
52
+			default:
53
+				return nil, fmt.Errorf("extension %d not implemented", ins.Num)
54
+			}
55
+		}
56
+	}
57
+
58
+	// Make sure last instruction is a return instruction
59
+	switch filter[len(filter)-1].(type) {
60
+	case RetA, RetConstant:
61
+	default:
62
+		return nil, errors.New("BPF program must end with RetA or RetConstant")
63
+	}
64
+
65
+	// Though our VM works using disassembled instructions, we
66
+	// attempt to assemble the input filter anyway to ensure it is compatible
67
+	// with an operating system VM.
68
+	_, err := Assemble(filter)
69
+
70
+	return &VM{
71
+		filter: filter,
72
+	}, err
73
+}
74
+
75
+// Run runs the VM's BPF program against the input bytes.
76
+// Run returns the number of bytes accepted by the BPF program, and any errors
77
+// which occurred while processing the program.
78
+func (v *VM) Run(in []byte) (int, error) {
79
+	var (
80
+		// Registers of the virtual machine
81
+		regA       uint32
82
+		regX       uint32
83
+		regScratch [16]uint32
84
+
85
+		// OK is true if the program should continue processing the next
86
+		// instruction, or false if not, causing the loop to break
87
+		ok = true
88
+	)
89
+
90
+	// TODO(mdlayher): implement:
91
+	// - NegateA:
92
+	//   - would require a change from uint32 registers to int32
93
+	//     registers
94
+
95
+	// TODO(mdlayher): add interop tests that check signedness of ALU
96
+	// operations against kernel implementation, and make sure Go
97
+	// implementation matches behavior
98
+
99
+	for i := 0; i < len(v.filter) && ok; i++ {
100
+		ins := v.filter[i]
101
+
102
+		switch ins := ins.(type) {
103
+		case ALUOpConstant:
104
+			regA = aluOpConstant(ins, regA)
105
+		case ALUOpX:
106
+			regA, ok = aluOpX(ins, regA, regX)
107
+		case Jump:
108
+			i += int(ins.Skip)
109
+		case JumpIf:
110
+			jump := jumpIf(ins, regA)
111
+			i += jump
112
+		case LoadAbsolute:
113
+			regA, ok = loadAbsolute(ins, in)
114
+		case LoadConstant:
115
+			regA, regX = loadConstant(ins, regA, regX)
116
+		case LoadExtension:
117
+			regA = loadExtension(ins, in)
118
+		case LoadIndirect:
119
+			regA, ok = loadIndirect(ins, in, regX)
120
+		case LoadMemShift:
121
+			regX, ok = loadMemShift(ins, in)
122
+		case LoadScratch:
123
+			regA, regX = loadScratch(ins, regScratch, regA, regX)
124
+		case RetA:
125
+			return int(regA), nil
126
+		case RetConstant:
127
+			return int(ins.Val), nil
128
+		case StoreScratch:
129
+			regScratch = storeScratch(ins, regScratch, regA, regX)
130
+		case TAX:
131
+			regX = regA
132
+		case TXA:
133
+			regA = regX
134
+		default:
135
+			return 0, fmt.Errorf("unknown Instruction at index %d: %T", i, ins)
136
+		}
137
+	}
138
+
139
+	return 0, nil
140
+}

+ 512
- 0
vendor/golang.org/x/net/bpf/vm_aluop_test.go View File

@@ -0,0 +1,512 @@
1
+// Copyright 2016 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package bpf_test
6
+
7
+import (
8
+	"testing"
9
+
10
+	"golang.org/x/net/bpf"
11
+)
12
+
13
+func TestVMALUOpAdd(t *testing.T) {
14
+	vm, done, err := testVM(t, []bpf.Instruction{
15
+		bpf.LoadAbsolute{
16
+			Off:  8,
17
+			Size: 1,
18
+		},
19
+		bpf.ALUOpConstant{
20
+			Op:  bpf.ALUOpAdd,
21
+			Val: 3,
22
+		},
23
+		bpf.RetA{},
24
+	})
25
+	if err != nil {
26
+		t.Fatalf("failed to load BPF program: %v", err)
27
+	}
28
+	defer done()
29
+
30
+	out, err := vm.Run([]byte{
31
+		0xff, 0xff, 0xff, 0xff,
32
+		0xff, 0xff, 0xff, 0xff,
33
+		8, 2, 3,
34
+	})
35
+	if err != nil {
36
+		t.Fatalf("unexpected error while running program: %v", err)
37
+	}
38
+	if want, got := 3, out; want != got {
39
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
40
+			want, got)
41
+	}
42
+}
43
+
44
+func TestVMALUOpSub(t *testing.T) {
45
+	vm, done, err := testVM(t, []bpf.Instruction{
46
+		bpf.LoadAbsolute{
47
+			Off:  8,
48
+			Size: 1,
49
+		},
50
+		bpf.TAX{},
51
+		bpf.ALUOpX{
52
+			Op: bpf.ALUOpSub,
53
+		},
54
+		bpf.RetA{},
55
+	})
56
+	if err != nil {
57
+		t.Fatalf("failed to load BPF program: %v", err)
58
+	}
59
+	defer done()
60
+
61
+	out, err := vm.Run([]byte{
62
+		0xff, 0xff, 0xff, 0xff,
63
+		0xff, 0xff, 0xff, 0xff,
64
+		1, 2, 3,
65
+	})
66
+	if err != nil {
67
+		t.Fatalf("unexpected error while running program: %v", err)
68
+	}
69
+	if want, got := 0, out; want != got {
70
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
71
+			want, got)
72
+	}
73
+}
74
+
75
+func TestVMALUOpMul(t *testing.T) {
76
+	vm, done, err := testVM(t, []bpf.Instruction{
77
+		bpf.LoadAbsolute{
78
+			Off:  8,
79
+			Size: 1,
80
+		},
81
+		bpf.ALUOpConstant{
82
+			Op:  bpf.ALUOpMul,
83
+			Val: 2,
84
+		},
85
+		bpf.RetA{},
86
+	})
87
+	if err != nil {
88
+		t.Fatalf("failed to load BPF program: %v", err)
89
+	}
90
+	defer done()
91
+
92
+	out, err := vm.Run([]byte{
93
+		0xff, 0xff, 0xff, 0xff,
94
+		0xff, 0xff, 0xff, 0xff,
95
+		6, 2, 3, 4,
96
+	})
97
+	if err != nil {
98
+		t.Fatalf("unexpected error while running program: %v", err)
99
+	}
100
+	if want, got := 4, out; want != got {
101
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
102
+			want, got)
103
+	}
104
+}
105
+
106
+func TestVMALUOpDiv(t *testing.T) {
107
+	vm, done, err := testVM(t, []bpf.Instruction{
108
+		bpf.LoadAbsolute{
109
+			Off:  8,
110
+			Size: 1,
111
+		},
112
+		bpf.ALUOpConstant{
113
+			Op:  bpf.ALUOpDiv,
114
+			Val: 2,
115
+		},
116
+		bpf.RetA{},
117
+	})
118
+	if err != nil {
119
+		t.Fatalf("failed to load BPF program: %v", err)
120
+	}
121
+	defer done()
122
+
123
+	out, err := vm.Run([]byte{
124
+		0xff, 0xff, 0xff, 0xff,
125
+		0xff, 0xff, 0xff, 0xff,
126
+		20, 2, 3, 4,
127
+	})
128
+	if err != nil {
129
+		t.Fatalf("unexpected error while running program: %v", err)
130
+	}
131
+	if want, got := 2, out; want != got {
132
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
133
+			want, got)
134
+	}
135
+}
136
+
137
+func TestVMALUOpDivByZeroALUOpConstant(t *testing.T) {
138
+	_, _, err := testVM(t, []bpf.Instruction{
139
+		bpf.ALUOpConstant{
140
+			Op:  bpf.ALUOpDiv,
141
+			Val: 0,
142
+		},
143
+		bpf.RetA{},
144
+	})
145
+	if errStr(err) != "cannot divide by zero using ALUOpConstant" {
146
+		t.Fatalf("unexpected error: %v", err)
147
+	}
148
+}
149
+
150
+func TestVMALUOpDivByZeroALUOpX(t *testing.T) {
151
+	vm, done, err := testVM(t, []bpf.Instruction{
152
+		// Load byte 0 into X
153
+		bpf.LoadAbsolute{
154
+			Off:  8,
155
+			Size: 1,
156
+		},
157
+		bpf.TAX{},
158
+		// Load byte 1 into A
159
+		bpf.LoadAbsolute{
160
+			Off:  9,
161
+			Size: 1,
162
+		},
163
+		// Attempt to perform 1/0
164
+		bpf.ALUOpX{
165
+			Op: bpf.ALUOpDiv,
166
+		},
167
+		// Return 4 bytes if program does not terminate
168
+		bpf.LoadConstant{
169
+			Val: 12,
170
+		},
171
+		bpf.RetA{},
172
+	})
173
+	if err != nil {
174
+		t.Fatalf("failed to load BPF program: %v", err)
175
+	}
176
+	defer done()
177
+
178
+	out, err := vm.Run([]byte{
179
+		0xff, 0xff, 0xff, 0xff,
180
+		0xff, 0xff, 0xff, 0xff,
181
+		0, 1, 3, 4,
182
+	})
183
+	if err != nil {
184
+		t.Fatalf("unexpected error while running program: %v", err)
185
+	}
186
+	if want, got := 0, out; want != got {
187
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
188
+			want, got)
189
+	}
190
+}
191
+
192
+func TestVMALUOpOr(t *testing.T) {
193
+	vm, done, err := testVM(t, []bpf.Instruction{
194
+		bpf.LoadAbsolute{
195
+			Off:  8,
196
+			Size: 2,
197
+		},
198
+		bpf.ALUOpConstant{
199
+			Op:  bpf.ALUOpOr,
200
+			Val: 0x01,
201
+		},
202
+		bpf.RetA{},
203
+	})
204
+	if err != nil {
205
+		t.Fatalf("failed to load BPF program: %v", err)
206
+	}
207
+	defer done()
208
+
209
+	out, err := vm.Run([]byte{
210
+		0xff, 0xff, 0xff, 0xff,
211
+		0xff, 0xff, 0xff, 0xff,
212
+		0x00, 0x10, 0x03, 0x04,
213
+		0x05, 0x06, 0x07, 0x08,
214
+		0x09, 0xff,
215
+	})
216
+	if err != nil {
217
+		t.Fatalf("unexpected error while running program: %v", err)
218
+	}
219
+	if want, got := 9, out; want != got {
220
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
221
+			want, got)
222
+	}
223
+}
224
+
225
+func TestVMALUOpAnd(t *testing.T) {
226
+	vm, done, err := testVM(t, []bpf.Instruction{
227
+		bpf.LoadAbsolute{
228
+			Off:  8,
229
+			Size: 2,
230
+		},
231
+		bpf.ALUOpConstant{
232
+			Op:  bpf.ALUOpAnd,
233
+			Val: 0x0019,
234
+		},
235
+		bpf.RetA{},
236
+	})
237
+	if err != nil {
238
+		t.Fatalf("failed to load BPF program: %v", err)
239
+	}
240
+	defer done()
241
+
242
+	out, err := vm.Run([]byte{
243
+		0xff, 0xff, 0xff, 0xff,
244
+		0xff, 0xff, 0xff, 0xff,
245
+		0xaa, 0x09,
246
+	})
247
+	if err != nil {
248
+		t.Fatalf("unexpected error while running program: %v", err)
249
+	}
250
+	if want, got := 1, out; want != got {
251
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
252
+			want, got)
253
+	}
254
+}
255
+
256
+func TestVMALUOpShiftLeft(t *testing.T) {
257
+	vm, done, err := testVM(t, []bpf.Instruction{
258
+		bpf.LoadAbsolute{
259
+			Off:  8,
260
+			Size: 1,
261
+		},
262
+		bpf.ALUOpConstant{
263
+			Op:  bpf.ALUOpShiftLeft,
264
+			Val: 0x01,
265
+		},
266
+		bpf.JumpIf{
267
+			Cond:     bpf.JumpEqual,
268
+			Val:      0x02,
269
+			SkipTrue: 1,
270
+		},
271
+		bpf.RetConstant{
272
+			Val: 0,
273
+		},
274
+		bpf.RetConstant{
275
+			Val: 9,
276
+		},
277
+	})
278
+	if err != nil {
279
+		t.Fatalf("failed to load BPF program: %v", err)
280
+	}
281
+	defer done()
282
+
283
+	out, err := vm.Run([]byte{
284
+		0xff, 0xff, 0xff, 0xff,
285
+		0xff, 0xff, 0xff, 0xff,
286
+		0x01, 0xaa,
287
+	})
288
+	if err != nil {
289
+		t.Fatalf("unexpected error while running program: %v", err)
290
+	}
291
+	if want, got := 1, out; want != got {
292
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
293
+			want, got)
294
+	}
295
+}
296
+
297
+func TestVMALUOpShiftRight(t *testing.T) {
298
+	vm, done, err := testVM(t, []bpf.Instruction{
299
+		bpf.LoadAbsolute{
300
+			Off:  8,
301
+			Size: 1,
302
+		},
303
+		bpf.ALUOpConstant{
304
+			Op:  bpf.ALUOpShiftRight,
305
+			Val: 0x01,
306
+		},
307
+		bpf.JumpIf{
308
+			Cond:     bpf.JumpEqual,
309
+			Val:      0x04,
310
+			SkipTrue: 1,
311
+		},
312
+		bpf.RetConstant{
313
+			Val: 0,
314
+		},
315
+		bpf.RetConstant{
316
+			Val: 9,
317
+		},
318
+	})
319
+	if err != nil {
320
+		t.Fatalf("failed to load BPF program: %v", err)
321
+	}
322
+	defer done()
323
+
324
+	out, err := vm.Run([]byte{
325
+		0xff, 0xff, 0xff, 0xff,
326
+		0xff, 0xff, 0xff, 0xff,
327
+		0x08, 0xff, 0xff,
328
+	})
329
+	if err != nil {
330
+		t.Fatalf("unexpected error while running program: %v", err)
331
+	}
332
+	if want, got := 1, out; want != got {
333
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
334
+			want, got)
335
+	}
336
+}
337
+
338
+func TestVMALUOpMod(t *testing.T) {
339
+	vm, done, err := testVM(t, []bpf.Instruction{
340
+		bpf.LoadAbsolute{
341
+			Off:  8,
342
+			Size: 1,
343
+		},
344
+		bpf.ALUOpConstant{
345
+			Op:  bpf.ALUOpMod,
346
+			Val: 20,
347
+		},
348
+		bpf.RetA{},
349
+	})
350
+	if err != nil {
351
+		t.Fatalf("failed to load BPF program: %v", err)
352
+	}
353
+	defer done()
354
+
355
+	out, err := vm.Run([]byte{
356
+		0xff, 0xff, 0xff, 0xff,
357
+		0xff, 0xff, 0xff, 0xff,
358
+		30, 0, 0,
359
+	})
360
+	if err != nil {
361
+		t.Fatalf("unexpected error while running program: %v", err)
362
+	}
363
+	if want, got := 2, out; want != got {
364
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
365
+			want, got)
366
+	}
367
+}
368
+
369
+func TestVMALUOpModByZeroALUOpConstant(t *testing.T) {
370
+	_, _, err := testVM(t, []bpf.Instruction{
371
+		bpf.LoadAbsolute{
372
+			Off:  8,
373
+			Size: 1,
374
+		},
375
+		bpf.ALUOpConstant{
376
+			Op:  bpf.ALUOpMod,
377
+			Val: 0,
378
+		},
379
+		bpf.RetA{},
380
+	})
381
+	if errStr(err) != "cannot divide by zero using ALUOpConstant" {
382
+		t.Fatalf("unexpected error: %v", err)
383
+	}
384
+}
385
+
386
+func TestVMALUOpModByZeroALUOpX(t *testing.T) {
387
+	vm, done, err := testVM(t, []bpf.Instruction{
388
+		// Load byte 0 into X
389
+		bpf.LoadAbsolute{
390
+			Off:  8,
391
+			Size: 1,
392
+		},
393
+		bpf.TAX{},
394
+		// Load byte 1 into A
395
+		bpf.LoadAbsolute{
396
+			Off:  9,
397
+			Size: 1,
398
+		},
399
+		// Attempt to perform 1%0
400
+		bpf.ALUOpX{
401
+			Op: bpf.ALUOpMod,
402
+		},
403
+		// Return 4 bytes if program does not terminate
404
+		bpf.LoadConstant{
405
+			Val: 12,
406
+		},
407
+		bpf.RetA{},
408
+	})
409
+	if err != nil {
410
+		t.Fatalf("failed to load BPF program: %v", err)
411
+	}
412
+	defer done()
413
+
414
+	out, err := vm.Run([]byte{
415
+		0xff, 0xff, 0xff, 0xff,
416
+		0xff, 0xff, 0xff, 0xff,
417
+		0, 1, 3, 4,
418
+	})
419
+	if err != nil {
420
+		t.Fatalf("unexpected error while running program: %v", err)
421
+	}
422
+	if want, got := 0, out; want != got {
423
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
424
+			want, got)
425
+	}
426
+}
427
+
428
+func TestVMALUOpXor(t *testing.T) {
429
+	vm, done, err := testVM(t, []bpf.Instruction{
430
+		bpf.LoadAbsolute{
431
+			Off:  8,
432
+			Size: 1,
433
+		},
434
+		bpf.ALUOpConstant{
435
+			Op:  bpf.ALUOpXor,
436
+			Val: 0x0a,
437
+		},
438
+		bpf.JumpIf{
439
+			Cond:     bpf.JumpEqual,
440
+			Val:      0x01,
441
+			SkipTrue: 1,
442
+		},
443
+		bpf.RetConstant{
444
+			Val: 0,
445
+		},
446
+		bpf.RetConstant{
447
+			Val: 9,
448
+		},
449
+	})
450
+	if err != nil {
451
+		t.Fatalf("failed to load BPF program: %v", err)
452
+	}
453
+	defer done()
454
+
455
+	out, err := vm.Run([]byte{
456
+		0xff, 0xff, 0xff, 0xff,
457
+		0xff, 0xff, 0xff, 0xff,
458
+		0x0b, 0x00, 0x00, 0x00,
459
+	})
460
+	if err != nil {
461
+		t.Fatalf("unexpected error while running program: %v", err)
462
+	}
463
+	if want, got := 1, out; want != got {
464
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
465
+			want, got)
466
+	}
467
+}
468
+
469
+func TestVMALUOpUnknown(t *testing.T) {
470
+	vm, done, err := testVM(t, []bpf.Instruction{
471
+		bpf.LoadAbsolute{
472
+			Off:  8,
473
+			Size: 1,
474
+		},
475
+		bpf.ALUOpConstant{
476
+			Op:  bpf.ALUOpAdd,
477
+			Val: 1,
478
+		},
479
+		// Verify that an unknown operation is a no-op
480
+		bpf.ALUOpConstant{
481
+			Op: 100,
482
+		},
483
+		bpf.JumpIf{
484
+			Cond:     bpf.JumpEqual,
485
+			Val:      0x02,
486
+			SkipTrue: 1,
487
+		},
488
+		bpf.RetConstant{
489
+			Val: 0,
490
+		},
491
+		bpf.RetConstant{
492
+			Val: 9,
493
+		},
494
+	})
495
+	if err != nil {
496
+		t.Fatalf("failed to load BPF program: %v", err)
497
+	}
498
+	defer done()
499
+
500
+	out, err := vm.Run([]byte{
501
+		0xff, 0xff, 0xff, 0xff,
502
+		0xff, 0xff, 0xff, 0xff,
503
+		1,
504
+	})
505
+	if err != nil {
506
+		t.Fatalf("unexpected error while running program: %v", err)
507
+	}
508
+	if want, got := 1, out; want != got {
509
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
510
+			want, got)
511
+	}
512
+}

+ 192
- 0
vendor/golang.org/x/net/bpf/vm_bpf_test.go View File

@@ -0,0 +1,192 @@
1
+// Copyright 2016 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package bpf_test
6
+
7
+import (
8
+	"net"
9
+	"runtime"
10
+	"testing"
11
+	"time"
12
+
13
+	"golang.org/x/net/bpf"
14
+	"golang.org/x/net/ipv4"
15
+)
16
+
17
+// A virtualMachine is a BPF virtual machine which can process an
18
+// input packet against a BPF program and render a verdict.
19
+type virtualMachine interface {
20
+	Run(in []byte) (int, error)
21
+}
22
+
23
+// canUseOSVM indicates if the OS BPF VM is available on this platform.
24
+func canUseOSVM() bool {
25
+	// OS BPF VM can only be used on platforms where x/net/ipv4 supports
26
+	// attaching a BPF program to a socket.
27
+	switch runtime.GOOS {
28
+	case "linux":
29
+		return true
30
+	}
31
+
32
+	return false
33
+}
34
+
35
+// All BPF tests against both the Go VM and OS VM are assumed to
36
+// be used with a UDP socket. As a result, the entire contents
37
+// of a UDP datagram is sent through the BPF program, but only
38
+// the body after the UDP header will ever be returned in output.
39
+
40
+// testVM sets up a Go BPF VM, and if available, a native OS BPF VM
41
+// for integration testing.
42
+func testVM(t *testing.T, filter []bpf.Instruction) (virtualMachine, func(), error) {
43
+	goVM, err := bpf.NewVM(filter)
44
+	if err != nil {
45
+		// Some tests expect an error, so this error must be returned
46
+		// instead of fatally exiting the test
47
+		return nil, nil, err
48
+	}
49
+
50
+	mvm := &multiVirtualMachine{
51
+		goVM: goVM,
52
+
53
+		t: t,
54
+	}
55
+
56
+	// If available, add the OS VM for tests which verify that both the Go
57
+	// VM and OS VM have exactly the same output for the same input program
58
+	// and packet.
59
+	done := func() {}
60
+	if canUseOSVM() {
61
+		osVM, osVMDone := testOSVM(t, filter)
62
+		done = func() { osVMDone() }
63
+		mvm.osVM = osVM
64
+	}
65
+
66
+	return mvm, done, nil
67
+}
68
+
69
+// udpHeaderLen is the length of a UDP header.
70
+const udpHeaderLen = 8
71
+
72
+// A multiVirtualMachine is a virtualMachine which can call out to both the Go VM
73
+// and the native OS VM, if the OS VM is available.
74
+type multiVirtualMachine struct {
75
+	goVM virtualMachine
76
+	osVM virtualMachine
77
+
78
+	t *testing.T
79
+}
80
+
81
+func (mvm *multiVirtualMachine) Run(in []byte) (int, error) {
82
+	if len(in) < udpHeaderLen {
83
+		mvm.t.Fatalf("input must be at least length of UDP header (%d), got: %d",
84
+			udpHeaderLen, len(in))
85
+	}
86
+
87
+	// All tests have a UDP header as part of input, because the OS VM
88
+	// packets always will. For the Go VM, this output is trimmed before
89
+	// being sent back to tests.
90
+	goOut, goErr := mvm.goVM.Run(in)
91
+	if goOut >= udpHeaderLen {
92
+		goOut -= udpHeaderLen
93
+	}
94
+
95
+	// If Go output is larger than the size of the packet, packet filtering
96
+	// interop tests must trim the output bytes to the length of the packet.
97
+	// The BPF VM should not do this on its own, as other uses of it do
98
+	// not trim the output byte count.
99
+	trim := len(in) - udpHeaderLen
100
+	if goOut > trim {
101
+		goOut = trim
102
+	}
103
+
104
+	// When the OS VM is not available, process using the Go VM alone
105
+	if mvm.osVM == nil {
106
+		return goOut, goErr
107
+	}
108
+
109
+	// The OS VM will apply its own UDP header, so remove the pseudo header
110
+	// that the Go VM needs.
111
+	osOut, err := mvm.osVM.Run(in[udpHeaderLen:])
112
+	if err != nil {
113
+		mvm.t.Fatalf("error while running OS VM: %v", err)
114
+	}
115
+
116
+	// Verify both VMs return same number of bytes
117
+	var mismatch bool
118
+	if goOut != osOut {
119
+		mismatch = true
120
+		mvm.t.Logf("output byte count does not match:\n- go: %v\n- os: %v", goOut, osOut)
121
+	}
122
+
123
+	if mismatch {
124
+		mvm.t.Fatal("Go BPF and OS BPF packet outputs do not match")
125
+	}
126
+
127
+	return goOut, goErr
128
+}
129
+
130
+// An osVirtualMachine is a virtualMachine which uses the OS's BPF VM for
131
+// processing BPF programs.
132
+type osVirtualMachine struct {
133
+	l net.PacketConn
134
+	s net.Conn
135
+}
136
+
137
+// testOSVM creates a virtualMachine which uses the OS's BPF VM by injecting
138
+// packets into a UDP listener with a BPF program attached to it.
139
+func testOSVM(t *testing.T, filter []bpf.Instruction) (virtualMachine, func()) {
140
+	l, err := net.ListenPacket("udp4", "127.0.0.1:0")
141
+	if err != nil {
142
+		t.Fatalf("failed to open OS VM UDP listener: %v", err)
143
+	}
144
+
145
+	prog, err := bpf.Assemble(filter)
146
+	if err != nil {
147
+		t.Fatalf("failed to compile BPF program: %v", err)
148
+	}
149
+
150
+	p := ipv4.NewPacketConn(l)
151
+	if err = p.SetBPF(prog); err != nil {
152
+		t.Fatalf("failed to attach BPF program to listener: %v", err)
153
+	}
154
+
155
+	s, err := net.Dial("udp4", l.LocalAddr().String())
156
+	if err != nil {
157
+		t.Fatalf("failed to dial connection to listener: %v", err)
158
+	}
159
+
160
+	done := func() {
161
+		_ = s.Close()
162
+		_ = l.Close()
163
+	}
164
+
165
+	return &osVirtualMachine{
166
+		l: l,
167
+		s: s,
168
+	}, done
169
+}
170
+
171
+// Run sends the input bytes into the OS's BPF VM and returns its verdict.
172
+func (vm *osVirtualMachine) Run(in []byte) (int, error) {
173
+	go func() {
174
+		_, _ = vm.s.Write(in)
175
+	}()
176
+
177
+	vm.l.SetDeadline(time.Now().Add(50 * time.Millisecond))
178
+
179
+	var b [512]byte
180
+	n, _, err := vm.l.ReadFrom(b[:])
181
+	if err != nil {
182
+		// A timeout indicates that BPF filtered out the packet, and thus,
183
+		// no input should be returned.
184
+		if nerr, ok := err.(net.Error); ok && nerr.Timeout() {
185
+			return n, nil
186
+		}
187
+
188
+		return n, err
189
+	}
190
+
191
+	return n, nil
192
+}

+ 49
- 0
vendor/golang.org/x/net/bpf/vm_extension_test.go View File

@@ -0,0 +1,49 @@
1
+// Copyright 2016 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package bpf_test
6
+
7
+import (
8
+	"testing"
9
+
10
+	"golang.org/x/net/bpf"
11
+)
12
+
13
+func TestVMLoadExtensionNotImplemented(t *testing.T) {
14
+	_, _, err := testVM(t, []bpf.Instruction{
15
+		bpf.LoadExtension{
16
+			Num: 100,
17
+		},
18
+		bpf.RetA{},
19
+	})
20
+	if errStr(err) != "extension 100 not implemented" {
21
+		t.Fatalf("unexpected error: %v", err)
22
+	}
23
+}
24
+
25
+func TestVMLoadExtensionExtLen(t *testing.T) {
26
+	vm, done, err := testVM(t, []bpf.Instruction{
27
+		bpf.LoadExtension{
28
+			Num: bpf.ExtLen,
29
+		},
30
+		bpf.RetA{},
31
+	})
32
+	if err != nil {
33
+		t.Fatalf("failed to load BPF program: %v", err)
34
+	}
35
+	defer done()
36
+
37
+	out, err := vm.Run([]byte{
38
+		0xff, 0xff, 0xff, 0xff,
39
+		0xff, 0xff, 0xff, 0xff,
40
+		0, 1, 2, 3,
41
+	})
42
+	if err != nil {
43
+		t.Fatalf("unexpected error while running program: %v", err)
44
+	}
45
+	if want, got := 4, out; want != got {
46
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
47
+			want, got)
48
+	}
49
+}

+ 174
- 0
vendor/golang.org/x/net/bpf/vm_instructions.go View File

@@ -0,0 +1,174 @@
1
+// Copyright 2016 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package bpf
6
+
7
+import (
8
+	"encoding/binary"
9
+	"fmt"
10
+)
11
+
12
+func aluOpConstant(ins ALUOpConstant, regA uint32) uint32 {
13
+	return aluOpCommon(ins.Op, regA, ins.Val)
14
+}
15
+
16
+func aluOpX(ins ALUOpX, regA uint32, regX uint32) (uint32, bool) {
17
+	// Guard against division or modulus by zero by terminating
18
+	// the program, as the OS BPF VM does
19
+	if regX == 0 {
20
+		switch ins.Op {
21
+		case ALUOpDiv, ALUOpMod:
22
+			return 0, false
23
+		}
24
+	}
25
+
26
+	return aluOpCommon(ins.Op, regA, regX), true
27
+}
28
+
29
+func aluOpCommon(op ALUOp, regA uint32, value uint32) uint32 {
30
+	switch op {
31
+	case ALUOpAdd:
32
+		return regA + value
33
+	case ALUOpSub:
34
+		return regA - value
35
+	case ALUOpMul:
36
+		return regA * value
37
+	case ALUOpDiv:
38
+		// Division by zero not permitted by NewVM and aluOpX checks
39
+		return regA / value
40
+	case ALUOpOr:
41
+		return regA | value
42
+	case ALUOpAnd:
43
+		return regA & value
44
+	case ALUOpShiftLeft:
45
+		return regA << value
46
+	case ALUOpShiftRight:
47
+		return regA >> value
48
+	case ALUOpMod:
49
+		// Modulus by zero not permitted by NewVM and aluOpX checks
50
+		return regA % value
51
+	case ALUOpXor:
52
+		return regA ^ value
53
+	default:
54
+		return regA
55
+	}
56
+}
57
+
58
+func jumpIf(ins JumpIf, value uint32) int {
59
+	var ok bool
60
+	inV := uint32(ins.Val)
61
+
62
+	switch ins.Cond {
63
+	case JumpEqual:
64
+		ok = value == inV
65
+	case JumpNotEqual:
66
+		ok = value != inV
67
+	case JumpGreaterThan:
68
+		ok = value > inV
69
+	case JumpLessThan:
70
+		ok = value < inV
71
+	case JumpGreaterOrEqual:
72
+		ok = value >= inV
73
+	case JumpLessOrEqual:
74
+		ok = value <= inV
75
+	case JumpBitsSet:
76
+		ok = (value & inV) != 0
77
+	case JumpBitsNotSet:
78
+		ok = (value & inV) == 0
79
+	}
80
+
81
+	if ok {
82
+		return int(ins.SkipTrue)
83
+	}
84
+
85
+	return int(ins.SkipFalse)
86
+}
87
+
88
+func loadAbsolute(ins LoadAbsolute, in []byte) (uint32, bool) {
89
+	offset := int(ins.Off)
90
+	size := int(ins.Size)
91
+
92
+	return loadCommon(in, offset, size)
93
+}
94
+
95
+func loadConstant(ins LoadConstant, regA uint32, regX uint32) (uint32, uint32) {
96
+	switch ins.Dst {
97
+	case RegA:
98
+		regA = ins.Val
99
+	case RegX:
100
+		regX = ins.Val
101
+	}
102
+
103
+	return regA, regX
104
+}
105
+
106
+func loadExtension(ins LoadExtension, in []byte) uint32 {
107
+	switch ins.Num {
108
+	case ExtLen:
109
+		return uint32(len(in))
110
+	default:
111
+		panic(fmt.Sprintf("unimplemented extension: %d", ins.Num))
112
+	}
113
+}
114
+
115
+func loadIndirect(ins LoadIndirect, in []byte, regX uint32) (uint32, bool) {
116
+	offset := int(ins.Off) + int(regX)
117
+	size := int(ins.Size)
118
+
119
+	return loadCommon(in, offset, size)
120
+}
121
+
122
+func loadMemShift(ins LoadMemShift, in []byte) (uint32, bool) {
123
+	offset := int(ins.Off)
124
+
125
+	if !inBounds(len(in), offset, 0) {
126
+		return 0, false
127
+	}
128
+
129
+	// Mask off high 4 bits and multiply low 4 bits by 4
130
+	return uint32(in[offset]&0x0f) * 4, true
131
+}
132
+
133
+func inBounds(inLen int, offset int, size int) bool {
134
+	return offset+size <= inLen
135
+}
136
+
137
+func loadCommon(in []byte, offset int, size int) (uint32, bool) {
138
+	if !inBounds(len(in), offset, size) {
139
+		return 0, false
140
+	}
141
+
142
+	switch size {
143
+	case 1:
144
+		return uint32(in[offset]), true
145
+	case 2:
146
+		return uint32(binary.BigEndian.Uint16(in[offset : offset+size])), true
147
+	case 4:
148
+		return uint32(binary.BigEndian.Uint32(in[offset : offset+size])), true
149
+	default:
150
+		panic(fmt.Sprintf("invalid load size: %d", size))
151
+	}
152
+}
153
+
154
+func loadScratch(ins LoadScratch, regScratch [16]uint32, regA uint32, regX uint32) (uint32, uint32) {
155
+	switch ins.Dst {
156
+	case RegA:
157
+		regA = regScratch[ins.N]
158
+	case RegX:
159
+		regX = regScratch[ins.N]
160
+	}
161
+
162
+	return regA, regX
163
+}
164
+
165
+func storeScratch(ins StoreScratch, regScratch [16]uint32, regA uint32, regX uint32) [16]uint32 {
166
+	switch ins.Src {
167
+	case RegA:
168
+		regScratch[ins.N] = regA
169
+	case RegX:
170
+		regScratch[ins.N] = regX
171
+	}
172
+
173
+	return regScratch
174
+}

+ 380
- 0
vendor/golang.org/x/net/bpf/vm_jump_test.go View File

@@ -0,0 +1,380 @@
1
+// Copyright 2016 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package bpf_test
6
+
7
+import (
8
+	"testing"
9
+
10
+	"golang.org/x/net/bpf"
11
+)
12
+
13
+func TestVMJumpOne(t *testing.T) {
14
+	vm, done, err := testVM(t, []bpf.Instruction{
15
+		bpf.LoadAbsolute{
16
+			Off:  8,
17
+			Size: 1,
18
+		},
19
+		bpf.Jump{
20
+			Skip: 1,
21
+		},
22
+		bpf.RetConstant{
23
+			Val: 0,
24
+		},
25
+		bpf.RetConstant{
26
+			Val: 9,
27
+		},
28
+	})
29
+	if err != nil {
30
+		t.Fatalf("failed to load BPF program: %v", err)
31
+	}
32
+	defer done()
33
+
34
+	out, err := vm.Run([]byte{
35
+		0xff, 0xff, 0xff, 0xff,
36
+		0xff, 0xff, 0xff, 0xff,
37
+		1,
38
+	})
39
+	if err != nil {
40
+		t.Fatalf("unexpected error while running program: %v", err)
41
+	}
42
+	if want, got := 1, out; want != got {
43
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
44
+			want, got)
45
+	}
46
+}
47
+
48
+func TestVMJumpOutOfProgram(t *testing.T) {
49
+	_, _, err := testVM(t, []bpf.Instruction{
50
+		bpf.Jump{
51
+			Skip: 1,
52
+		},
53
+		bpf.RetA{},
54
+	})
55
+	if errStr(err) != "cannot jump 1 instructions; jumping past program bounds" {
56
+		t.Fatalf("unexpected error: %v", err)
57
+	}
58
+}
59
+
60
+func TestVMJumpIfTrueOutOfProgram(t *testing.T) {
61
+	_, _, err := testVM(t, []bpf.Instruction{
62
+		bpf.JumpIf{
63
+			Cond:     bpf.JumpEqual,
64
+			SkipTrue: 2,
65
+		},
66
+		bpf.RetA{},
67
+	})
68
+	if errStr(err) != "cannot jump 2 instructions in true case; jumping past program bounds" {
69
+		t.Fatalf("unexpected error: %v", err)
70
+	}
71
+}
72
+
73
+func TestVMJumpIfFalseOutOfProgram(t *testing.T) {
74
+	_, _, err := testVM(t, []bpf.Instruction{
75
+		bpf.JumpIf{
76
+			Cond:      bpf.JumpEqual,
77
+			SkipFalse: 3,
78
+		},
79
+		bpf.RetA{},
80
+	})
81
+	if errStr(err) != "cannot jump 3 instructions in false case; jumping past program bounds" {
82
+		t.Fatalf("unexpected error: %v", err)
83
+	}
84
+}
85
+
86
+func TestVMJumpIfEqual(t *testing.T) {
87
+	vm, done, err := testVM(t, []bpf.Instruction{
88
+		bpf.LoadAbsolute{
89
+			Off:  8,
90
+			Size: 1,
91
+		},
92
+		bpf.JumpIf{
93
+			Cond:     bpf.JumpEqual,
94
+			Val:      1,
95
+			SkipTrue: 1,
96
+		},
97
+		bpf.RetConstant{
98
+			Val: 0,
99
+		},
100
+		bpf.RetConstant{
101
+			Val: 9,
102
+		},
103
+	})
104
+	if err != nil {
105
+		t.Fatalf("failed to load BPF program: %v", err)
106
+	}
107
+	defer done()
108
+
109
+	out, err := vm.Run([]byte{
110
+		0xff, 0xff, 0xff, 0xff,
111
+		0xff, 0xff, 0xff, 0xff,
112
+		1,
113
+	})
114
+	if err != nil {
115
+		t.Fatalf("unexpected error while running program: %v", err)
116
+	}
117
+	if want, got := 1, out; want != got {
118
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
119
+			want, got)
120
+	}
121
+}
122
+
123
+func TestVMJumpIfNotEqual(t *testing.T) {
124
+	vm, done, err := testVM(t, []bpf.Instruction{
125
+		bpf.LoadAbsolute{
126
+			Off:  8,
127
+			Size: 1,
128
+		},
129
+		bpf.JumpIf{
130
+			Cond:      bpf.JumpNotEqual,
131
+			Val:       1,
132
+			SkipFalse: 1,
133
+		},
134
+		bpf.RetConstant{
135
+			Val: 0,
136
+		},
137
+		bpf.RetConstant{
138
+			Val: 9,
139
+		},
140
+	})
141
+	if err != nil {
142
+		t.Fatalf("failed to load BPF program: %v", err)
143
+	}
144
+	defer done()
145
+
146
+	out, err := vm.Run([]byte{
147
+		0xff, 0xff, 0xff, 0xff,
148
+		0xff, 0xff, 0xff, 0xff,
149
+		1,
150
+	})
151
+	if err != nil {
152
+		t.Fatalf("unexpected error while running program: %v", err)
153
+	}
154
+	if want, got := 1, out; want != got {
155
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
156
+			want, got)
157
+	}
158
+}
159
+
160
+func TestVMJumpIfGreaterThan(t *testing.T) {
161
+	vm, done, err := testVM(t, []bpf.Instruction{
162
+		bpf.LoadAbsolute{
163
+			Off:  8,
164
+			Size: 4,
165
+		},
166
+		bpf.JumpIf{
167
+			Cond:     bpf.JumpGreaterThan,
168
+			Val:      0x00010202,
169
+			SkipTrue: 1,
170
+		},
171
+		bpf.RetConstant{
172
+			Val: 0,
173
+		},
174
+		bpf.RetConstant{
175
+			Val: 12,
176
+		},
177
+	})
178
+	if err != nil {
179
+		t.Fatalf("failed to load BPF program: %v", err)
180
+	}
181
+	defer done()
182
+
183
+	out, err := vm.Run([]byte{
184
+		0xff, 0xff, 0xff, 0xff,
185
+		0xff, 0xff, 0xff, 0xff,
186
+		0, 1, 2, 3,
187
+	})
188
+	if err != nil {
189
+		t.Fatalf("unexpected error while running program: %v", err)
190
+	}
191
+	if want, got := 4, out; want != got {
192
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
193
+			want, got)
194
+	}
195
+}
196
+
197
+func TestVMJumpIfLessThan(t *testing.T) {
198
+	vm, done, err := testVM(t, []bpf.Instruction{
199
+		bpf.LoadAbsolute{
200
+			Off:  8,
201
+			Size: 4,
202
+		},
203
+		bpf.JumpIf{
204
+			Cond:     bpf.JumpLessThan,
205
+			Val:      0xff010203,
206
+			SkipTrue: 1,
207
+		},
208
+		bpf.RetConstant{
209
+			Val: 0,
210
+		},
211
+		bpf.RetConstant{
212
+			Val: 12,
213
+		},
214
+	})
215
+	if err != nil {
216
+		t.Fatalf("failed to load BPF program: %v", err)
217
+	}
218
+	defer done()
219
+
220
+	out, err := vm.Run([]byte{
221
+		0xff, 0xff, 0xff, 0xff,
222
+		0xff, 0xff, 0xff, 0xff,
223
+		0, 1, 2, 3,
224
+	})
225
+	if err != nil {
226
+		t.Fatalf("unexpected error while running program: %v", err)
227
+	}
228
+	if want, got := 4, out; want != got {
229
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
230
+			want, got)
231
+	}
232
+}
233
+
234
+func TestVMJumpIfGreaterOrEqual(t *testing.T) {
235
+	vm, done, err := testVM(t, []bpf.Instruction{
236
+		bpf.LoadAbsolute{
237
+			Off:  8,
238
+			Size: 4,
239
+		},
240
+		bpf.JumpIf{
241
+			Cond:     bpf.JumpGreaterOrEqual,
242
+			Val:      0x00010203,
243
+			SkipTrue: 1,
244
+		},
245
+		bpf.RetConstant{
246
+			Val: 0,
247
+		},
248
+		bpf.RetConstant{
249
+			Val: 12,
250
+		},
251
+	})
252
+	if err != nil {
253
+		t.Fatalf("failed to load BPF program: %v", err)
254
+	}
255
+	defer done()
256
+
257
+	out, err := vm.Run([]byte{
258
+		0xff, 0xff, 0xff, 0xff,
259
+		0xff, 0xff, 0xff, 0xff,
260
+		0, 1, 2, 3,
261
+	})
262
+	if err != nil {
263
+		t.Fatalf("unexpected error while running program: %v", err)
264
+	}
265
+	if want, got := 4, out; want != got {
266
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
267
+			want, got)
268
+	}
269
+}
270
+
271
+func TestVMJumpIfLessOrEqual(t *testing.T) {
272
+	vm, done, err := testVM(t, []bpf.Instruction{
273
+		bpf.LoadAbsolute{
274
+			Off:  8,
275
+			Size: 4,
276
+		},
277
+		bpf.JumpIf{
278
+			Cond:     bpf.JumpLessOrEqual,
279
+			Val:      0xff010203,
280
+			SkipTrue: 1,
281
+		},
282
+		bpf.RetConstant{
283
+			Val: 0,
284
+		},
285
+		bpf.RetConstant{
286
+			Val: 12,
287
+		},
288
+	})
289
+	if err != nil {
290
+		t.Fatalf("failed to load BPF program: %v", err)
291
+	}
292
+	defer done()
293
+
294
+	out, err := vm.Run([]byte{
295
+		0xff, 0xff, 0xff, 0xff,
296
+		0xff, 0xff, 0xff, 0xff,
297
+		0, 1, 2, 3,
298
+	})
299
+	if err != nil {
300
+		t.Fatalf("unexpected error while running program: %v", err)
301
+	}
302
+	if want, got := 4, out; want != got {
303
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
304
+			want, got)
305
+	}
306
+}
307
+
308
+func TestVMJumpIfBitsSet(t *testing.T) {
309
+	vm, done, err := testVM(t, []bpf.Instruction{
310
+		bpf.LoadAbsolute{
311
+			Off:  8,
312
+			Size: 2,
313
+		},
314
+		bpf.JumpIf{
315
+			Cond:     bpf.JumpBitsSet,
316
+			Val:      0x1122,
317
+			SkipTrue: 1,
318
+		},
319
+		bpf.RetConstant{
320
+			Val: 0,
321
+		},
322
+		bpf.RetConstant{
323
+			Val: 10,
324
+		},
325
+	})
326
+	if err != nil {
327
+		t.Fatalf("failed to load BPF program: %v", err)
328
+	}
329
+	defer done()
330
+
331
+	out, err := vm.Run([]byte{
332
+		0xff, 0xff, 0xff, 0xff,
333
+		0xff, 0xff, 0xff, 0xff,
334
+		0x01, 0x02,
335
+	})
336
+	if err != nil {
337
+		t.Fatalf("unexpected error while running program: %v", err)
338
+	}
339
+	if want, got := 2, out; want != got {
340
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
341
+			want, got)
342
+	}
343
+}
344
+
345
+func TestVMJumpIfBitsNotSet(t *testing.T) {
346
+	vm, done, err := testVM(t, []bpf.Instruction{
347
+		bpf.LoadAbsolute{
348
+			Off:  8,
349
+			Size: 2,
350
+		},
351
+		bpf.JumpIf{
352
+			Cond:     bpf.JumpBitsNotSet,
353
+			Val:      0x1221,
354
+			SkipTrue: 1,
355
+		},
356
+		bpf.RetConstant{
357
+			Val: 0,
358
+		},
359
+		bpf.RetConstant{
360
+			Val: 10,
361
+		},
362
+	})
363
+	if err != nil {
364
+		t.Fatalf("failed to load BPF program: %v", err)
365
+	}
366
+	defer done()
367
+
368
+	out, err := vm.Run([]byte{
369
+		0xff, 0xff, 0xff, 0xff,
370
+		0xff, 0xff, 0xff, 0xff,
371
+		0x01, 0x02,
372
+	})
373
+	if err != nil {
374
+		t.Fatalf("unexpected error while running program: %v", err)
375
+	}
376
+	if want, got := 2, out; want != got {
377
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
378
+			want, got)
379
+	}
380
+}

+ 246
- 0
vendor/golang.org/x/net/bpf/vm_load_test.go View File

@@ -0,0 +1,246 @@
1
+// Copyright 2016 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package bpf_test
6
+
7
+import (
8
+	"net"
9
+	"testing"
10
+
11
+	"golang.org/x/net/bpf"
12
+	"golang.org/x/net/ipv4"
13
+)
14
+
15
+func TestVMLoadAbsoluteOffsetOutOfBounds(t *testing.T) {
16
+	vm, done, err := testVM(t, []bpf.Instruction{
17
+		bpf.LoadAbsolute{
18
+			Off:  100,
19
+			Size: 2,
20
+		},
21
+		bpf.RetA{},
22
+	})
23
+	if err != nil {
24
+		t.Fatalf("failed to load BPF program: %v", err)
25
+	}
26
+	defer done()
27
+
28
+	out, err := vm.Run([]byte{
29
+		0xff, 0xff, 0xff, 0xff,
30
+		0xff, 0xff, 0xff, 0xff,
31
+		0, 1, 2, 3,
32
+	})
33
+	if err != nil {
34
+		t.Fatalf("unexpected error while running program: %v", err)
35
+	}
36
+	if want, got := 0, out; want != got {
37
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
38
+			want, got)
39
+	}
40
+}
41
+
42
+func TestVMLoadAbsoluteOffsetPlusSizeOutOfBounds(t *testing.T) {
43
+	vm, done, err := testVM(t, []bpf.Instruction{
44
+		bpf.LoadAbsolute{
45
+			Off:  8,
46
+			Size: 2,
47
+		},
48
+		bpf.RetA{},
49
+	})
50
+	if err != nil {
51
+		t.Fatalf("failed to load BPF program: %v", err)
52
+	}
53
+	defer done()
54
+
55
+	out, err := vm.Run([]byte{
56
+		0xff, 0xff, 0xff, 0xff,
57
+		0xff, 0xff, 0xff, 0xff,
58
+		0,
59
+	})
60
+	if err != nil {
61
+		t.Fatalf("unexpected error while running program: %v", err)
62
+	}
63
+	if want, got := 0, out; want != got {
64
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
65
+			want, got)
66
+	}
67
+}
68
+
69
+func TestVMLoadAbsoluteBadInstructionSize(t *testing.T) {
70
+	_, _, err := testVM(t, []bpf.Instruction{
71
+		bpf.LoadAbsolute{
72
+			Size: 5,
73
+		},
74
+		bpf.RetA{},
75
+	})
76
+	if errStr(err) != "assembling instruction 1: invalid load byte length 0" {
77
+		t.Fatalf("unexpected error: %v", err)
78
+	}
79
+}
80
+
81
+func TestVMLoadConstantOK(t *testing.T) {
82
+	vm, done, err := testVM(t, []bpf.Instruction{
83
+		bpf.LoadConstant{
84
+			Dst: bpf.RegX,
85
+			Val: 9,
86
+		},
87
+		bpf.TXA{},
88
+		bpf.RetA{},
89
+	})
90
+	if err != nil {
91
+		t.Fatalf("failed to load BPF program: %v", err)
92
+	}
93
+	defer done()
94
+
95
+	out, err := vm.Run([]byte{
96
+		0xff, 0xff, 0xff, 0xff,
97
+		0xff, 0xff, 0xff, 0xff,
98
+		0,
99
+	})
100
+	if err != nil {
101
+		t.Fatalf("unexpected error while running program: %v", err)
102
+	}
103
+	if want, got := 1, out; want != got {
104
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
105
+			want, got)
106
+	}
107
+}
108
+
109
+func TestVMLoadIndirectOutOfBounds(t *testing.T) {
110
+	vm, done, err := testVM(t, []bpf.Instruction{
111
+		bpf.LoadIndirect{
112
+			Off:  100,
113
+			Size: 1,
114
+		},
115
+		bpf.RetA{},
116
+	})
117
+	if err != nil {
118
+		t.Fatalf("failed to load BPF program: %v", err)
119
+	}
120
+	defer done()
121
+
122
+	out, err := vm.Run([]byte{
123
+		0xff, 0xff, 0xff, 0xff,
124
+		0xff, 0xff, 0xff, 0xff,
125
+		0,
126
+	})
127
+	if err != nil {
128
+		t.Fatalf("unexpected error while running program: %v", err)
129
+	}
130
+	if want, got := 0, out; want != got {
131
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
132
+			want, got)
133
+	}
134
+}
135
+
136
+func TestVMLoadMemShiftOutOfBounds(t *testing.T) {
137
+	vm, done, err := testVM(t, []bpf.Instruction{
138
+		bpf.LoadMemShift{
139
+			Off: 100,
140
+		},
141
+		bpf.RetA{},
142
+	})
143
+	if err != nil {
144
+		t.Fatalf("failed to load BPF program: %v", err)
145
+	}
146
+	defer done()
147
+
148
+	out, err := vm.Run([]byte{
149
+		0xff, 0xff, 0xff, 0xff,
150
+		0xff, 0xff, 0xff, 0xff,
151
+		0,
152
+	})
153
+	if err != nil {
154
+		t.Fatalf("unexpected error while running program: %v", err)
155
+	}
156
+	if want, got := 0, out; want != got {
157
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
158
+			want, got)
159
+	}
160
+}
161
+
162
+const (
163
+	dhcp4Port = 53
164
+)
165
+
166
+func TestVMLoadMemShiftLoadIndirectNoResult(t *testing.T) {
167
+	vm, in, done := testDHCPv4(t)
168
+	defer done()
169
+
170
+	// Append mostly empty UDP header with incorrect DHCPv4 port
171
+	in = append(in, []byte{
172
+		0, 0,
173
+		0, dhcp4Port + 1,
174
+		0, 0,
175
+		0, 0,
176
+	}...)
177
+
178
+	out, err := vm.Run(in)
179
+	if err != nil {
180
+		t.Fatalf("unexpected error while running program: %v", err)
181
+	}
182
+	if want, got := 0, out; want != got {
183
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
184
+			want, got)
185
+	}
186
+}
187
+
188
+func TestVMLoadMemShiftLoadIndirectOK(t *testing.T) {
189
+	vm, in, done := testDHCPv4(t)
190
+	defer done()
191
+
192
+	// Append mostly empty UDP header with correct DHCPv4 port
193
+	in = append(in, []byte{
194
+		0, 0,
195
+		0, dhcp4Port,
196
+		0, 0,
197
+		0, 0,
198
+	}...)
199
+
200
+	out, err := vm.Run(in)
201
+	if err != nil {
202
+		t.Fatalf("unexpected error while running program: %v", err)
203
+	}
204
+	if want, got := len(in)-8, out; want != got {
205
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
206
+			want, got)
207
+	}
208
+}
209
+
210
+func testDHCPv4(t *testing.T) (virtualMachine, []byte, func()) {
211
+	// DHCPv4 test data courtesy of David Anderson:
212
+	// https://github.com/google/netboot/blob/master/dhcp4/conn_linux.go#L59-L70
213
+	vm, done, err := testVM(t, []bpf.Instruction{
214
+		// Load IPv4 packet length
215
+		bpf.LoadMemShift{Off: 8},
216
+		// Get UDP dport
217
+		bpf.LoadIndirect{Off: 8 + 2, Size: 2},
218
+		// Correct dport?
219
+		bpf.JumpIf{Cond: bpf.JumpEqual, Val: dhcp4Port, SkipFalse: 1},
220
+		// Accept
221
+		bpf.RetConstant{Val: 1500},
222
+		// Ignore
223
+		bpf.RetConstant{Val: 0},
224
+	})
225
+	if err != nil {
226
+		t.Fatalf("failed to load BPF program: %v", err)
227
+	}
228
+
229
+	// Minimal requirements to make a valid IPv4 header
230
+	h := &ipv4.Header{
231
+		Len: ipv4.HeaderLen,
232
+		Src: net.IPv4(192, 168, 1, 1),
233
+		Dst: net.IPv4(192, 168, 1, 2),
234
+	}
235
+	hb, err := h.Marshal()
236
+	if err != nil {
237
+		t.Fatalf("failed to marshal IPv4 header: %v", err)
238
+	}
239
+
240
+	hb = append([]byte{
241
+		0xff, 0xff, 0xff, 0xff,
242
+		0xff, 0xff, 0xff, 0xff,
243
+	}, hb...)
244
+
245
+	return vm, hb, done
246
+}

+ 115
- 0
vendor/golang.org/x/net/bpf/vm_ret_test.go View File

@@ -0,0 +1,115 @@
1
+// Copyright 2016 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package bpf_test
6
+
7
+import (
8
+	"testing"
9
+
10
+	"golang.org/x/net/bpf"
11
+)
12
+
13
+func TestVMRetA(t *testing.T) {
14
+	vm, done, err := testVM(t, []bpf.Instruction{
15
+		bpf.LoadAbsolute{
16
+			Off:  8,
17
+			Size: 1,
18
+		},
19
+		bpf.RetA{},
20
+	})
21
+	if err != nil {
22
+		t.Fatalf("failed to load BPF program: %v", err)
23
+	}
24
+	defer done()
25
+
26
+	out, err := vm.Run([]byte{
27
+		0xff, 0xff, 0xff, 0xff,
28
+		0xff, 0xff, 0xff, 0xff,
29
+		9,
30
+	})
31
+	if err != nil {
32
+		t.Fatalf("unexpected error while running program: %v", err)
33
+	}
34
+	if want, got := 1, out; want != got {
35
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
36
+			want, got)
37
+	}
38
+}
39
+
40
+func TestVMRetALargerThanInput(t *testing.T) {
41
+	vm, done, err := testVM(t, []bpf.Instruction{
42
+		bpf.LoadAbsolute{
43
+			Off:  8,
44
+			Size: 2,
45
+		},
46
+		bpf.RetA{},
47
+	})
48
+	if err != nil {
49
+		t.Fatalf("failed to load BPF program: %v", err)
50
+	}
51
+	defer done()
52
+
53
+	out, err := vm.Run([]byte{
54
+		0xff, 0xff, 0xff, 0xff,
55
+		0xff, 0xff, 0xff, 0xff,
56
+		0, 255,
57
+	})
58
+	if err != nil {
59
+		t.Fatalf("unexpected error while running program: %v", err)
60
+	}
61
+	if want, got := 2, out; want != got {
62
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
63
+			want, got)
64
+	}
65
+}
66
+
67
+func TestVMRetConstant(t *testing.T) {
68
+	vm, done, err := testVM(t, []bpf.Instruction{
69
+		bpf.RetConstant{
70
+			Val: 9,
71
+		},
72
+	})
73
+	if err != nil {
74
+		t.Fatalf("failed to load BPF program: %v", err)
75
+	}
76
+	defer done()
77
+
78
+	out, err := vm.Run([]byte{
79
+		0xff, 0xff, 0xff, 0xff,
80
+		0xff, 0xff, 0xff, 0xff,
81
+		0, 1,
82
+	})
83
+	if err != nil {
84
+		t.Fatalf("unexpected error while running program: %v", err)
85
+	}
86
+	if want, got := 1, out; want != got {
87
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
88
+			want, got)
89
+	}
90
+}
91
+
92
+func TestVMRetConstantLargerThanInput(t *testing.T) {
93
+	vm, done, err := testVM(t, []bpf.Instruction{
94
+		bpf.RetConstant{
95
+			Val: 16,
96
+		},
97
+	})
98
+	if err != nil {
99
+		t.Fatalf("failed to load BPF program: %v", err)
100
+	}
101
+	defer done()
102
+
103
+	out, err := vm.Run([]byte{
104
+		0xff, 0xff, 0xff, 0xff,
105
+		0xff, 0xff, 0xff, 0xff,
106
+		0, 1,
107
+	})
108
+	if err != nil {
109
+		t.Fatalf("unexpected error while running program: %v", err)
110
+	}
111
+	if want, got := 2, out; want != got {
112
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
113
+			want, got)
114
+	}
115
+}

+ 247
- 0
vendor/golang.org/x/net/bpf/vm_scratch_test.go View File

@@ -0,0 +1,247 @@
1
+// Copyright 2016 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package bpf_test
6
+
7
+import (
8
+	"testing"
9
+
10
+	"golang.org/x/net/bpf"
11
+)
12
+
13
+func TestVMStoreScratchInvalidScratchRegisterTooSmall(t *testing.T) {
14
+	_, _, err := testVM(t, []bpf.Instruction{
15
+		bpf.StoreScratch{
16
+			Src: bpf.RegA,
17
+			N:   -1,
18
+		},
19
+		bpf.RetA{},
20
+	})
21
+	if errStr(err) != "assembling instruction 1: invalid scratch slot -1" {
22
+		t.Fatalf("unexpected error: %v", err)
23
+	}
24
+}
25
+
26
+func TestVMStoreScratchInvalidScratchRegisterTooLarge(t *testing.T) {
27
+	_, _, err := testVM(t, []bpf.Instruction{
28
+		bpf.StoreScratch{
29
+			Src: bpf.RegA,
30
+			N:   16,
31
+		},
32
+		bpf.RetA{},
33
+	})
34
+	if errStr(err) != "assembling instruction 1: invalid scratch slot 16" {
35
+		t.Fatalf("unexpected error: %v", err)
36
+	}
37
+}
38
+
39
+func TestVMStoreScratchUnknownSourceRegister(t *testing.T) {
40
+	_, _, err := testVM(t, []bpf.Instruction{
41
+		bpf.StoreScratch{
42
+			Src: 100,
43
+			N:   0,
44
+		},
45
+		bpf.RetA{},
46
+	})
47
+	if errStr(err) != "assembling instruction 1: invalid source register 100" {
48
+		t.Fatalf("unexpected error: %v", err)
49
+	}
50
+}
51
+
52
+func TestVMLoadScratchInvalidScratchRegisterTooSmall(t *testing.T) {
53
+	_, _, err := testVM(t, []bpf.Instruction{
54
+		bpf.LoadScratch{
55
+			Dst: bpf.RegX,
56
+			N:   -1,
57
+		},
58
+		bpf.RetA{},
59
+	})
60
+	if errStr(err) != "assembling instruction 1: invalid scratch slot -1" {
61
+		t.Fatalf("unexpected error: %v", err)
62
+	}
63
+}
64
+
65
+func TestVMLoadScratchInvalidScratchRegisterTooLarge(t *testing.T) {
66
+	_, _, err := testVM(t, []bpf.Instruction{
67
+		bpf.LoadScratch{
68
+			Dst: bpf.RegX,
69
+			N:   16,
70
+		},
71
+		bpf.RetA{},
72
+	})
73
+	if errStr(err) != "assembling instruction 1: invalid scratch slot 16" {
74
+		t.Fatalf("unexpected error: %v", err)
75
+	}
76
+}
77
+
78
+func TestVMLoadScratchUnknownDestinationRegister(t *testing.T) {
79
+	_, _, err := testVM(t, []bpf.Instruction{
80
+		bpf.LoadScratch{
81
+			Dst: 100,
82
+			N:   0,
83
+		},
84
+		bpf.RetA{},
85
+	})
86
+	if errStr(err) != "assembling instruction 1: invalid target register 100" {
87
+		t.Fatalf("unexpected error: %v", err)
88
+	}
89
+}
90
+
91
+func TestVMStoreScratchLoadScratchOneValue(t *testing.T) {
92
+	vm, done, err := testVM(t, []bpf.Instruction{
93
+		// Load byte 255
94
+		bpf.LoadAbsolute{
95
+			Off:  8,
96
+			Size: 1,
97
+		},
98
+		// Copy to X and store in scratch[0]
99
+		bpf.TAX{},
100
+		bpf.StoreScratch{
101
+			Src: bpf.RegX,
102
+			N:   0,
103
+		},
104
+		// Load byte 1
105
+		bpf.LoadAbsolute{
106
+			Off:  9,
107
+			Size: 1,
108
+		},
109
+		// Overwrite 1 with 255 from scratch[0]
110
+		bpf.LoadScratch{
111
+			Dst: bpf.RegA,
112
+			N:   0,
113
+		},
114
+		// Return 255
115
+		bpf.RetA{},
116
+	})
117
+	if err != nil {
118
+		t.Fatalf("failed to load BPF program: %v", err)
119
+	}
120
+	defer done()
121
+
122
+	out, err := vm.Run([]byte{
123
+		0xff, 0xff, 0xff, 0xff,
124
+		0xff, 0xff, 0xff, 0xff,
125
+		255, 1, 2,
126
+	})
127
+	if err != nil {
128
+		t.Fatalf("unexpected error while running program: %v", err)
129
+	}
130
+	if want, got := 3, out; want != got {
131
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
132
+			want, got)
133
+	}
134
+}
135
+
136
+func TestVMStoreScratchLoadScratchMultipleValues(t *testing.T) {
137
+	vm, done, err := testVM(t, []bpf.Instruction{
138
+		// Load byte 10
139
+		bpf.LoadAbsolute{
140
+			Off:  8,
141
+			Size: 1,
142
+		},
143
+		// Store in scratch[0]
144
+		bpf.StoreScratch{
145
+			Src: bpf.RegA,
146
+			N:   0,
147
+		},
148
+		// Load byte 20
149
+		bpf.LoadAbsolute{
150
+			Off:  9,
151
+			Size: 1,
152
+		},
153
+		// Store in scratch[1]
154
+		bpf.StoreScratch{
155
+			Src: bpf.RegA,
156
+			N:   1,
157
+		},
158
+		// Load byte 30
159
+		bpf.LoadAbsolute{
160
+			Off:  10,
161
+			Size: 1,
162
+		},
163
+		// Store in scratch[2]
164
+		bpf.StoreScratch{
165
+			Src: bpf.RegA,
166
+			N:   2,
167
+		},
168
+		// Load byte 1
169
+		bpf.LoadAbsolute{
170
+			Off:  11,
171
+			Size: 1,
172
+		},
173
+		// Store in scratch[3]
174
+		bpf.StoreScratch{
175
+			Src: bpf.RegA,
176
+			N:   3,
177
+		},
178
+		// Load in byte 10 to X
179
+		bpf.LoadScratch{
180
+			Dst: bpf.RegX,
181
+			N:   0,
182
+		},
183
+		// Copy X -> A
184
+		bpf.TXA{},
185
+		// Verify value is 10
186
+		bpf.JumpIf{
187
+			Cond:     bpf.JumpEqual,
188
+			Val:      10,
189
+			SkipTrue: 1,
190
+		},
191
+		// Fail test if incorrect
192
+		bpf.RetConstant{
193
+			Val: 0,
194
+		},
195
+		// Load in byte 20 to A
196
+		bpf.LoadScratch{
197
+			Dst: bpf.RegA,
198
+			N:   1,
199
+		},
200
+		// Verify value is 20
201
+		bpf.JumpIf{
202
+			Cond:     bpf.JumpEqual,
203
+			Val:      20,
204
+			SkipTrue: 1,
205
+		},
206
+		// Fail test if incorrect
207
+		bpf.RetConstant{
208
+			Val: 0,
209
+		},
210
+		// Load in byte 30 to A
211
+		bpf.LoadScratch{
212
+			Dst: bpf.RegA,
213
+			N:   2,
214
+		},
215
+		// Verify value is 30
216
+		bpf.JumpIf{
217
+			Cond:     bpf.JumpEqual,
218
+			Val:      30,
219
+			SkipTrue: 1,
220
+		},
221
+		// Fail test if incorrect
222
+		bpf.RetConstant{
223
+			Val: 0,
224
+		},
225
+		// Return first two bytes on success
226
+		bpf.RetConstant{
227
+			Val: 10,
228
+		},
229
+	})
230
+	if err != nil {
231
+		t.Fatalf("failed to load BPF program: %v", err)
232
+	}
233
+	defer done()
234
+
235
+	out, err := vm.Run([]byte{
236
+		0xff, 0xff, 0xff, 0xff,
237
+		0xff, 0xff, 0xff, 0xff,
238
+		10, 20, 30, 1,
239
+	})
240
+	if err != nil {
241
+		t.Fatalf("unexpected error while running program: %v", err)
242
+	}
243
+	if want, got := 2, out; want != got {
244
+		t.Fatalf("unexpected number of output bytes:\n- want: %d\n-  got: %d",
245
+			want, got)
246
+	}
247
+}

+ 144
- 0
vendor/golang.org/x/net/bpf/vm_test.go View File

@@ -0,0 +1,144 @@
1
+// Copyright 2016 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package bpf_test
6
+
7
+import (
8
+	"fmt"
9
+	"testing"
10
+
11
+	"golang.org/x/net/bpf"
12
+)
13
+
14
+var _ bpf.Instruction = unknown{}
15
+
16
+type unknown struct{}
17
+
18
+func (unknown) Assemble() (bpf.RawInstruction, error) {
19
+	return bpf.RawInstruction{}, nil
20
+}
21
+
22
+func TestVMUnknownInstruction(t *testing.T) {
23
+	vm, done, err := testVM(t, []bpf.Instruction{
24
+		bpf.LoadConstant{
25
+			Dst: bpf.RegA,
26
+			Val: 100,
27
+		},
28
+		// Should terminate the program with an error immediately
29
+		unknown{},
30
+		bpf.RetA{},
31
+	})
32
+	if err != nil {
33
+		t.Fatalf("unexpected error: %v", err)
34
+	}
35
+	defer done()
36
+
37
+	_, err = vm.Run([]byte{
38
+		0xff, 0xff, 0xff, 0xff,
39
+		0xff, 0xff, 0xff, 0xff,
40
+		0x00, 0x00,
41
+	})
42
+	if errStr(err) != "unknown Instruction at index 1: bpf_test.unknown" {
43
+		t.Fatalf("unexpected error while running program: %v", err)
44
+	}
45
+}
46
+
47
+func TestVMNoReturnInstruction(t *testing.T) {
48
+	_, _, err := testVM(t, []bpf.Instruction{
49
+		bpf.LoadConstant{
50
+			Dst: bpf.RegA,
51
+			Val: 1,
52
+		},
53
+	})
54
+	if errStr(err) != "BPF program must end with RetA or RetConstant" {
55
+		t.Fatalf("unexpected error: %v", err)
56
+	}
57
+}
58
+
59
+func TestVMNoInputInstructions(t *testing.T) {
60
+	_, _, err := testVM(t, []bpf.Instruction{})
61
+	if errStr(err) != "one or more Instructions must be specified" {
62
+		t.Fatalf("unexpected error: %v", err)
63
+	}
64
+}
65
+
66
+// ExampleNewVM demonstrates usage of a VM, using an Ethernet frame
67
+// as input and checking its EtherType to determine if it should be accepted.
68
+func ExampleNewVM() {
69
+	// Offset | Length | Comment
70
+	// -------------------------
71
+	//   00   |   06   | Ethernet destination MAC address
72
+	//   06   |   06   | Ethernet source MAC address
73
+	//   12   |   02   | Ethernet EtherType
74
+	const (
75
+		etOff = 12
76
+		etLen = 2
77
+
78
+		etARP = 0x0806
79
+	)
80
+
81
+	// Set up a VM to filter traffic based on if its EtherType
82
+	// matches the ARP EtherType.
83
+	vm, err := bpf.NewVM([]bpf.Instruction{
84
+		// Load EtherType value from Ethernet header
85
+		bpf.LoadAbsolute{
86
+			Off:  etOff,
87
+			Size: etLen,
88
+		},
89
+		// If EtherType is equal to the ARP EtherType, jump to allow
90
+		// packet to be accepted
91
+		bpf.JumpIf{
92
+			Cond:     bpf.JumpEqual,
93
+			Val:      etARP,
94
+			SkipTrue: 1,
95
+		},
96
+		// EtherType does not match the ARP EtherType
97
+		bpf.RetConstant{
98
+			Val: 0,
99
+		},
100
+		// EtherType matches the ARP EtherType, accept up to 1500
101
+		// bytes of packet
102
+		bpf.RetConstant{
103
+			Val: 1500,
104
+		},
105
+	})
106
+	if err != nil {
107
+		panic(fmt.Sprintf("failed to load BPF program: %v", err))
108
+	}
109
+
110
+	// Create an Ethernet frame with the ARP EtherType for testing
111
+	frame := []byte{
112
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
113
+		0x00, 0x11, 0x22, 0x33, 0x44, 0x55,
114
+		0x08, 0x06,
115
+		// Payload omitted for brevity
116
+	}
117
+
118
+	// Run our VM's BPF program using the Ethernet frame as input
119
+	out, err := vm.Run(frame)
120
+	if err != nil {
121
+		panic(fmt.Sprintf("failed to accept Ethernet frame: %v", err))
122
+	}
123
+
124
+	// BPF VM can return a byte count greater than the number of input
125
+	// bytes, so trim the output to match the input byte length
126
+	if out > len(frame) {
127
+		out = len(frame)
128
+	}
129
+
130
+	fmt.Printf("out: %d bytes", out)
131
+
132
+	// Output:
133
+	// out: 14 bytes
134
+}
135
+
136
+// errStr returns the string representation of an error, or
137
+// "<nil>" if it is nil.
138
+func errStr(err error) string {
139
+	if err == nil {
140
+		return "<nil>"
141
+	}
142
+
143
+	return err.Error()
144
+}

+ 1
- 0
vendor/golang.org/x/net/codereview.cfg View File

@@ -0,0 +1 @@
1
+issuerepo: golang/go

+ 54
- 0
vendor/golang.org/x/net/context/context.go View File

@@ -0,0 +1,54 @@
1
+// Copyright 2014 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+// Package context defines the Context type, which carries deadlines,
6
+// cancelation signals, and other request-scoped values across API boundaries
7
+// and between processes.
8
+//
9
+// Incoming requests to a server should create a Context, and outgoing calls to
10
+// servers should accept a Context. The chain of function calls between must
11
+// propagate the Context, optionally replacing it with a modified copy created
12
+// using WithDeadline, WithTimeout, WithCancel, or WithValue.
13
+//
14
+// Programs that use Contexts should follow these rules to keep interfaces
15
+// consistent across packages and enable static analysis tools to check context
16
+// propagation:
17
+//
18
+// Do not store Contexts inside a struct type; instead, pass a Context
19
+// explicitly to each function that needs it. The Context should be the first
20
+// parameter, typically named ctx:
21
+//
22
+// 	func DoSomething(ctx context.Context, arg Arg) error {
23
+// 		// ... use ctx ...
24
+// 	}
25
+//
26
+// Do not pass a nil Context, even if a function permits it. Pass context.TODO
27
+// if you are unsure about which Context to use.
28
+//
29
+// Use context Values only for request-scoped data that transits processes and
30
+// APIs, not for passing optional parameters to functions.
31
+//
32
+// The same Context may be passed to functions running in different goroutines;
33
+// Contexts are safe for simultaneous use by multiple goroutines.
34
+//
35
+// See http://blog.golang.org/context for example code for a server that uses
36
+// Contexts.
37
+package context // import "golang.org/x/net/context"
38
+
39
+// Background returns a non-nil, empty Context. It is never canceled, has no
40
+// values, and has no deadline. It is typically used by the main function,
41
+// initialization, and tests, and as the top-level Context for incoming
42
+// requests.
43
+func Background() Context {
44
+	return background
45
+}
46
+
47
+// TODO returns a non-nil, empty Context. Code should use context.TODO when
48
+// it's unclear which Context to use or it is not yet available (because the
49
+// surrounding function has not yet been extended to accept a Context
50
+// parameter).  TODO is recognized by static analysis tools that determine
51
+// whether Contexts are propagated correctly in a program.
52
+func TODO() Context {
53
+	return todo
54
+}

+ 583
- 0
vendor/golang.org/x/net/context/context_test.go View File

@@ -0,0 +1,583 @@
1
+// Copyright 2014 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+// +build !go1.7
6
+
7
+package context
8
+
9
+import (
10
+	"fmt"
11
+	"math/rand"
12
+	"runtime"
13
+	"strings"
14
+	"sync"
15
+	"testing"
16
+	"time"
17
+)
18
+
19
+// otherContext is a Context that's not one of the types defined in context.go.
20
+// This lets us test code paths that differ based on the underlying type of the
21
+// Context.
22
+type otherContext struct {
23
+	Context
24
+}
25
+
26
+func TestBackground(t *testing.T) {
27
+	c := Background()
28
+	if c == nil {
29
+		t.Fatalf("Background returned nil")
30
+	}
31
+	select {
32
+	case x := <-c.Done():
33
+		t.Errorf("<-c.Done() == %v want nothing (it should block)", x)
34
+	default:
35
+	}
36
+	if got, want := fmt.Sprint(c), "context.Background"; got != want {
37
+		t.Errorf("Background().String() = %q want %q", got, want)
38
+	}
39
+}
40
+
41
+func TestTODO(t *testing.T) {
42
+	c := TODO()
43
+	if c == nil {
44
+		t.Fatalf("TODO returned nil")
45
+	}
46
+	select {
47
+	case x := <-c.Done():
48
+		t.Errorf("<-c.Done() == %v want nothing (it should block)", x)
49
+	default:
50
+	}
51
+	if got, want := fmt.Sprint(c), "context.TODO"; got != want {
52
+		t.Errorf("TODO().String() = %q want %q", got, want)
53
+	}
54
+}
55
+
56
+func TestWithCancel(t *testing.T) {
57
+	c1, cancel := WithCancel(Background())
58
+
59
+	if got, want := fmt.Sprint(c1), "context.Background.WithCancel"; got != want {
60
+		t.Errorf("c1.String() = %q want %q", got, want)
61
+	}
62
+
63
+	o := otherContext{c1}
64
+	c2, _ := WithCancel(o)
65
+	contexts := []Context{c1, o, c2}
66
+
67
+	for i, c := range contexts {
68
+		if d := c.Done(); d == nil {
69
+			t.Errorf("c[%d].Done() == %v want non-nil", i, d)
70
+		}
71
+		if e := c.Err(); e != nil {
72
+			t.Errorf("c[%d].Err() == %v want nil", i, e)
73
+		}
74
+
75
+		select {
76
+		case x := <-c.Done():
77
+			t.Errorf("<-c.Done() == %v want nothing (it should block)", x)
78
+		default:
79
+		}
80
+	}
81
+
82
+	cancel()
83
+	time.Sleep(100 * time.Millisecond) // let cancelation propagate
84
+
85
+	for i, c := range contexts {
86
+		select {
87
+		case <-c.Done():
88
+		default:
89
+			t.Errorf("<-c[%d].Done() blocked, but shouldn't have", i)
90
+		}
91
+		if e := c.Err(); e != Canceled {
92
+			t.Errorf("c[%d].Err() == %v want %v", i, e, Canceled)
93
+		}
94
+	}
95
+}
96
+
97
+func TestParentFinishesChild(t *testing.T) {
98
+	// Context tree:
99
+	// parent -> cancelChild
100
+	// parent -> valueChild -> timerChild
101
+	parent, cancel := WithCancel(Background())
102
+	cancelChild, stop := WithCancel(parent)
103
+	defer stop()
104
+	valueChild := WithValue(parent, "key", "value")
105
+	timerChild, stop := WithTimeout(valueChild, 10000*time.Hour)
106
+	defer stop()
107
+
108
+	select {
109
+	case x := <-parent.Done():
110
+		t.Errorf("<-parent.Done() == %v want nothing (it should block)", x)
111
+	case x := <-cancelChild.Done():
112
+		t.Errorf("<-cancelChild.Done() == %v want nothing (it should block)", x)
113
+	case x := <-timerChild.Done():
114
+		t.Errorf("<-timerChild.Done() == %v want nothing (it should block)", x)
115
+	case x := <-valueChild.Done():
116
+		t.Errorf("<-valueChild.Done() == %v want nothing (it should block)", x)
117
+	default:
118
+	}
119
+
120
+	// The parent's children should contain the two cancelable children.
121
+	pc := parent.(*cancelCtx)
122
+	cc := cancelChild.(*cancelCtx)
123
+	tc := timerChild.(*timerCtx)
124
+	pc.mu.Lock()
125
+	if len(pc.children) != 2 || !pc.children[cc] || !pc.children[tc] {
126
+		t.Errorf("bad linkage: pc.children = %v, want %v and %v",
127
+			pc.children, cc, tc)
128
+	}
129
+	pc.mu.Unlock()
130
+
131
+	if p, ok := parentCancelCtx(cc.Context); !ok || p != pc {
132
+		t.Errorf("bad linkage: parentCancelCtx(cancelChild.Context) = %v, %v want %v, true", p, ok, pc)
133
+	}
134
+	if p, ok := parentCancelCtx(tc.Context); !ok || p != pc {
135
+		t.Errorf("bad linkage: parentCancelCtx(timerChild.Context) = %v, %v want %v, true", p, ok, pc)
136
+	}
137
+
138
+	cancel()
139
+
140
+	pc.mu.Lock()
141
+	if len(pc.children) != 0 {
142
+		t.Errorf("pc.cancel didn't clear pc.children = %v", pc.children)
143
+	}
144
+	pc.mu.Unlock()
145
+
146
+	// parent and children should all be finished.
147
+	check := func(ctx Context, name string) {
148
+		select {
149
+		case <-ctx.Done():
150
+		default:
151
+			t.Errorf("<-%s.Done() blocked, but shouldn't have", name)
152
+		}
153
+		if e := ctx.Err(); e != Canceled {
154
+			t.Errorf("%s.Err() == %v want %v", name, e, Canceled)
155
+		}
156
+	}
157
+	check(parent, "parent")
158
+	check(cancelChild, "cancelChild")
159
+	check(valueChild, "valueChild")
160
+	check(timerChild, "timerChild")
161
+
162
+	// WithCancel should return a canceled context on a canceled parent.
163
+	precanceledChild := WithValue(parent, "key", "value")
164
+	select {
165
+	case <-precanceledChild.Done():
166
+	default:
167
+		t.Errorf("<-precanceledChild.Done() blocked, but shouldn't have")
168
+	}
169
+	if e := precanceledChild.Err(); e != Canceled {
170
+		t.Errorf("precanceledChild.Err() == %v want %v", e, Canceled)
171
+	}
172
+}
173
+
174
+func TestChildFinishesFirst(t *testing.T) {
175
+	cancelable, stop := WithCancel(Background())
176
+	defer stop()
177
+	for _, parent := range []Context{Background(), cancelable} {
178
+		child, cancel := WithCancel(parent)
179
+
180
+		select {
181
+		case x := <-parent.Done():
182
+			t.Errorf("<-parent.Done() == %v want nothing (it should block)", x)
183
+		case x := <-child.Done():
184
+			t.Errorf("<-child.Done() == %v want nothing (it should block)", x)
185
+		default:
186
+		}
187
+
188
+		cc := child.(*cancelCtx)
189
+		pc, pcok := parent.(*cancelCtx) // pcok == false when parent == Background()
190
+		if p, ok := parentCancelCtx(cc.Context); ok != pcok || (ok && pc != p) {
191
+			t.Errorf("bad linkage: parentCancelCtx(cc.Context) = %v, %v want %v, %v", p, ok, pc, pcok)
192
+		}
193
+
194
+		if pcok {
195
+			pc.mu.Lock()
196
+			if len(pc.children) != 1 || !pc.children[cc] {
197
+				t.Errorf("bad linkage: pc.children = %v, cc = %v", pc.children, cc)
198
+			}
199
+			pc.mu.Unlock()
200
+		}
201
+
202
+		cancel()
203
+
204
+		if pcok {
205
+			pc.mu.Lock()
206
+			if len(pc.children) != 0 {
207
+				t.Errorf("child's cancel didn't remove self from pc.children = %v", pc.children)
208
+			}
209
+			pc.mu.Unlock()
210
+		}
211
+
212
+		// child should be finished.
213
+		select {
214
+		case <-child.Done():
215
+		default:
216
+			t.Errorf("<-child.Done() blocked, but shouldn't have")
217
+		}
218
+		if e := child.Err(); e != Canceled {
219
+			t.Errorf("child.Err() == %v want %v", e, Canceled)
220
+		}
221
+
222
+		// parent should not be finished.
223
+		select {
224
+		case x := <-parent.Done():
225
+			t.Errorf("<-parent.Done() == %v want nothing (it should block)", x)
226
+		default:
227
+		}
228
+		if e := parent.Err(); e != nil {
229
+			t.Errorf("parent.Err() == %v want nil", e)
230
+		}
231
+	}
232
+}
233
+
234
+func testDeadline(c Context, wait time.Duration, t *testing.T) {
235
+	select {
236
+	case <-time.After(wait):
237
+		t.Fatalf("context should have timed out")
238
+	case <-c.Done():
239
+	}
240
+	if e := c.Err(); e != DeadlineExceeded {
241
+		t.Errorf("c.Err() == %v want %v", e, DeadlineExceeded)
242
+	}
243
+}
244
+
245
+func TestDeadline(t *testing.T) {
246
+	t.Parallel()
247
+	const timeUnit = 500 * time.Millisecond
248
+	c, _ := WithDeadline(Background(), time.Now().Add(1*timeUnit))
249
+	if got, prefix := fmt.Sprint(c), "context.Background.WithDeadline("; !strings.HasPrefix(got, prefix) {
250
+		t.Errorf("c.String() = %q want prefix %q", got, prefix)
251
+	}
252
+	testDeadline(c, 2*timeUnit, t)
253
+
254
+	c, _ = WithDeadline(Background(), time.Now().Add(1*timeUnit))
255
+	o := otherContext{c}
256
+	testDeadline(o, 2*timeUnit, t)
257
+
258
+	c, _ = WithDeadline(Background(), time.Now().Add(1*timeUnit))
259
+	o = otherContext{c}
260
+	c, _ = WithDeadline(o, time.Now().Add(3*timeUnit))
261
+	testDeadline(c, 2*timeUnit, t)
262
+}
263
+
264
+func TestTimeout(t *testing.T) {
265
+	t.Parallel()
266
+	const timeUnit = 500 * time.Millisecond
267
+	c, _ := WithTimeout(Background(), 1*timeUnit)
268
+	if got, prefix := fmt.Sprint(c), "context.Background.WithDeadline("; !strings.HasPrefix(got, prefix) {
269
+		t.Errorf("c.String() = %q want prefix %q", got, prefix)
270
+	}
271
+	testDeadline(c, 2*timeUnit, t)
272
+
273
+	c, _ = WithTimeout(Background(), 1*timeUnit)
274
+	o := otherContext{c}
275
+	testDeadline(o, 2*timeUnit, t)
276
+
277
+	c, _ = WithTimeout(Background(), 1*timeUnit)
278
+	o = otherContext{c}
279
+	c, _ = WithTimeout(o, 3*timeUnit)
280
+	testDeadline(c, 2*timeUnit, t)
281
+}
282
+
283
+func TestCanceledTimeout(t *testing.T) {
284
+	t.Parallel()
285
+	const timeUnit = 500 * time.Millisecond
286
+	c, _ := WithTimeout(Background(), 2*timeUnit)
287
+	o := otherContext{c}
288
+	c, cancel := WithTimeout(o, 4*timeUnit)
289
+	cancel()
290
+	time.Sleep(1 * timeUnit) // let cancelation propagate
291
+	select {
292
+	case <-c.Done():
293
+	default:
294
+		t.Errorf("<-c.Done() blocked, but shouldn't have")
295
+	}
296
+	if e := c.Err(); e != Canceled {
297
+		t.Errorf("c.Err() == %v want %v", e, Canceled)
298
+	}
299
+}
300
+
301
+type key1 int
302
+type key2 int
303
+
304
+var k1 = key1(1)
305
+var k2 = key2(1) // same int as k1, different type
306
+var k3 = key2(3) // same type as k2, different int
307
+
308
+func TestValues(t *testing.T) {
309
+	check := func(c Context, nm, v1, v2, v3 string) {
310
+		if v, ok := c.Value(k1).(string); ok == (len(v1) == 0) || v != v1 {
311
+			t.Errorf(`%s.Value(k1).(string) = %q, %t want %q, %t`, nm, v, ok, v1, len(v1) != 0)
312
+		}
313
+		if v, ok := c.Value(k2).(string); ok == (len(v2) == 0) || v != v2 {
314
+			t.Errorf(`%s.Value(k2).(string) = %q, %t want %q, %t`, nm, v, ok, v2, len(v2) != 0)
315
+		}
316
+		if v, ok := c.Value(k3).(string); ok == (len(v3) == 0) || v != v3 {
317
+			t.Errorf(`%s.Value(k3).(string) = %q, %t want %q, %t`, nm, v, ok, v3, len(v3) != 0)
318
+		}
319
+	}
320
+
321
+	c0 := Background()
322
+	check(c0, "c0", "", "", "")
323
+
324
+	c1 := WithValue(Background(), k1, "c1k1")
325
+	check(c1, "c1", "c1k1", "", "")
326
+
327
+	if got, want := fmt.Sprint(c1), `context.Background.WithValue(1, "c1k1")`; got != want {
328
+		t.Errorf("c.String() = %q want %q", got, want)
329
+	}
330
+
331
+	c2 := WithValue(c1, k2, "c2k2")
332
+	check(c2, "c2", "c1k1", "c2k2", "")
333
+
334
+	c3 := WithValue(c2, k3, "c3k3")
335
+	check(c3, "c2", "c1k1", "c2k2", "c3k3")
336
+
337
+	c4 := WithValue(c3, k1, nil)
338
+	check(c4, "c4", "", "c2k2", "c3k3")
339
+
340
+	o0 := otherContext{Background()}
341
+	check(o0, "o0", "", "", "")
342
+
343
+	o1 := otherContext{WithValue(Background(), k1, "c1k1")}
344
+	check(o1, "o1", "c1k1", "", "")
345
+
346
+	o2 := WithValue(o1, k2, "o2k2")
347
+	check(o2, "o2", "c1k1", "o2k2", "")
348
+
349
+	o3 := otherContext{c4}
350
+	check(o3, "o3", "", "c2k2", "c3k3")
351
+
352
+	o4 := WithValue(o3, k3, nil)
353
+	check(o4, "o4", "", "c2k2", "")
354
+}
355
+
356
+func TestAllocs(t *testing.T) {
357
+	bg := Background()
358
+	for _, test := range []struct {
359
+		desc       string
360
+		f          func()
361
+		limit      float64
362
+		gccgoLimit float64
363
+	}{
364
+		{
365
+			desc:       "Background()",
366
+			f:          func() { Background() },
367
+			limit:      0,
368
+			gccgoLimit: 0,
369
+		},
370
+		{
371
+			desc: fmt.Sprintf("WithValue(bg, %v, nil)", k1),
372
+			f: func() {
373
+				c := WithValue(bg, k1, nil)
374
+				c.Value(k1)
375
+			},
376
+			limit:      3,
377
+			gccgoLimit: 3,
378
+		},
379
+		{
380
+			desc: "WithTimeout(bg, 15*time.Millisecond)",
381
+			f: func() {
382
+				c, _ := WithTimeout(bg, 15*time.Millisecond)
383
+				<-c.Done()
384
+			},
385
+			limit:      8,
386
+			gccgoLimit: 16,
387
+		},
388
+		{
389
+			desc: "WithCancel(bg)",
390
+			f: func() {
391
+				c, cancel := WithCancel(bg)
392
+				cancel()
393
+				<-c.Done()
394
+			},
395
+			limit:      5,
396
+			gccgoLimit: 8,
397
+		},
398
+		{
399
+			desc: "WithTimeout(bg, 100*time.Millisecond)",
400
+			f: func() {
401
+				c, cancel := WithTimeout(bg, 100*time.Millisecond)
402
+				cancel()
403
+				<-c.Done()
404
+			},
405
+			limit:      8,
406
+			gccgoLimit: 25,
407
+		},
408
+	} {
409
+		limit := test.limit
410
+		if runtime.Compiler == "gccgo" {
411
+			// gccgo does not yet do escape analysis.
412
+			// TODO(iant): Remove this when gccgo does do escape analysis.
413
+			limit = test.gccgoLimit
414
+		}
415
+		if n := testing.AllocsPerRun(100, test.f); n > limit {
416
+			t.Errorf("%s allocs = %f want %d", test.desc, n, int(limit))
417
+		}
418
+	}
419
+}
420
+
421
+func TestSimultaneousCancels(t *testing.T) {
422
+	root, cancel := WithCancel(Background())
423
+	m := map[Context]CancelFunc{root: cancel}
424
+	q := []Context{root}
425
+	// Create a tree of contexts.
426
+	for len(q) != 0 && len(m) < 100 {
427
+		parent := q[0]
428
+		q = q[1:]
429
+		for i := 0; i < 4; i++ {
430
+			ctx, cancel := WithCancel(parent)
431
+			m[ctx] = cancel
432
+			q = append(q, ctx)
433
+		}
434
+	}
435
+	// Start all the cancels in a random order.
436
+	var wg sync.WaitGroup
437
+	wg.Add(len(m))
438
+	for _, cancel := range m {
439
+		go func(cancel CancelFunc) {
440
+			cancel()
441
+			wg.Done()
442
+		}(cancel)
443
+	}
444
+	// Wait on all the contexts in a random order.
445
+	for ctx := range m {
446
+		select {
447
+		case <-ctx.Done():
448
+		case <-time.After(1 * time.Second):
449
+			buf := make([]byte, 10<<10)
450
+			n := runtime.Stack(buf, true)
451
+			t.Fatalf("timed out waiting for <-ctx.Done(); stacks:\n%s", buf[:n])
452
+		}
453
+	}
454
+	// Wait for all the cancel functions to return.
455
+	done := make(chan struct{})
456
+	go func() {
457
+		wg.Wait()
458
+		close(done)
459
+	}()
460
+	select {
461
+	case <-done:
462
+	case <-time.After(1 * time.Second):
463
+		buf := make([]byte, 10<<10)
464
+		n := runtime.Stack(buf, true)
465
+		t.Fatalf("timed out waiting for cancel functions; stacks:\n%s", buf[:n])
466
+	}
467
+}
468
+
469
+func TestInterlockedCancels(t *testing.T) {
470
+	parent, cancelParent := WithCancel(Background())
471
+	child, cancelChild := WithCancel(parent)
472
+	go func() {
473
+		parent.Done()
474
+		cancelChild()
475
+	}()
476
+	cancelParent()
477
+	select {
478
+	case <-child.Done():
479
+	case <-time.After(1 * time.Second):
480
+		buf := make([]byte, 10<<10)
481
+		n := runtime.Stack(buf, true)
482
+		t.Fatalf("timed out waiting for child.Done(); stacks:\n%s", buf[:n])
483
+	}
484
+}
485
+
486
+func TestLayersCancel(t *testing.T) {
487
+	testLayers(t, time.Now().UnixNano(), false)
488
+}
489
+
490
+func TestLayersTimeout(t *testing.T) {
491
+	testLayers(t, time.Now().UnixNano(), true)
492
+}
493
+
494
+func testLayers(t *testing.T, seed int64, testTimeout bool) {
495
+	rand.Seed(seed)
496
+	errorf := func(format string, a ...interface{}) {
497
+		t.Errorf(fmt.Sprintf("seed=%d: %s", seed, format), a...)
498
+	}
499
+	const (
500
+		timeout   = 200 * time.Millisecond
501
+		minLayers = 30
502
+	)
503
+	type value int
504
+	var (
505
+		vals      []*value
506
+		cancels   []CancelFunc
507
+		numTimers int
508
+		ctx       = Background()
509
+	)
510
+	for i := 0; i < minLayers || numTimers == 0 || len(cancels) == 0 || len(vals) == 0; i++ {
511
+		switch rand.Intn(3) {
512
+		case 0:
513
+			v := new(value)
514
+			ctx = WithValue(ctx, v, v)
515
+			vals = append(vals, v)
516
+		case 1:
517
+			var cancel CancelFunc
518
+			ctx, cancel = WithCancel(ctx)
519
+			cancels = append(cancels, cancel)
520
+		case 2:
521
+			var cancel CancelFunc
522
+			ctx, cancel = WithTimeout(ctx, timeout)
523
+			cancels = append(cancels, cancel)
524
+			numTimers++
525
+		}
526
+	}
527
+	checkValues := func(when string) {
528
+		for _, key := range vals {
529
+			if val := ctx.Value(key).(*value); key != val {
530
+				errorf("%s: ctx.Value(%p) = %p want %p", when, key, val, key)
531
+			}
532
+		}
533
+	}
534
+	select {
535
+	case <-ctx.Done():
536
+		errorf("ctx should not be canceled yet")
537
+	default:
538
+	}
539
+	if s, prefix := fmt.Sprint(ctx), "context.Background."; !strings.HasPrefix(s, prefix) {
540
+		t.Errorf("ctx.String() = %q want prefix %q", s, prefix)
541
+	}
542
+	t.Log(ctx)
543
+	checkValues("before cancel")
544
+	if testTimeout {
545
+		select {
546
+		case <-ctx.Done():
547
+		case <-time.After(timeout + 100*time.Millisecond):
548
+			errorf("ctx should have timed out")
549
+		}
550
+		checkValues("after timeout")
551
+	} else {
552
+		cancel := cancels[rand.Intn(len(cancels))]
553
+		cancel()
554
+		select {
555
+		case <-ctx.Done():
556
+		default:
557
+			errorf("ctx should be canceled")
558
+		}
559
+		checkValues("after cancel")
560
+	}
561
+}
562
+
563
+func TestCancelRemoves(t *testing.T) {
564
+	checkChildren := func(when string, ctx Context, want int) {
565
+		if got := len(ctx.(*cancelCtx).children); got != want {
566
+			t.Errorf("%s: context has %d children, want %d", when, got, want)
567
+		}
568
+	}
569
+
570
+	ctx, _ := WithCancel(Background())
571
+	checkChildren("after creation", ctx, 0)
572
+	_, cancel := WithCancel(ctx)
573
+	checkChildren("with WithCancel child ", ctx, 1)
574
+	cancel()
575
+	checkChildren("after cancelling WithCancel child", ctx, 0)
576
+
577
+	ctx, _ = WithCancel(Background())
578
+	checkChildren("after creation", ctx, 0)
579
+	_, cancel = WithTimeout(ctx, 60*time.Minute)
580
+	checkChildren("with WithTimeout child ", ctx, 1)
581
+	cancel()
582
+	checkChildren("after cancelling WithTimeout child", ctx, 0)
583
+}

+ 74
- 0
vendor/golang.org/x/net/context/ctxhttp/ctxhttp.go View File

@@ -0,0 +1,74 @@
1
+// Copyright 2016 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+// +build go1.7
6
+
7
+// Package ctxhttp provides helper functions for performing context-aware HTTP requests.
8
+package ctxhttp // import "golang.org/x/net/context/ctxhttp"
9
+
10
+import (
11
+	"io"
12
+	"net/http"
13
+	"net/url"
14
+	"strings"
15
+
16
+	"golang.org/x/net/context"
17
+)
18
+
19
+// Do sends an HTTP request with the provided http.Client and returns
20
+// an HTTP response.
21
+//
22
+// If the client is nil, http.DefaultClient is used.
23
+//
24
+// The provided ctx must be non-nil. If it is canceled or times out,
25
+// ctx.Err() will be returned.
26
+func Do(ctx context.Context, client *http.Client, req *http.Request) (*http.Response, error) {
27
+	if client == nil {
28
+		client = http.DefaultClient
29
+	}
30
+	resp, err := client.Do(req.WithContext(ctx))
31
+	// If we got an error, and the context has been canceled,
32
+	// the context's error is probably more useful.
33
+	if err != nil {
34
+		select {
35
+		case <-ctx.Done():
36
+			err = ctx.Err()
37
+		default:
38
+		}
39
+	}
40
+	return resp, err
41
+}
42
+
43
+// Get issues a GET request via the Do function.
44
+func Get(ctx context.Context, client *http.Client, url string) (*http.Response, error) {
45
+	req, err := http.NewRequest("GET", url, nil)
46
+	if err != nil {
47
+		return nil, err
48
+	}
49
+	return Do(ctx, client, req)
50
+}
51
+
52
+// Head issues a HEAD request via the Do function.
53
+func Head(ctx context.Context, client *http.Client, url string) (*http.Response, error) {
54
+	req, err := http.NewRequest("HEAD", url, nil)
55
+	if err != nil {
56
+		return nil, err
57
+	}
58
+	return Do(ctx, client, req)
59
+}
60
+
61
+// Post issues a POST request via the Do function.
62
+func Post(ctx context.Context, client *http.Client, url string, bodyType string, body io.Reader) (*http.Response, error) {
63
+	req, err := http.NewRequest("POST", url, body)
64
+	if err != nil {
65
+		return nil, err
66
+	}
67
+	req.Header.Set("Content-Type", bodyType)
68
+	return Do(ctx, client, req)
69
+}
70
+
71
+// PostForm issues a POST request via the Do function.
72
+func PostForm(ctx context.Context, client *http.Client, url string, data url.Values) (*http.Response, error) {
73
+	return Post(ctx, client, url, "application/x-www-form-urlencoded", strings.NewReader(data.Encode()))
74
+}

+ 29
- 0
vendor/golang.org/x/net/context/ctxhttp/ctxhttp_17_test.go View File

@@ -0,0 +1,29 @@
1
+// Copyright 2015 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+// +build !plan9,go1.7
6
+
7
+package ctxhttp
8
+
9
+import (
10
+	"io"
11
+	"net/http"
12
+	"net/http/httptest"
13
+	"testing"
14
+
15
+	"context"
16
+)
17
+
18
+func TestGo17Context(t *testing.T) {
19
+	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
20
+		io.WriteString(w, "ok")
21
+	}))
22
+	defer ts.Close()
23
+	ctx := context.Background()
24
+	resp, err := Get(ctx, http.DefaultClient, ts.URL)
25
+	if resp == nil || err != nil {
26
+		t.Fatalf("error received from client: %v %v", err, resp)
27
+	}
28
+	resp.Body.Close()
29
+}

+ 147
- 0
vendor/golang.org/x/net/context/ctxhttp/ctxhttp_pre17.go View File

@@ -0,0 +1,147 @@
1
+// Copyright 2015 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+// +build !go1.7
6
+
7
+package ctxhttp // import "golang.org/x/net/context/ctxhttp"
8
+
9
+import (
10
+	"io"
11
+	"net/http"
12
+	"net/url"
13
+	"strings"
14
+
15
+	"golang.org/x/net/context"
16
+)
17
+
18
+func nop() {}
19
+
20
+var (
21
+	testHookContextDoneBeforeHeaders = nop
22
+	testHookDoReturned               = nop
23
+	testHookDidBodyClose             = nop
24
+)
25
+
26
+// Do sends an HTTP request with the provided http.Client and returns an HTTP response.
27
+// If the client is nil, http.DefaultClient is used.
28
+// If the context is canceled or times out, ctx.Err() will be returned.
29
+func Do(ctx context.Context, client *http.Client, req *http.Request) (*http.Response, error) {
30
+	if client == nil {
31
+		client = http.DefaultClient
32
+	}
33
+
34
+	// TODO(djd): Respect any existing value of req.Cancel.
35
+	cancel := make(chan struct{})
36
+	req.Cancel = cancel
37
+
38
+	type responseAndError struct {
39
+		resp *http.Response
40
+		err  error
41
+	}
42
+	result := make(chan responseAndError, 1)
43
+
44
+	// Make local copies of test hooks closed over by goroutines below.
45
+	// Prevents data races in tests.
46
+	testHookDoReturned := testHookDoReturned
47
+	testHookDidBodyClose := testHookDidBodyClose
48
+
49
+	go func() {
50
+		resp, err := client.Do(req)
51
+		testHookDoReturned()
52
+		result <- responseAndError{resp, err}
53
+	}()
54
+
55
+	var resp *http.Response
56
+
57
+	select {
58
+	case <-ctx.Done():
59
+		testHookContextDoneBeforeHeaders()
60
+		close(cancel)
61
+		// Clean up after the goroutine calling client.Do:
62
+		go func() {
63
+			if r := <-result; r.resp != nil {
64
+				testHookDidBodyClose()
65
+				r.resp.Body.Close()
66
+			}
67
+		}()
68
+		return nil, ctx.Err()
69
+	case r := <-result:
70
+		var err error
71
+		resp, err = r.resp, r.err
72
+		if err != nil {
73
+			return resp, err
74
+		}
75
+	}
76
+
77
+	c := make(chan struct{})
78
+	go func() {
79
+		select {
80
+		case <-ctx.Done():
81
+			close(cancel)
82
+		case <-c:
83
+			// The response's Body is closed.
84
+		}
85
+	}()
86
+	resp.Body = &notifyingReader{resp.Body, c}
87
+
88
+	return resp, nil
89
+}
90
+
91
+// Get issues a GET request via the Do function.
92
+func Get(ctx context.Context, client *http.Client, url string) (*http.Response, error) {
93
+	req, err := http.NewRequest("GET", url, nil)
94
+	if err != nil {
95
+		return nil, err
96
+	}
97
+	return Do(ctx, client, req)
98
+}
99
+
100
+// Head issues a HEAD request via the Do function.
101
+func Head(ctx context.Context, client *http.Client, url string) (*http.Response, error) {
102
+	req, err := http.NewRequest("HEAD", url, nil)
103
+	if err != nil {
104
+		return nil, err
105
+	}
106
+	return Do(ctx, client, req)
107
+}
108
+
109
+// Post issues a POST request via the Do function.
110
+func Post(ctx context.Context, client *http.Client, url string, bodyType string, body io.Reader) (*http.Response, error) {
111
+	req, err := http.NewRequest("POST", url, body)
112
+	if err != nil {
113
+		return nil, err
114
+	}
115
+	req.Header.Set("Content-Type", bodyType)
116
+	return Do(ctx, client, req)
117
+}
118
+
119
+// PostForm issues a POST request via the Do function.
120
+func PostForm(ctx context.Context, client *http.Client, url string, data url.Values) (*http.Response, error) {
121
+	return Post(ctx, client, url, "application/x-www-form-urlencoded", strings.NewReader(data.Encode()))
122
+}
123
+
124
+// notifyingReader is an io.ReadCloser that closes the notify channel after
125
+// Close is called or a Read fails on the underlying ReadCloser.
126
+type notifyingReader struct {
127
+	io.ReadCloser
128
+	notify chan<- struct{}
129
+}
130
+
131
+func (r *notifyingReader) Read(p []byte) (int, error) {
132
+	n, err := r.ReadCloser.Read(p)
133
+	if err != nil && r.notify != nil {
134
+		close(r.notify)
135
+		r.notify = nil
136
+	}
137
+	return n, err
138
+}
139
+
140
+func (r *notifyingReader) Close() error {
141
+	err := r.ReadCloser.Close()
142
+	if r.notify != nil {
143
+		close(r.notify)
144
+		r.notify = nil
145
+	}
146
+	return err
147
+}

+ 79
- 0
vendor/golang.org/x/net/context/ctxhttp/ctxhttp_pre17_test.go View File

@@ -0,0 +1,79 @@
1
+// Copyright 2015 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+// +build !plan9,!go1.7
6
+
7
+package ctxhttp
8
+
9
+import (
10
+	"net"
11
+	"net/http"
12
+	"net/http/httptest"
13
+	"sync"
14
+	"testing"
15
+	"time"
16
+
17
+	"golang.org/x/net/context"
18
+)
19
+
20
+// golang.org/issue/14065
21
+func TestClosesResponseBodyOnCancel(t *testing.T) {
22
+	defer func() { testHookContextDoneBeforeHeaders = nop }()
23
+	defer func() { testHookDoReturned = nop }()
24
+	defer func() { testHookDidBodyClose = nop }()
25
+
26
+	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
27
+	defer ts.Close()
28
+
29
+	ctx, cancel := context.WithCancel(context.Background())
30
+
31
+	// closed when Do enters select case <-ctx.Done()
32
+	enteredDonePath := make(chan struct{})
33
+
34
+	testHookContextDoneBeforeHeaders = func() {
35
+		close(enteredDonePath)
36
+	}
37
+
38
+	testHookDoReturned = func() {
39
+		// We now have the result (the Flush'd headers) at least,
40
+		// so we can cancel the request.
41
+		cancel()
42
+
43
+		// But block the client.Do goroutine from sending
44
+		// until Do enters into the <-ctx.Done() path, since
45
+		// otherwise if both channels are readable, select
46
+		// picks a random one.
47
+		<-enteredDonePath
48
+	}
49
+
50
+	sawBodyClose := make(chan struct{})
51
+	testHookDidBodyClose = func() { close(sawBodyClose) }
52
+
53
+	tr := &http.Transport{}
54
+	defer tr.CloseIdleConnections()
55
+	c := &http.Client{Transport: tr}
56
+	req, _ := http.NewRequest("GET", ts.URL, nil)
57
+	_, doErr := Do(ctx, c, req)
58
+
59
+	select {
60
+	case <-sawBodyClose:
61
+	case <-time.After(5 * time.Second):
62
+		t.Fatal("timeout waiting for body to close")
63
+	}
64
+
65
+	if doErr != ctx.Err() {
66
+		t.Errorf("Do error = %v; want %v", doErr, ctx.Err())
67
+	}
68
+}
69
+
70
+type noteCloseConn struct {
71
+	net.Conn
72
+	onceClose sync.Once
73
+	closefn   func()
74
+}
75
+
76
+func (c *noteCloseConn) Close() error {
77
+	c.onceClose.Do(c.closefn)
78
+	return c.Conn.Close()
79
+}

+ 105
- 0
vendor/golang.org/x/net/context/ctxhttp/ctxhttp_test.go View File

@@ -0,0 +1,105 @@
1
+// Copyright 2015 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+// +build !plan9
6
+
7
+package ctxhttp
8
+
9
+import (
10
+	"io"
11
+	"io/ioutil"
12
+	"net/http"
13
+	"net/http/httptest"
14
+	"testing"
15
+	"time"
16
+
17
+	"golang.org/x/net/context"
18
+)
19
+
20
+const (
21
+	requestDuration = 100 * time.Millisecond
22
+	requestBody     = "ok"
23
+)
24
+
25
+func okHandler(w http.ResponseWriter, r *http.Request) {
26
+	time.Sleep(requestDuration)
27
+	io.WriteString(w, requestBody)
28
+}
29
+
30
+func TestNoTimeout(t *testing.T) {
31
+	ts := httptest.NewServer(http.HandlerFunc(okHandler))
32
+	defer ts.Close()
33
+
34
+	ctx := context.Background()
35
+	res, err := Get(ctx, nil, ts.URL)
36
+	if err != nil {
37
+		t.Fatal(err)
38
+	}
39
+	defer res.Body.Close()
40
+	slurp, err := ioutil.ReadAll(res.Body)
41
+	if err != nil {
42
+		t.Fatal(err)
43
+	}
44
+	if string(slurp) != requestBody {
45
+		t.Errorf("body = %q; want %q", slurp, requestBody)
46
+	}
47
+}
48
+
49
+func TestCancelBeforeHeaders(t *testing.T) {
50
+	ctx, cancel := context.WithCancel(context.Background())
51
+
52
+	blockServer := make(chan struct{})
53
+	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
54
+		cancel()
55
+		<-blockServer
56
+		io.WriteString(w, requestBody)
57
+	}))
58
+	defer ts.Close()
59
+	defer close(blockServer)
60
+
61
+	res, err := Get(ctx, nil, ts.URL)
62
+	if err == nil {
63
+		res.Body.Close()
64
+		t.Fatal("Get returned unexpected nil error")
65
+	}
66
+	if err != context.Canceled {
67
+		t.Errorf("err = %v; want %v", err, context.Canceled)
68
+	}
69
+}
70
+
71
+func TestCancelAfterHangingRequest(t *testing.T) {
72
+	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
73
+		w.WriteHeader(http.StatusOK)
74
+		w.(http.Flusher).Flush()
75
+		<-w.(http.CloseNotifier).CloseNotify()
76
+	}))
77
+	defer ts.Close()
78
+
79
+	ctx, cancel := context.WithCancel(context.Background())
80
+	resp, err := Get(ctx, nil, ts.URL)
81
+	if err != nil {
82
+		t.Fatalf("unexpected error in Get: %v", err)
83
+	}
84
+
85
+	// Cancel befer reading the body.
86
+	// Reading Request.Body should fail, since the request was
87
+	// canceled before anything was written.
88
+	cancel()
89
+
90
+	done := make(chan struct{})
91
+
92
+	go func() {
93
+		b, err := ioutil.ReadAll(resp.Body)
94
+		if len(b) != 0 || err == nil {
95
+			t.Errorf(`Read got (%q, %v); want ("", error)`, b, err)
96
+		}
97
+		close(done)
98
+	}()
99
+
100
+	select {
101
+	case <-time.After(1 * time.Second):
102
+		t.Errorf("Test timed out")
103
+	case <-done:
104
+	}
105
+}

+ 72
- 0
vendor/golang.org/x/net/context/go17.go View File

@@ -0,0 +1,72 @@
1
+// Copyright 2016 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+// +build go1.7
6
+
7
+package context
8
+
9
+import (
10
+	"context" // standard library's context, as of Go 1.7
11
+	"time"
12
+)
13
+
14
+var (
15
+	todo       = context.TODO()
16
+	background = context.Background()
17
+)
18
+
19
+// Canceled is the error returned by Context.Err when the context is canceled.
20
+var Canceled = context.Canceled
21
+
22
+// DeadlineExceeded is the error returned by Context.Err when the context's
23
+// deadline passes.
24
+var DeadlineExceeded = context.DeadlineExceeded
25
+
26
+// WithCancel returns a copy of parent with a new Done channel. The returned
27
+// context's Done channel is closed when the returned cancel function is called
28
+// or when the parent context's Done channel is closed, whichever happens first.
29
+//
30
+// Canceling this context releases resources associated with it, so code should
31
+// call cancel as soon as the operations running in this Context complete.
32
+func WithCancel(parent Context) (ctx Context, cancel CancelFunc) {
33
+	ctx, f := context.WithCancel(parent)
34
+	return ctx, CancelFunc(f)
35
+}
36
+
37
+// WithDeadline returns a copy of the parent context with the deadline adjusted
38
+// to be no later than d. If the parent's deadline is already earlier than d,
39
+// WithDeadline(parent, d) is semantically equivalent to parent. The returned
40
+// context's Done channel is closed when the deadline expires, when the returned
41
+// cancel function is called, or when the parent context's Done channel is
42
+// closed, whichever happens first.
43
+//
44
+// Canceling this context releases resources associated with it, so code should
45
+// call cancel as soon as the operations running in this Context complete.
46
+func WithDeadline(parent Context, deadline time.Time) (Context, CancelFunc) {
47
+	ctx, f := context.WithDeadline(parent, deadline)
48
+	return ctx, CancelFunc(f)
49
+}
50
+
51
+// WithTimeout returns WithDeadline(parent, time.Now().Add(timeout)).
52
+//
53
+// Canceling this context releases resources associated with it, so code should
54
+// call cancel as soon as the operations running in this Context complete:
55
+//
56
+// 	func slowOperationWithTimeout(ctx context.Context) (Result, error) {
57
+// 		ctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
58
+// 		defer cancel()  // releases resources if slowOperation completes before timeout elapses
59
+// 		return slowOperation(ctx)
60
+// 	}
61
+func WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc) {
62
+	return WithDeadline(parent, time.Now().Add(timeout))
63
+}
64
+
65
+// WithValue returns a copy of parent in which the value associated with key is
66
+// val.
67
+//
68
+// Use context Values only for request-scoped data that transits processes and
69
+// APIs, not for passing optional parameters to functions.
70
+func WithValue(parent Context, key interface{}, val interface{}) Context {
71
+	return context.WithValue(parent, key, val)
72
+}

+ 20
- 0
vendor/golang.org/x/net/context/go19.go View File

@@ -0,0 +1,20 @@
1
+// Copyright 2017 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+// +build go1.9
6
+
7
+package context
8
+
9
+import "context" // standard library's context, as of Go 1.7
10
+
11
+// A Context carries a deadline, a cancelation signal, and other values across
12
+// API boundaries.
13
+//
14
+// Context's methods may be called by multiple goroutines simultaneously.
15
+type Context = context.Context
16
+
17
+// A CancelFunc tells an operation to abandon its work.
18
+// A CancelFunc does not wait for the work to stop.
19
+// After the first call, subsequent calls to a CancelFunc do nothing.
20
+type CancelFunc = context.CancelFunc

+ 300
- 0
vendor/golang.org/x/net/context/pre_go17.go View File

@@ -0,0 +1,300 @@
1
+// Copyright 2014 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+// +build !go1.7
6
+
7
+package context
8
+
9
+import (
10
+	"errors"
11
+	"fmt"
12
+	"sync"
13
+	"time"
14
+)
15
+
16
+// An emptyCtx is never canceled, has no values, and has no deadline. It is not
17
+// struct{}, since vars of this type must have distinct addresses.
18
+type emptyCtx int
19
+
20
+func (*emptyCtx) Deadline() (deadline time.Time, ok bool) {
21
+	return
22
+}
23
+
24
+func (*emptyCtx) Done() <-chan struct{} {
25
+	return nil
26
+}
27
+
28
+func (*emptyCtx) Err() error {
29
+	return nil
30
+}
31
+
32
+func (*emptyCtx) Value(key interface{}) interface{} {
33
+	return nil
34
+}
35
+
36
+func (e *emptyCtx) String() string {
37
+	switch e {
38
+	case background:
39
+		return "context.Background"
40
+	case todo:
41
+		return "context.TODO"
42
+	}
43
+	return "unknown empty Context"
44
+}
45
+
46
+var (
47
+	background = new(emptyCtx)
48
+	todo       = new(emptyCtx)
49
+)
50
+
51
+// Canceled is the error returned by Context.Err when the context is canceled.
52
+var Canceled = errors.New("context canceled")
53
+
54
+// DeadlineExceeded is the error returned by Context.Err when the context's
55
+// deadline passes.
56
+var DeadlineExceeded = errors.New("context deadline exceeded")
57
+
58
+// WithCancel returns a copy of parent with a new Done channel. The returned
59
+// context's Done channel is closed when the returned cancel function is called
60
+// or when the parent context's Done channel is closed, whichever happens first.
61
+//
62
+// Canceling this context releases resources associated with it, so code should
63
+// call cancel as soon as the operations running in this Context complete.
64
+func WithCancel(parent Context) (ctx Context, cancel CancelFunc) {
65
+	c := newCancelCtx(parent)
66
+	propagateCancel(parent, c)
67
+	return c, func() { c.cancel(true, Canceled) }
68
+}
69
+
70
+// newCancelCtx returns an initialized cancelCtx.
71
+func newCancelCtx(parent Context) *cancelCtx {
72
+	return &cancelCtx{
73
+		Context: parent,
74
+		done:    make(chan struct{}),
75
+	}
76
+}
77
+
78
+// propagateCancel arranges for child to be canceled when parent is.
79
+func propagateCancel(parent Context, child canceler) {
80
+	if parent.Done() == nil {
81
+		return // parent is never canceled
82
+	}
83
+	if p, ok := parentCancelCtx(parent); ok {
84
+		p.mu.Lock()
85
+		if p.err != nil {
86
+			// parent has already been canceled
87
+			child.cancel(false, p.err)
88
+		} else {
89
+			if p.children == nil {
90
+				p.children = make(map[canceler]bool)
91
+			}
92
+			p.children[child] = true
93
+		}
94
+		p.mu.Unlock()
95
+	} else {
96
+		go func() {
97
+			select {
98
+			case <-parent.Done():
99
+				child.cancel(false, parent.Err())
100
+			case <-child.Done():
101
+			}
102
+		}()
103
+	}
104
+}
105
+
106
+// parentCancelCtx follows a chain of parent references until it finds a
107
+// *cancelCtx. This function understands how each of the concrete types in this
108
+// package represents its parent.
109
+func parentCancelCtx(parent Context) (*cancelCtx, bool) {
110
+	for {
111
+		switch c := parent.(type) {
112
+		case *cancelCtx:
113
+			return c, true
114
+		case *timerCtx:
115
+			return c.cancelCtx, true
116
+		case *valueCtx:
117
+			parent = c.Context
118
+		default:
119
+			return nil, false
120
+		}
121
+	}
122
+}
123
+
124
+// removeChild removes a context from its parent.
125
+func removeChild(parent Context, child canceler) {
126
+	p, ok := parentCancelCtx(parent)
127
+	if !ok {
128
+		return
129
+	}
130
+	p.mu.Lock()
131
+	if p.children != nil {
132
+		delete(p.children, child)
133
+	}
134
+	p.mu.Unlock()
135
+}
136
+
137
+// A canceler is a context type that can be canceled directly. The
138
+// implementations are *cancelCtx and *timerCtx.
139
+type canceler interface {
140
+	cancel(removeFromParent bool, err error)
141
+	Done() <-chan struct{}
142
+}
143
+
144
+// A cancelCtx can be canceled. When canceled, it also cancels any children
145
+// that implement canceler.
146
+type cancelCtx struct {
147
+	Context
148
+
149
+	done chan struct{} // closed by the first cancel call.
150
+
151
+	mu       sync.Mutex
152
+	children map[canceler]bool // set to nil by the first cancel call
153
+	err      error             // set to non-nil by the first cancel call
154
+}
155
+
156
+func (c *cancelCtx) Done() <-chan struct{} {
157
+	return c.done
158
+}
159
+
160
+func (c *cancelCtx) Err() error {
161
+	c.mu.Lock()
162
+	defer c.mu.Unlock()
163
+	return c.err
164
+}
165
+
166
+func (c *cancelCtx) String() string {
167
+	return fmt.Sprintf("%v.WithCancel", c.Context)
168
+}
169
+
170
+// cancel closes c.done, cancels each of c's children, and, if
171
+// removeFromParent is true, removes c from its parent's children.
172
+func (c *cancelCtx) cancel(removeFromParent bool, err error) {
173
+	if err == nil {
174
+		panic("context: internal error: missing cancel error")
175
+	}
176
+	c.mu.Lock()
177
+	if c.err != nil {
178
+		c.mu.Unlock()
179
+		return // already canceled
180
+	}
181
+	c.err = err
182
+	close(c.done)
183
+	for child := range c.children {
184
+		// NOTE: acquiring the child's lock while holding parent's lock.
185
+		child.cancel(false, err)
186
+	}
187
+	c.children = nil
188
+	c.mu.Unlock()
189
+
190
+	if removeFromParent {
191
+		removeChild(c.Context, c)
192
+	}
193
+}
194
+
195
+// WithDeadline returns a copy of the parent context with the deadline adjusted
196
+// to be no later than d. If the parent's deadline is already earlier than d,
197
+// WithDeadline(parent, d) is semantically equivalent to parent. The returned
198
+// context's Done channel is closed when the deadline expires, when the returned
199
+// cancel function is called, or when the parent context's Done channel is
200
+// closed, whichever happens first.
201
+//
202
+// Canceling this context releases resources associated with it, so code should
203
+// call cancel as soon as the operations running in this Context complete.
204
+func WithDeadline(parent Context, deadline time.Time) (Context, CancelFunc) {
205
+	if cur, ok := parent.Deadline(); ok && cur.Before(deadline) {
206
+		// The current deadline is already sooner than the new one.
207
+		return WithCancel(parent)
208
+	}
209
+	c := &timerCtx{
210
+		cancelCtx: newCancelCtx(parent),
211
+		deadline:  deadline,
212
+	}
213
+	propagateCancel(parent, c)
214
+	d := deadline.Sub(time.Now())
215
+	if d <= 0 {
216
+		c.cancel(true, DeadlineExceeded) // deadline has already passed
217
+		return c, func() { c.cancel(true, Canceled) }
218
+	}
219
+	c.mu.Lock()
220
+	defer c.mu.Unlock()
221
+	if c.err == nil {
222
+		c.timer = time.AfterFunc(d, func() {
223
+			c.cancel(true, DeadlineExceeded)
224
+		})
225
+	}
226
+	return c, func() { c.cancel(true, Canceled) }
227
+}
228
+
229
+// A timerCtx carries a timer and a deadline. It embeds a cancelCtx to
230
+// implement Done and Err. It implements cancel by stopping its timer then
231
+// delegating to cancelCtx.cancel.
232
+type timerCtx struct {
233
+	*cancelCtx
234
+	timer *time.Timer // Under cancelCtx.mu.
235
+
236
+	deadline time.Time
237
+}
238
+
239
+func (c *timerCtx) Deadline() (deadline time.Time, ok bool) {
240
+	return c.deadline, true
241
+}
242
+
243
+func (c *timerCtx) String() string {
244
+	return fmt.Sprintf("%v.WithDeadline(%s [%s])", c.cancelCtx.Context, c.deadline, c.deadline.Sub(time.Now()))
245
+}
246
+
247
+func (c *timerCtx) cancel(removeFromParent bool, err error) {
248
+	c.cancelCtx.cancel(false, err)
249
+	if removeFromParent {
250
+		// Remove this timerCtx from its parent cancelCtx's children.
251
+		removeChild(c.cancelCtx.Context, c)
252
+	}
253
+	c.mu.Lock()
254
+	if c.timer != nil {
255
+		c.timer.Stop()
256
+		c.timer = nil
257
+	}
258
+	c.mu.Unlock()
259
+}
260
+
261
+// WithTimeout returns WithDeadline(parent, time.Now().Add(timeout)).
262
+//
263
+// Canceling this context releases resources associated with it, so code should
264
+// call cancel as soon as the operations running in this Context complete:
265
+//
266
+// 	func slowOperationWithTimeout(ctx context.Context) (Result, error) {
267
+// 		ctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
268
+// 		defer cancel()  // releases resources if slowOperation completes before timeout elapses
269
+// 		return slowOperation(ctx)
270
+// 	}
271
+func WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc) {
272
+	return WithDeadline(parent, time.Now().Add(timeout))
273
+}
274
+
275
+// WithValue returns a copy of parent in which the value associated with key is
276
+// val.
277
+//
278
+// Use context Values only for request-scoped data that transits processes and
279
+// APIs, not for passing optional parameters to functions.
280
+func WithValue(parent Context, key interface{}, val interface{}) Context {
281
+	return &valueCtx{parent, key, val}
282
+}
283
+
284
+// A valueCtx carries a key-value pair. It implements Value for that key and
285
+// delegates all other calls to the embedded Context.
286
+type valueCtx struct {
287
+	Context
288
+	key, val interface{}
289
+}
290
+
291
+func (c *valueCtx) String() string {
292
+	return fmt.Sprintf("%v.WithValue(%#v, %#v)", c.Context, c.key, c.val)
293
+}
294
+
295
+func (c *valueCtx) Value(key interface{}) interface{} {
296
+	if c.key == key {
297
+		return c.val
298
+	}
299
+	return c.Context.Value(key)
300
+}

+ 109
- 0
vendor/golang.org/x/net/context/pre_go19.go View File

@@ -0,0 +1,109 @@
1
+// Copyright 2014 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+// +build !go1.9
6
+
7
+package context
8
+
9
+import "time"
10
+
11
+// A Context carries a deadline, a cancelation signal, and other values across
12
+// API boundaries.
13
+//
14
+// Context's methods may be called by multiple goroutines simultaneously.
15
+type Context interface {
16
+	// Deadline returns the time when work done on behalf of this context
17
+	// should be canceled. Deadline returns ok==false when no deadline is
18
+	// set. Successive calls to Deadline return the same results.
19
+	Deadline() (deadline time.Time, ok bool)
20
+
21
+	// Done returns a channel that's closed when work done on behalf of this
22
+	// context should be canceled. Done may return nil if this context can
23
+	// never be canceled. Successive calls to Done return the same value.
24
+	//
25
+	// WithCancel arranges for Done to be closed when cancel is called;
26
+	// WithDeadline arranges for Done to be closed when the deadline
27
+	// expires; WithTimeout arranges for Done to be closed when the timeout
28
+	// elapses.
29
+	//
30
+	// Done is provided for use in select statements:
31
+	//
32
+	//  // Stream generates values with DoSomething and sends them to out
33
+	//  // until DoSomething returns an error or ctx.Done is closed.
34
+	//  func Stream(ctx context.Context, out chan<- Value) error {
35
+	//  	for {
36
+	//  		v, err := DoSomething(ctx)
37
+	//  		if err != nil {
38
+	//  			return err
39
+	//  		}
40
+	//  		select {
41
+	//  		case <-ctx.Done():
42
+	//  			return ctx.Err()
43
+	//  		case out <- v:
44
+	//  		}
45
+	//  	}
46
+	//  }
47
+	//
48
+	// See http://blog.golang.org/pipelines for more examples of how to use
49
+	// a Done channel for cancelation.
50
+	Done() <-chan struct{}
51
+
52
+	// Err returns a non-nil error value after Done is closed. Err returns
53
+	// Canceled if the context was canceled or DeadlineExceeded if the
54
+	// context's deadline passed. No other values for Err are defined.
55
+	// After Done is closed, successive calls to Err return the same value.
56
+	Err() error
57
+
58
+	// Value returns the value associated with this context for key, or nil
59
+	// if no value is associated with key. Successive calls to Value with
60
+	// the same key returns the same result.
61
+	//
62
+	// Use context values only for request-scoped data that transits
63
+	// processes and API boundaries, not for passing optional parameters to
64
+	// functions.
65
+	//
66
+	// A key identifies a specific value in a Context. Functions that wish
67
+	// to store values in Context typically allocate a key in a global
68
+	// variable then use that key as the argument to context.WithValue and
69
+	// Context.Value. A key can be any type that supports equality;
70
+	// packages should define keys as an unexported type to avoid
71
+	// collisions.
72
+	//
73
+	// Packages that define a Context key should provide type-safe accessors
74
+	// for the values stores using that key:
75
+	//
76
+	// 	// Package user defines a User type that's stored in Contexts.
77
+	// 	package user
78
+	//
79
+	// 	import "golang.org/x/net/context"
80
+	//
81
+	// 	// User is the type of value stored in the Contexts.
82
+	// 	type User struct {...}
83
+	//
84
+	// 	// key is an unexported type for keys defined in this package.
85
+	// 	// This prevents collisions with keys defined in other packages.
86
+	// 	type key int
87
+	//
88
+	// 	// userKey is the key for user.User values in Contexts. It is
89
+	// 	// unexported; clients use user.NewContext and user.FromContext
90
+	// 	// instead of using this key directly.
91
+	// 	var userKey key = 0
92
+	//
93
+	// 	// NewContext returns a new Context that carries value u.
94
+	// 	func NewContext(ctx context.Context, u *User) context.Context {
95
+	// 		return context.WithValue(ctx, userKey, u)
96
+	// 	}
97
+	//
98
+	// 	// FromContext returns the User value stored in ctx, if any.
99
+	// 	func FromContext(ctx context.Context) (*User, bool) {
100
+	// 		u, ok := ctx.Value(userKey).(*User)
101
+	// 		return u, ok
102
+	// 	}
103
+	Value(key interface{}) interface{}
104
+}
105
+
106
+// A CancelFunc tells an operation to abandon its work.
107
+// A CancelFunc does not wait for the work to stop.
108
+// After the first call, subsequent calls to a CancelFunc do nothing.
109
+type CancelFunc func()

+ 31
- 0
vendor/golang.org/x/net/context/withtimeout_test.go View File

@@ -0,0 +1,31 @@
1
+// Copyright 2014 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package context_test
6
+
7
+import (
8
+	"fmt"
9
+	"time"
10
+
11
+	"golang.org/x/net/context"
12
+)
13
+
14
+// This example passes a context with a timeout to tell a blocking function that
15
+// it should abandon its work after the timeout elapses.
16
+func ExampleWithTimeout() {
17
+	// Pass a context with a timeout to tell a blocking function that it
18
+	// should abandon its work after the timeout elapses.
19
+	ctx, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond)
20
+	defer cancel()
21
+
22
+	select {
23
+	case <-time.After(1 * time.Second):
24
+		fmt.Println("overslept")
25
+	case <-ctx.Done():
26
+		fmt.Println(ctx.Err()) // prints "context deadline exceeded"
27
+	}
28
+
29
+	// Output:
30
+	// context deadline exceeded
31
+}

+ 210
- 0
vendor/golang.org/x/net/dict/dict.go View File

@@ -0,0 +1,210 @@
1
+// Copyright 2010 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+// Package dict implements the Dictionary Server Protocol
6
+// as defined in RFC 2229.
7
+package dict // import "golang.org/x/net/dict"
8
+
9
+import (
10
+	"net/textproto"
11
+	"strconv"
12
+	"strings"
13
+)
14
+
15
+// A Client represents a client connection to a dictionary server.
16
+type Client struct {
17
+	text *textproto.Conn
18
+}
19
+
20
+// Dial returns a new client connected to a dictionary server at
21
+// addr on the given network.
22
+func Dial(network, addr string) (*Client, error) {
23
+	text, err := textproto.Dial(network, addr)
24
+	if err != nil {
25
+		return nil, err
26
+	}
27
+	_, _, err = text.ReadCodeLine(220)
28
+	if err != nil {
29
+		text.Close()
30
+		return nil, err
31
+	}
32
+	return &Client{text: text}, nil
33
+}
34
+
35
+// Close closes the connection to the dictionary server.
36
+func (c *Client) Close() error {
37
+	return c.text.Close()
38
+}
39
+
40
+// A Dict represents a dictionary available on the server.
41
+type Dict struct {
42
+	Name string // short name of dictionary
43
+	Desc string // long description
44
+}
45
+
46
+// Dicts returns a list of the dictionaries available on the server.
47
+func (c *Client) Dicts() ([]Dict, error) {
48
+	id, err := c.text.Cmd("SHOW DB")
49
+	if err != nil {
50
+		return nil, err
51
+	}
52
+
53
+	c.text.StartResponse(id)
54
+	defer c.text.EndResponse(id)
55
+
56
+	_, _, err = c.text.ReadCodeLine(110)
57
+	if err != nil {
58
+		return nil, err
59
+	}
60
+	lines, err := c.text.ReadDotLines()
61
+	if err != nil {
62
+		return nil, err
63
+	}
64
+	_, _, err = c.text.ReadCodeLine(250)
65
+
66
+	dicts := make([]Dict, len(lines))
67
+	for i := range dicts {
68
+		d := &dicts[i]
69
+		a, _ := fields(lines[i])
70
+		if len(a) < 2 {
71
+			return nil, textproto.ProtocolError("invalid dictionary: " + lines[i])
72
+		}
73
+		d.Name = a[0]
74
+		d.Desc = a[1]
75
+	}
76
+	return dicts, err
77
+}
78
+
79
+// A Defn represents a definition.
80
+type Defn struct {
81
+	Dict Dict   // Dict where definition was found
82
+	Word string // Word being defined
83
+	Text []byte // Definition text, typically multiple lines
84
+}
85
+
86
+// Define requests the definition of the given word.
87
+// The argument dict names the dictionary to use,
88
+// the Name field of a Dict returned by Dicts.
89
+//
90
+// The special dictionary name "*" means to look in all the
91
+// server's dictionaries.
92
+// The special dictionary name "!" means to look in all the
93
+// server's dictionaries in turn, stopping after finding the word
94
+// in one of them.
95
+func (c *Client) Define(dict, word string) ([]*Defn, error) {
96
+	id, err := c.text.Cmd("DEFINE %s %q", dict, word)
97
+	if err != nil {
98
+		return nil, err
99
+	}
100
+
101
+	c.text.StartResponse(id)
102
+	defer c.text.EndResponse(id)
103
+
104
+	_, line, err := c.text.ReadCodeLine(150)
105
+	if err != nil {
106
+		return nil, err
107
+	}
108
+	a, _ := fields(line)
109
+	if len(a) < 1 {
110
+		return nil, textproto.ProtocolError("malformed response: " + line)
111
+	}
112
+	n, err := strconv.Atoi(a[0])
113
+	if err != nil {
114
+		return nil, textproto.ProtocolError("invalid definition count: " + a[0])
115
+	}
116
+	def := make([]*Defn, n)
117
+	for i := 0; i < n; i++ {
118
+		_, line, err = c.text.ReadCodeLine(151)
119
+		if err != nil {
120
+			return nil, err
121
+		}
122
+		a, _ := fields(line)
123
+		if len(a) < 3 {
124
+			// skip it, to keep protocol in sync
125
+			i--
126
+			n--
127
+			def = def[0:n]
128
+			continue
129
+		}
130
+		d := &Defn{Word: a[0], Dict: Dict{a[1], a[2]}}
131
+		d.Text, err = c.text.ReadDotBytes()
132
+		if err != nil {
133
+			return nil, err
134
+		}
135
+		def[i] = d
136
+	}
137
+	_, _, err = c.text.ReadCodeLine(250)
138
+	return def, err
139
+}
140
+
141
+// Fields returns the fields in s.
142
+// Fields are space separated unquoted words
143
+// or quoted with single or double quote.
144
+func fields(s string) ([]string, error) {
145
+	var v []string
146
+	i := 0
147
+	for {
148
+		for i < len(s) && (s[i] == ' ' || s[i] == '\t') {
149
+			i++
150
+		}
151
+		if i >= len(s) {
152
+			break
153
+		}
154
+		if s[i] == '"' || s[i] == '\'' {
155
+			q := s[i]
156
+			// quoted string
157
+			var j int
158
+			for j = i + 1; ; j++ {
159
+				if j >= len(s) {
160
+					return nil, textproto.ProtocolError("malformed quoted string")
161
+				}
162
+				if s[j] == '\\' {
163
+					j++
164
+					continue
165
+				}
166
+				if s[j] == q {
167
+					j++
168
+					break
169
+				}
170
+			}
171
+			v = append(v, unquote(s[i+1:j-1]))
172
+			i = j
173
+		} else {
174
+			// atom
175
+			var j int
176
+			for j = i; j < len(s); j++ {
177
+				if s[j] == ' ' || s[j] == '\t' || s[j] == '\\' || s[j] == '"' || s[j] == '\'' {
178
+					break
179
+				}
180
+			}
181
+			v = append(v, s[i:j])
182
+			i = j
183
+		}
184
+		if i < len(s) {
185
+			c := s[i]
186
+			if c != ' ' && c != '\t' {
187
+				return nil, textproto.ProtocolError("quotes not on word boundaries")
188
+			}
189
+		}
190
+	}
191
+	return v, nil
192
+}
193
+
194
+func unquote(s string) string {
195
+	if strings.Index(s, "\\") < 0 {
196
+		return s
197
+	}
198
+	b := []byte(s)
199
+	w := 0
200
+	for r := 0; r < len(b); r++ {
201
+		c := b[r]
202
+		if c == '\\' {
203
+			r++
204
+			c = b[r]
205
+		}
206
+		b[w] = c
207
+		w++
208
+	}
209
+	return string(b[0:w])
210
+}

+ 132
- 0
vendor/golang.org/x/net/dns/dnsmessage/example_test.go View File

@@ -0,0 +1,132 @@
1
+// Copyright 2017 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package dnsmessage_test
6
+
7
+import (
8
+	"fmt"
9
+	"net"
10
+	"strings"
11
+
12
+	"golang.org/x/net/dns/dnsmessage"
13
+)
14
+
15
+func mustNewName(name string) dnsmessage.Name {
16
+	n, err := dnsmessage.NewName(name)
17
+	if err != nil {
18
+		panic(err)
19
+	}
20
+	return n
21
+}
22
+
23
+func ExampleParser() {
24
+	msg := dnsmessage.Message{
25
+		Header: dnsmessage.Header{Response: true, Authoritative: true},
26
+		Questions: []dnsmessage.Question{
27
+			{
28
+				Name:  mustNewName("foo.bar.example.com."),
29
+				Type:  dnsmessage.TypeA,
30
+				Class: dnsmessage.ClassINET,
31
+			},
32
+			{
33
+				Name:  mustNewName("bar.example.com."),
34
+				Type:  dnsmessage.TypeA,
35
+				Class: dnsmessage.ClassINET,
36
+			},
37
+		},
38
+		Answers: []dnsmessage.Resource{
39
+			{
40
+				dnsmessage.ResourceHeader{
41
+					Name:  mustNewName("foo.bar.example.com."),
42
+					Type:  dnsmessage.TypeA,
43
+					Class: dnsmessage.ClassINET,
44
+				},
45
+				&dnsmessage.AResource{[4]byte{127, 0, 0, 1}},
46
+			},
47
+			{
48
+				dnsmessage.ResourceHeader{
49
+					Name:  mustNewName("bar.example.com."),
50
+					Type:  dnsmessage.TypeA,
51
+					Class: dnsmessage.ClassINET,
52
+				},
53
+				&dnsmessage.AResource{[4]byte{127, 0, 0, 2}},
54
+			},
55
+		},
56
+	}
57
+
58
+	buf, err := msg.Pack()
59
+	if err != nil {
60
+		panic(err)
61
+	}
62
+
63
+	wantName := "bar.example.com."
64
+
65
+	var p dnsmessage.Parser
66
+	if _, err := p.Start(buf); err != nil {
67
+		panic(err)
68
+	}
69
+
70
+	for {
71
+		q, err := p.Question()
72
+		if err == dnsmessage.ErrSectionDone {
73
+			break
74
+		}
75
+		if err != nil {
76
+			panic(err)
77
+		}
78
+
79
+		if q.Name.String() != wantName {
80
+			continue
81
+		}
82
+
83
+		fmt.Println("Found question for name", wantName)
84
+		if err := p.SkipAllQuestions(); err != nil {
85
+			panic(err)
86
+		}
87
+		break
88
+	}
89
+
90
+	var gotIPs []net.IP
91
+	for {
92
+		h, err := p.AnswerHeader()
93
+		if err == dnsmessage.ErrSectionDone {
94
+			break
95
+		}
96
+		if err != nil {
97
+			panic(err)
98
+		}
99
+
100
+		if (h.Type != dnsmessage.TypeA && h.Type != dnsmessage.TypeAAAA) || h.Class != dnsmessage.ClassINET {
101
+			continue
102
+		}
103
+
104
+		if !strings.EqualFold(h.Name.String(), wantName) {
105
+			if err := p.SkipAnswer(); err != nil {
106
+				panic(err)
107
+			}
108
+			continue
109
+		}
110
+
111
+		switch h.Type {
112
+		case dnsmessage.TypeA:
113
+			r, err := p.AResource()
114
+			if err != nil {
115
+				panic(err)
116
+			}
117
+			gotIPs = append(gotIPs, r.A[:])
118
+		case dnsmessage.TypeAAAA:
119
+			r, err := p.AAAAResource()
120
+			if err != nil {
121
+				panic(err)
122
+			}
123
+			gotIPs = append(gotIPs, r.AAAA[:])
124
+		}
125
+	}
126
+
127
+	fmt.Printf("Found A/AAAA records for name %s: %v\n", wantName, gotIPs)
128
+
129
+	// Output:
130
+	// Found question for name bar.example.com.
131
+	// Found A/AAAA records for name bar.example.com.: [127.0.0.2]
132
+}

+ 1997
- 0
vendor/golang.org/x/net/dns/dnsmessage/message.go
File diff suppressed because it is too large
View File


+ 1116
- 0
vendor/golang.org/x/net/dns/dnsmessage/message_test.go
File diff suppressed because it is too large
View File


+ 78
- 0
vendor/golang.org/x/net/html/atom/atom.go View File

@@ -0,0 +1,78 @@
1
+// Copyright 2012 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+// Package atom provides integer codes (also known as atoms) for a fixed set of
6
+// frequently occurring HTML strings: tag names and attribute keys such as "p"
7
+// and "id".
8
+//
9
+// Sharing an atom's name between all elements with the same tag can result in
10
+// fewer string allocations when tokenizing and parsing HTML. Integer
11
+// comparisons are also generally faster than string comparisons.
12
+//
13
+// The value of an atom's particular code is not guaranteed to stay the same
14
+// between versions of this package. Neither is any ordering guaranteed:
15
+// whether atom.H1 < atom.H2 may also change. The codes are not guaranteed to
16
+// be dense. The only guarantees are that e.g. looking up "div" will yield
17
+// atom.Div, calling atom.Div.String will return "div", and atom.Div != 0.
18
+package atom // import "golang.org/x/net/html/atom"
19
+
20
+// Atom is an integer code for a string. The zero value maps to "".
21
+type Atom uint32
22
+
23
+// String returns the atom's name.
24
+func (a Atom) String() string {
25
+	start := uint32(a >> 8)
26
+	n := uint32(a & 0xff)
27
+	if start+n > uint32(len(atomText)) {
28
+		return ""
29
+	}
30
+	return atomText[start : start+n]
31
+}
32
+
33
+func (a Atom) string() string {
34
+	return atomText[a>>8 : a>>8+a&0xff]
35
+}
36
+
37
+// fnv computes the FNV hash with an arbitrary starting value h.
38
+func fnv(h uint32, s []byte) uint32 {
39
+	for i := range s {
40
+		h ^= uint32(s[i])
41
+		h *= 16777619
42
+	}
43
+	return h
44
+}
45
+
46
+func match(s string, t []byte) bool {
47
+	for i, c := range t {
48
+		if s[i] != c {
49
+			return false
50
+		}
51
+	}
52
+	return true
53
+}
54
+
55
+// Lookup returns the atom whose name is s. It returns zero if there is no
56
+// such atom. The lookup is case sensitive.
57
+func Lookup(s []byte) Atom {
58
+	if len(s) == 0 || len(s) > maxAtomLen {
59
+		return 0
60
+	}
61
+	h := fnv(hash0, s)
62
+	if a := table[h&uint32(len(table)-1)]; int(a&0xff) == len(s) && match(a.string(), s) {
63
+		return a
64
+	}
65
+	if a := table[(h>>16)&uint32(len(table)-1)]; int(a&0xff) == len(s) && match(a.string(), s) {
66
+		return a
67
+	}
68
+	return 0
69
+}
70
+
71
+// String returns a string whose contents are equal to s. In that sense, it is
72
+// equivalent to string(s) but may be more efficient.
73
+func String(s []byte) string {
74
+	if a := Lookup(s); a != 0 {
75
+		return a.String()
76
+	}
77
+	return string(s)
78
+}

+ 109
- 0
vendor/golang.org/x/net/html/atom/atom_test.go View File

@@ -0,0 +1,109 @@
1
+// Copyright 2012 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package atom
6
+
7
+import (
8
+	"sort"
9
+	"testing"
10
+)
11
+
12
+func TestKnown(t *testing.T) {
13
+	for _, s := range testAtomList {
14
+		if atom := Lookup([]byte(s)); atom.String() != s {
15
+			t.Errorf("Lookup(%q) = %#x (%q)", s, uint32(atom), atom.String())
16
+		}
17
+	}
18
+}
19
+
20
+func TestHits(t *testing.T) {
21
+	for _, a := range table {
22
+		if a == 0 {
23
+			continue
24
+		}
25
+		got := Lookup([]byte(a.String()))
26
+		if got != a {
27
+			t.Errorf("Lookup(%q) = %#x, want %#x", a.String(), uint32(got), uint32(a))
28
+		}
29
+	}
30
+}
31
+
32
+func TestMisses(t *testing.T) {
33
+	testCases := []string{
34
+		"",
35
+		"\x00",
36
+		"\xff",
37
+		"A",
38
+		"DIV",
39
+		"Div",
40
+		"dIV",
41
+		"aa",
42
+		"a\x00",
43
+		"ab",
44
+		"abb",
45
+		"abbr0",
46
+		"abbr ",
47
+		" abbr",
48
+		" a",
49
+		"acceptcharset",
50
+		"acceptCharset",
51
+		"accept_charset",
52
+		"h0",
53
+		"h1h2",
54
+		"h7",
55
+		"onClick",
56
+		"λ",
57
+		// The following string has the same hash (0xa1d7fab7) as "onmouseover".
58
+		"\x00\x00\x00\x00\x00\x50\x18\xae\x38\xd0\xb7",
59
+	}
60
+	for _, tc := range testCases {
61
+		got := Lookup([]byte(tc))
62
+		if got != 0 {
63
+			t.Errorf("Lookup(%q): got %d, want 0", tc, got)
64
+		}
65
+	}
66
+}
67
+
68
+func TestForeignObject(t *testing.T) {
69
+	const (
70
+		afo = Foreignobject
71
+		afO = ForeignObject
72
+		sfo = "foreignobject"
73
+		sfO = "foreignObject"
74
+	)
75
+	if got := Lookup([]byte(sfo)); got != afo {
76
+		t.Errorf("Lookup(%q): got %#v, want %#v", sfo, got, afo)
77
+	}
78
+	if got := Lookup([]byte(sfO)); got != afO {
79
+		t.Errorf("Lookup(%q): got %#v, want %#v", sfO, got, afO)
80
+	}
81
+	if got := afo.String(); got != sfo {
82
+		t.Errorf("Atom(%#v).String(): got %q, want %q", afo, got, sfo)
83
+	}
84
+	if got := afO.String(); got != sfO {
85
+		t.Errorf("Atom(%#v).String(): got %q, want %q", afO, got, sfO)
86
+	}
87
+}
88
+
89
+func BenchmarkLookup(b *testing.B) {
90
+	sortedTable := make([]string, 0, len(table))
91
+	for _, a := range table {
92
+		if a != 0 {
93
+			sortedTable = append(sortedTable, a.String())
94
+		}
95
+	}
96
+	sort.Strings(sortedTable)
97
+
98
+	x := make([][]byte, 1000)
99
+	for i := range x {
100
+		x[i] = []byte(sortedTable[i%len(sortedTable)])
101
+	}
102
+
103
+	b.ResetTimer()
104
+	for i := 0; i < b.N; i++ {
105
+		for _, s := range x {
106
+			Lookup(s)
107
+		}
108
+	}
109
+}

+ 648
- 0
vendor/golang.org/x/net/html/atom/gen.go View File

@@ -0,0 +1,648 @@
1
+// Copyright 2012 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+// +build ignore
6
+
7
+package main
8
+
9
+// This program generates table.go and table_test.go.
10
+// Invoke as
11
+//
12
+//	go run gen.go |gofmt >table.go
13
+//	go run gen.go -test |gofmt >table_test.go
14
+
15
+import (
16
+	"flag"
17
+	"fmt"
18
+	"math/rand"
19
+	"os"
20
+	"sort"
21
+	"strings"
22
+)
23
+
24
+// identifier converts s to a Go exported identifier.
25
+// It converts "div" to "Div" and "accept-charset" to "AcceptCharset".
26
+func identifier(s string) string {
27
+	b := make([]byte, 0, len(s))
28
+	cap := true
29
+	for _, c := range s {
30
+		if c == '-' {
31
+			cap = true
32
+			continue
33
+		}
34
+		if cap && 'a' <= c && c <= 'z' {
35
+			c -= 'a' - 'A'
36
+		}
37
+		cap = false
38
+		b = append(b, byte(c))
39
+	}
40
+	return string(b)
41
+}
42
+
43
+var test = flag.Bool("test", false, "generate table_test.go")
44
+
45
+func main() {
46
+	flag.Parse()
47
+
48
+	var all []string
49
+	all = append(all, elements...)
50
+	all = append(all, attributes...)
51
+	all = append(all, eventHandlers...)
52
+	all = append(all, extra...)
53
+	sort.Strings(all)
54
+
55
+	if *test {
56
+		fmt.Printf("// generated by go run gen.go -test; DO NOT EDIT\n\n")
57
+		fmt.Printf("package atom\n\n")
58
+		fmt.Printf("var testAtomList = []string{\n")
59
+		for _, s := range all {
60
+			fmt.Printf("\t%q,\n", s)
61
+		}
62
+		fmt.Printf("}\n")
63
+		return
64
+	}
65
+
66
+	// uniq - lists have dups
67
+	// compute max len too
68
+	maxLen := 0
69
+	w := 0
70
+	for _, s := range all {
71
+		if w == 0 || all[w-1] != s {
72
+			if maxLen < len(s) {
73
+				maxLen = len(s)
74
+			}
75
+			all[w] = s
76
+			w++
77
+		}
78
+	}
79
+	all = all[:w]
80
+
81
+	// Find hash that minimizes table size.
82
+	var best *table
83
+	for i := 0; i < 1000000; i++ {
84
+		if best != nil && 1<<(best.k-1) < len(all) {
85
+			break
86
+		}
87
+		h := rand.Uint32()
88
+		for k := uint(0); k <= 16; k++ {
89
+			if best != nil && k >= best.k {
90
+				break
91
+			}
92
+			var t table
93
+			if t.init(h, k, all) {
94
+				best = &t
95
+				break
96
+			}
97
+		}
98
+	}
99
+	if best == nil {
100
+		fmt.Fprintf(os.Stderr, "failed to construct string table\n")
101
+		os.Exit(1)
102
+	}
103
+
104
+	// Lay out strings, using overlaps when possible.
105
+	layout := append([]string{}, all...)
106
+
107
+	// Remove strings that are substrings of other strings
108
+	for changed := true; changed; {
109
+		changed = false
110
+		for i, s := range layout {
111
+			if s == "" {
112
+				continue
113
+			}
114
+			for j, t := range layout {
115
+				if i != j && t != "" && strings.Contains(s, t) {
116
+					changed = true
117
+					layout[j] = ""
118
+				}
119
+			}
120
+		}
121
+	}
122
+
123
+	// Join strings where one suffix matches another prefix.
124
+	for {
125
+		// Find best i, j, k such that layout[i][len-k:] == layout[j][:k],
126
+		// maximizing overlap length k.
127
+		besti := -1
128
+		bestj := -1
129
+		bestk := 0
130
+		for i, s := range layout {
131
+			if s == "" {
132
+				continue
133
+			}
134
+			for j, t := range layout {
135
+				if i == j {
136
+					continue
137
+				}
138
+				for k := bestk + 1; k <= len(s) && k <= len(t); k++ {
139
+					if s[len(s)-k:] == t[:k] {
140
+						besti = i
141
+						bestj = j
142
+						bestk = k
143
+					}
144
+				}
145
+			}
146
+		}
147
+		if bestk > 0 {
148
+			layout[besti] += layout[bestj][bestk:]
149
+			layout[bestj] = ""
150
+			continue
151
+		}
152
+		break
153
+	}
154
+
155
+	text := strings.Join(layout, "")
156
+
157
+	atom := map[string]uint32{}
158
+	for _, s := range all {
159
+		off := strings.Index(text, s)
160
+		if off < 0 {
161
+			panic("lost string " + s)
162
+		}
163
+		atom[s] = uint32(off<<8 | len(s))
164
+	}
165
+
166
+	// Generate the Go code.
167
+	fmt.Printf("// generated by go run gen.go; DO NOT EDIT\n\n")
168
+	fmt.Printf("package atom\n\nconst (\n")
169
+	for _, s := range all {
170
+		fmt.Printf("\t%s Atom = %#x\n", identifier(s), atom[s])
171
+	}
172
+	fmt.Printf(")\n\n")
173
+
174
+	fmt.Printf("const hash0 = %#x\n\n", best.h0)
175
+	fmt.Printf("const maxAtomLen = %d\n\n", maxLen)
176
+
177
+	fmt.Printf("var table = [1<<%d]Atom{\n", best.k)
178
+	for i, s := range best.tab {
179
+		if s == "" {
180
+			continue
181
+		}
182
+		fmt.Printf("\t%#x: %#x, // %s\n", i, atom[s], s)
183
+	}
184
+	fmt.Printf("}\n")
185
+	datasize := (1 << best.k) * 4
186
+
187
+	fmt.Printf("const atomText =\n")
188
+	textsize := len(text)
189
+	for len(text) > 60 {
190
+		fmt.Printf("\t%q +\n", text[:60])
191
+		text = text[60:]
192
+	}
193
+	fmt.Printf("\t%q\n\n", text)
194
+
195
+	fmt.Fprintf(os.Stderr, "%d atoms; %d string bytes + %d tables = %d total data\n", len(all), textsize, datasize, textsize+datasize)
196
+}
197
+
198
+type byLen []string
199
+
200
+func (x byLen) Less(i, j int) bool { return len(x[i]) > len(x[j]) }
201
+func (x byLen) Swap(i, j int)      { x[i], x[j] = x[j], x[i] }
202
+func (x byLen) Len() int           { return len(x) }
203
+
204
+// fnv computes the FNV hash with an arbitrary starting value h.
205
+func fnv(h uint32, s string) uint32 {
206
+	for i := 0; i < len(s); i++ {
207
+		h ^= uint32(s[i])
208
+		h *= 16777619
209
+	}
210
+	return h
211
+}
212
+
213
+// A table represents an attempt at constructing the lookup table.
214
+// The lookup table uses cuckoo hashing, meaning that each string
215
+// can be found in one of two positions.
216
+type table struct {
217
+	h0   uint32
218
+	k    uint
219
+	mask uint32
220
+	tab  []string
221
+}
222
+
223
+// hash returns the two hashes for s.
224
+func (t *table) hash(s string) (h1, h2 uint32) {
225
+	h := fnv(t.h0, s)
226
+	h1 = h & t.mask
227
+	h2 = (h >> 16) & t.mask
228
+	return
229
+}
230
+
231
+// init initializes the table with the given parameters.
232
+// h0 is the initial hash value,
233
+// k is the number of bits of hash value to use, and
234
+// x is the list of strings to store in the table.
235
+// init returns false if the table cannot be constructed.
236
+func (t *table) init(h0 uint32, k uint, x []string) bool {
237
+	t.h0 = h0
238
+	t.k = k
239
+	t.tab = make([]string, 1<<k)
240
+	t.mask = 1<<k - 1
241
+	for _, s := range x {
242
+		if !t.insert(s) {
243
+			return false
244
+		}
245
+	}
246
+	return true
247
+}
248
+
249
+// insert inserts s in the table.
250
+func (t *table) insert(s string) bool {
251
+	h1, h2 := t.hash(s)
252
+	if t.tab[h1] == "" {
253
+		t.tab[h1] = s
254
+		return true
255
+	}
256
+	if t.tab[h2] == "" {
257
+		t.tab[h2] = s
258
+		return true
259
+	}
260
+	if t.push(h1, 0) {
261
+		t.tab[h1] = s
262
+		return true
263
+	}
264
+	if t.push(h2, 0) {
265
+		t.tab[h2] = s
266
+		return true
267
+	}
268
+	return false
269
+}
270
+
271
+// push attempts to push aside the entry in slot i.
272
+func (t *table) push(i uint32, depth int) bool {
273
+	if depth > len(t.tab) {
274
+		return false
275
+	}
276
+	s := t.tab[i]
277
+	h1, h2 := t.hash(s)
278
+	j := h1 + h2 - i
279
+	if t.tab[j] != "" && !t.push(j, depth+1) {
280
+		return false
281
+	}
282
+	t.tab[j] = s
283
+	return true
284
+}
285
+
286
+// The lists of element names and attribute keys were taken from
287
+// https://html.spec.whatwg.org/multipage/indices.html#index
288
+// as of the "HTML Living Standard - Last Updated 21 February 2015" version.
289
+
290
+var elements = []string{
291
+	"a",
292
+	"abbr",
293
+	"address",
294
+	"area",
295
+	"article",
296
+	"aside",
297
+	"audio",
298
+	"b",
299
+	"base",
300
+	"bdi",
301
+	"bdo",
302
+	"blockquote",
303
+	"body",
304
+	"br",
305
+	"button",
306
+	"canvas",
307
+	"caption",
308
+	"cite",
309
+	"code",
310
+	"col",
311
+	"colgroup",
312
+	"command",
313
+	"data",
314
+	"datalist",
315
+	"dd",
316
+	"del",
317
+	"details",
318
+	"dfn",
319
+	"dialog",
320
+	"div",
321
+	"dl",
322
+	"dt",
323
+	"em",
324
+	"embed",
325
+	"fieldset",
326
+	"figcaption",
327
+	"figure",
328
+	"footer",
329
+	"form",
330
+	"h1",
331
+	"h2",
332
+	"h3",
333
+	"h4",
334
+	"h5",
335
+	"h6",
336
+	"head",
337
+	"header",
338
+	"hgroup",
339
+	"hr",
340
+	"html",
341
+	"i",
342
+	"iframe",
343
+	"img",
344
+	"input",
345
+	"ins",
346
+	"kbd",
347
+	"keygen",
348
+	"label",
349
+	"legend",
350
+	"li",
351
+	"link",
352
+	"map",
353
+	"mark",
354
+	"menu",
355
+	"menuitem",
356
+	"meta",
357
+	"meter",
358
+	"nav",
359
+	"noscript",
360
+	"object",
361
+	"ol",
362
+	"optgroup",
363
+	"option",
364
+	"output",
365
+	"p",
366
+	"param",
367
+	"pre",
368
+	"progress",
369
+	"q",
370
+	"rp",
371
+	"rt",
372
+	"ruby",
373
+	"s",
374
+	"samp",
375
+	"script",
376
+	"section",
377
+	"select",
378
+	"small",
379
+	"source",
380
+	"span",
381
+	"strong",
382
+	"style",
383
+	"sub",
384
+	"summary",
385
+	"sup",
386
+	"table",
387
+	"tbody",
388
+	"td",
389
+	"template",
390
+	"textarea",
391
+	"tfoot",
392
+	"th",
393
+	"thead",
394
+	"time",
395
+	"title",
396
+	"tr",
397
+	"track",
398
+	"u",
399
+	"ul",
400
+	"var",
401
+	"video",
402
+	"wbr",
403
+}
404
+
405
+// https://html.spec.whatwg.org/multipage/indices.html#attributes-3
406
+
407
+var attributes = []string{
408
+	"abbr",
409
+	"accept",
410
+	"accept-charset",
411
+	"accesskey",
412
+	"action",
413
+	"alt",
414
+	"async",
415
+	"autocomplete",
416
+	"autofocus",
417
+	"autoplay",
418
+	"challenge",
419
+	"charset",
420
+	"checked",
421
+	"cite",
422
+	"class",
423
+	"cols",
424
+	"colspan",
425
+	"command",
426
+	"content",
427
+	"contenteditable",
428
+	"contextmenu",
429
+	"controls",
430
+	"coords",
431
+	"crossorigin",
432
+	"data",
433
+	"datetime",
434
+	"default",
435
+	"defer",
436
+	"dir",
437
+	"dirname",
438
+	"disabled",
439
+	"download",
440
+	"draggable",
441
+	"dropzone",
442
+	"enctype",
443
+	"for",
444
+	"form",
445
+	"formaction",
446
+	"formenctype",
447
+	"formmethod",
448
+	"formnovalidate",
449
+	"formtarget",
450
+	"headers",
451
+	"height",
452
+	"hidden",
453
+	"high",
454
+	"href",
455
+	"hreflang",
456
+	"http-equiv",
457
+	"icon",
458
+	"id",
459
+	"inputmode",
460
+	"ismap",
461
+	"itemid",
462
+	"itemprop",
463
+	"itemref",
464
+	"itemscope",
465
+	"itemtype",
466
+	"keytype",
467
+	"kind",
468
+	"label",
469
+	"lang",
470
+	"list",
471
+	"loop",
472
+	"low",
473
+	"manifest",
474
+	"max",
475
+	"maxlength",
476
+	"media",
477
+	"mediagroup",
478
+	"method",
479
+	"min",
480
+	"minlength",
481
+	"multiple",
482
+	"muted",
483
+	"name",
484
+	"novalidate",
485
+	"open",
486
+	"optimum",
487
+	"pattern",
488
+	"ping",
489
+	"placeholder",
490
+	"poster",
491
+	"preload",
492
+	"radiogroup",
493
+	"readonly",
494
+	"rel",
495
+	"required",
496
+	"reversed",
497
+	"rows",
498
+	"rowspan",
499
+	"sandbox",
500
+	"spellcheck",
501
+	"scope",
502
+	"scoped",
503
+	"seamless",
504
+	"selected",
505
+	"shape",
506
+	"size",
507
+	"sizes",
508
+	"sortable",
509
+	"sorted",
510
+	"span",
511
+	"src",
512
+	"srcdoc",
513
+	"srclang",
514
+	"start",
515
+	"step",
516
+	"style",
517
+	"tabindex",
518
+	"target",
519
+	"title",
520
+	"translate",
521
+	"type",
522
+	"typemustmatch",
523
+	"usemap",
524
+	"value",
525
+	"width",
526
+	"wrap",
527
+}
528
+
529
+var eventHandlers = []string{
530
+	"onabort",
531
+	"onautocomplete",
532
+	"onautocompleteerror",
533
+	"onafterprint",
534
+	"onbeforeprint",
535
+	"onbeforeunload",
536
+	"onblur",
537
+	"oncancel",
538
+	"oncanplay",
539
+	"oncanplaythrough",
540
+	"onchange",
541
+	"onclick",
542
+	"onclose",
543
+	"oncontextmenu",
544
+	"oncuechange",
545
+	"ondblclick",
546
+	"ondrag",
547
+	"ondragend",
548
+	"ondragenter",
549
+	"ondragleave",
550
+	"ondragover",
551
+	"ondragstart",
552
+	"ondrop",
553
+	"ondurationchange",
554
+	"onemptied",
555
+	"onended",
556
+	"onerror",
557
+	"onfocus",
558
+	"onhashchange",
559
+	"oninput",
560
+	"oninvalid",
561
+	"onkeydown",
562
+	"onkeypress",
563
+	"onkeyup",
564
+	"onlanguagechange",
565
+	"onload",
566
+	"onloadeddata",
567
+	"onloadedmetadata",
568
+	"onloadstart",
569
+	"onmessage",
570
+	"onmousedown",
571
+	"onmousemove",
572
+	"onmouseout",
573
+	"onmouseover",
574
+	"onmouseup",
575
+	"onmousewheel",
576
+	"onoffline",
577
+	"ononline",
578
+	"onpagehide",
579
+	"onpageshow",
580
+	"onpause",
581
+	"onplay",
582
+	"onplaying",
583
+	"onpopstate",
584
+	"onprogress",
585
+	"onratechange",
586
+	"onreset",
587
+	"onresize",
588
+	"onscroll",
589
+	"onseeked",
590
+	"onseeking",
591
+	"onselect",
592
+	"onshow",
593
+	"onsort",
594
+	"onstalled",
595
+	"onstorage",
596
+	"onsubmit",
597
+	"onsuspend",
598
+	"ontimeupdate",
599
+	"ontoggle",
600
+	"onunload",
601
+	"onvolumechange",
602
+	"onwaiting",
603
+}
604
+
605
+// extra are ad-hoc values not covered by any of the lists above.
606
+var extra = []string{
607
+	"align",
608
+	"annotation",
609
+	"annotation-xml",
610
+	"applet",
611
+	"basefont",
612
+	"bgsound",
613
+	"big",
614
+	"blink",
615
+	"center",
616
+	"color",
617
+	"desc",
618
+	"face",
619
+	"font",
620
+	"foreignObject", // HTML is case-insensitive, but SVG-embedded-in-HTML is case-sensitive.
621
+	"foreignobject",
622
+	"frame",
623
+	"frameset",
624
+	"image",
625
+	"isindex",
626
+	"listing",
627
+	"malignmark",
628
+	"marquee",
629
+	"math",
630
+	"mglyph",
631
+	"mi",
632
+	"mn",
633
+	"mo",
634
+	"ms",
635
+	"mtext",
636
+	"nobr",
637
+	"noembed",
638
+	"noframes",
639
+	"plaintext",
640
+	"prompt",
641
+	"public",
642
+	"spacer",
643
+	"strike",
644
+	"svg",
645
+	"system",
646
+	"tt",
647
+	"xmp",
648
+}

+ 713
- 0
vendor/golang.org/x/net/html/atom/table.go View File

@@ -0,0 +1,713 @@
1
+// generated by go run gen.go; DO NOT EDIT
2
+
3
+package atom
4
+
5
+const (
6
+	A                   Atom = 0x1
7
+	Abbr                Atom = 0x4
8
+	Accept              Atom = 0x2106
9
+	AcceptCharset       Atom = 0x210e
10
+	Accesskey           Atom = 0x3309
11
+	Action              Atom = 0x1f606
12
+	Address             Atom = 0x4f307
13
+	Align               Atom = 0x1105
14
+	Alt                 Atom = 0x4503
15
+	Annotation          Atom = 0x1670a
16
+	AnnotationXml       Atom = 0x1670e
17
+	Applet              Atom = 0x2b306
18
+	Area                Atom = 0x2fa04
19
+	Article             Atom = 0x38807
20
+	Aside               Atom = 0x8305
21
+	Async               Atom = 0x7b05
22
+	Audio               Atom = 0xa605
23
+	Autocomplete        Atom = 0x1fc0c
24
+	Autofocus           Atom = 0xb309
25
+	Autoplay            Atom = 0xce08
26
+	B                   Atom = 0x101
27
+	Base                Atom = 0xd604
28
+	Basefont            Atom = 0xd608
29
+	Bdi                 Atom = 0x1a03
30
+	Bdo                 Atom = 0xe703
31
+	Bgsound             Atom = 0x11807
32
+	Big                 Atom = 0x12403
33
+	Blink               Atom = 0x12705
34
+	Blockquote          Atom = 0x12c0a
35
+	Body                Atom = 0x2f04
36
+	Br                  Atom = 0x202
37
+	Button              Atom = 0x13606
38
+	Canvas              Atom = 0x7f06
39
+	Caption             Atom = 0x1bb07
40
+	Center              Atom = 0x5b506
41
+	Challenge           Atom = 0x21f09
42
+	Charset             Atom = 0x2807
43
+	Checked             Atom = 0x32807
44
+	Cite                Atom = 0x3c804
45
+	Class               Atom = 0x4de05
46
+	Code                Atom = 0x14904
47
+	Col                 Atom = 0x15003
48
+	Colgroup            Atom = 0x15008
49
+	Color               Atom = 0x15d05
50
+	Cols                Atom = 0x16204
51
+	Colspan             Atom = 0x16207
52
+	Command             Atom = 0x17507
53
+	Content             Atom = 0x42307
54
+	Contenteditable     Atom = 0x4230f
55
+	Contextmenu         Atom = 0x3310b
56
+	Controls            Atom = 0x18808
57
+	Coords              Atom = 0x19406
58
+	Crossorigin         Atom = 0x19f0b
59
+	Data                Atom = 0x44a04
60
+	Datalist            Atom = 0x44a08
61
+	Datetime            Atom = 0x23c08
62
+	Dd                  Atom = 0x26702
63
+	Default             Atom = 0x8607
64
+	Defer               Atom = 0x14b05
65
+	Del                 Atom = 0x3ef03
66
+	Desc                Atom = 0x4db04
67
+	Details             Atom = 0x4807
68
+	Dfn                 Atom = 0x6103
69
+	Dialog              Atom = 0x1b06
70
+	Dir                 Atom = 0x6903
71
+	Dirname             Atom = 0x6907
72
+	Disabled            Atom = 0x10c08
73
+	Div                 Atom = 0x11303
74
+	Dl                  Atom = 0x11e02
75
+	Download            Atom = 0x40008
76
+	Draggable           Atom = 0x17b09
77
+	Dropzone            Atom = 0x39108
78
+	Dt                  Atom = 0x50902
79
+	Em                  Atom = 0x6502
80
+	Embed               Atom = 0x6505
81
+	Enctype             Atom = 0x21107
82
+	Face                Atom = 0x5b304
83
+	Fieldset            Atom = 0x1b008
84
+	Figcaption          Atom = 0x1b80a
85
+	Figure              Atom = 0x1cc06
86
+	Font                Atom = 0xda04
87
+	Footer              Atom = 0x8d06
88
+	For                 Atom = 0x1d803
89
+	ForeignObject       Atom = 0x1d80d
90
+	Foreignobject       Atom = 0x1e50d
91
+	Form                Atom = 0x1f204
92
+	Formaction          Atom = 0x1f20a
93
+	Formenctype         Atom = 0x20d0b
94
+	Formmethod          Atom = 0x2280a
95
+	Formnovalidate      Atom = 0x2320e
96
+	Formtarget          Atom = 0x2470a
97
+	Frame               Atom = 0x9a05
98
+	Frameset            Atom = 0x9a08
99
+	H1                  Atom = 0x26e02
100
+	H2                  Atom = 0x29402
101
+	H3                  Atom = 0x2a702
102
+	H4                  Atom = 0x2e902
103
+	H5                  Atom = 0x2f302
104
+	H6                  Atom = 0x50b02
105
+	Head                Atom = 0x2d504
106
+	Header              Atom = 0x2d506
107
+	Headers             Atom = 0x2d507
108
+	Height              Atom = 0x25106
109
+	Hgroup              Atom = 0x25906
110
+	Hidden              Atom = 0x26506
111
+	High                Atom = 0x26b04
112
+	Hr                  Atom = 0x27002
113
+	Href                Atom = 0x27004
114
+	Hreflang            Atom = 0x27008
115
+	Html                Atom = 0x25504
116
+	HttpEquiv           Atom = 0x2780a
117
+	I                   Atom = 0x601
118
+	Icon                Atom = 0x42204
119
+	Id                  Atom = 0x8502
120
+	Iframe              Atom = 0x29606
121
+	Image               Atom = 0x29c05
122
+	Img                 Atom = 0x2a103
123
+	Input               Atom = 0x3e805
124
+	Inputmode           Atom = 0x3e809
125
+	Ins                 Atom = 0x1a803
126
+	Isindex             Atom = 0x2a907
127
+	Ismap               Atom = 0x2b005
128
+	Itemid              Atom = 0x33c06
129
+	Itemprop            Atom = 0x3c908
130
+	Itemref             Atom = 0x5ad07
131
+	Itemscope           Atom = 0x2b909
132
+	Itemtype            Atom = 0x2c308
133
+	Kbd                 Atom = 0x1903
134
+	Keygen              Atom = 0x3906
135
+	Keytype             Atom = 0x53707
136
+	Kind                Atom = 0x10904
137
+	Label               Atom = 0xf005
138
+	Lang                Atom = 0x27404
139
+	Legend              Atom = 0x18206
140
+	Li                  Atom = 0x1202
141
+	Link                Atom = 0x12804
142
+	List                Atom = 0x44e04
143
+	Listing             Atom = 0x44e07
144
+	Loop                Atom = 0xf404
145
+	Low                 Atom = 0x11f03
146
+	Malignmark          Atom = 0x100a
147
+	Manifest            Atom = 0x5f108
148
+	Map                 Atom = 0x2b203
149
+	Mark                Atom = 0x1604
150
+	Marquee             Atom = 0x2cb07
151
+	Math                Atom = 0x2d204
152
+	Max                 Atom = 0x2e103
153
+	Maxlength           Atom = 0x2e109
154
+	Media               Atom = 0x6e05
155
+	Mediagroup          Atom = 0x6e0a
156
+	Menu                Atom = 0x33804
157
+	Menuitem            Atom = 0x33808
158
+	Meta                Atom = 0x45d04
159
+	Meter               Atom = 0x24205
160
+	Method              Atom = 0x22c06
161
+	Mglyph              Atom = 0x2a206
162
+	Mi                  Atom = 0x2eb02
163
+	Min                 Atom = 0x2eb03
164
+	Minlength           Atom = 0x2eb09
165
+	Mn                  Atom = 0x23502
166
+	Mo                  Atom = 0x3ed02
167
+	Ms                  Atom = 0x2bc02
168
+	Mtext               Atom = 0x2f505
169
+	Multiple            Atom = 0x30308
170
+	Muted               Atom = 0x30b05
171
+	Name                Atom = 0x6c04
172
+	Nav                 Atom = 0x3e03
173
+	Nobr                Atom = 0x5704
174
+	Noembed             Atom = 0x6307
175
+	Noframes            Atom = 0x9808
176
+	Noscript            Atom = 0x3d208
177
+	Novalidate          Atom = 0x2360a
178
+	Object              Atom = 0x1ec06
179
+	Ol                  Atom = 0xc902
180
+	Onabort             Atom = 0x13a07
181
+	Onafterprint        Atom = 0x1c00c
182
+	Onautocomplete      Atom = 0x1fa0e
183
+	Onautocompleteerror Atom = 0x1fa13
184
+	Onbeforeprint       Atom = 0x6040d
185
+	Onbeforeunload      Atom = 0x4e70e
186
+	Onblur              Atom = 0xaa06
187
+	Oncancel            Atom = 0xe908
188
+	Oncanplay           Atom = 0x28509
189
+	Oncanplaythrough    Atom = 0x28510
190
+	Onchange            Atom = 0x3a708
191
+	Onclick             Atom = 0x31007
192
+	Onclose             Atom = 0x31707
193
+	Oncontextmenu       Atom = 0x32f0d
194
+	Oncuechange         Atom = 0x3420b
195
+	Ondblclick          Atom = 0x34d0a
196
+	Ondrag              Atom = 0x35706
197
+	Ondragend           Atom = 0x35709
198
+	Ondragenter         Atom = 0x3600b
199
+	Ondragleave         Atom = 0x36b0b
200
+	Ondragover          Atom = 0x3760a
201
+	Ondragstart         Atom = 0x3800b
202
+	Ondrop              Atom = 0x38f06
203
+	Ondurationchange    Atom = 0x39f10
204
+	Onemptied           Atom = 0x39609
205
+	Onended             Atom = 0x3af07
206
+	Onerror             Atom = 0x3b607
207
+	Onfocus             Atom = 0x3bd07
208
+	Onhashchange        Atom = 0x3da0c
209
+	Oninput             Atom = 0x3e607
210
+	Oninvalid           Atom = 0x3f209
211
+	Onkeydown           Atom = 0x3fb09
212
+	Onkeypress          Atom = 0x4080a
213
+	Onkeyup             Atom = 0x41807
214
+	Onlanguagechange    Atom = 0x43210
215
+	Onload              Atom = 0x44206
216
+	Onloadeddata        Atom = 0x4420c
217
+	Onloadedmetadata    Atom = 0x45510
218
+	Onloadstart         Atom = 0x46b0b
219
+	Onmessage           Atom = 0x47609
220
+	Onmousedown         Atom = 0x47f0b
221
+	Onmousemove         Atom = 0x48a0b
222
+	Onmouseout          Atom = 0x4950a
223
+	Onmouseover         Atom = 0x4a20b
224
+	Onmouseup           Atom = 0x4ad09
225
+	Onmousewheel        Atom = 0x4b60c
226
+	Onoffline           Atom = 0x4c209
227
+	Ononline            Atom = 0x4cb08
228
+	Onpagehide          Atom = 0x4d30a
229
+	Onpageshow          Atom = 0x4fe0a
230
+	Onpause             Atom = 0x50d07
231
+	Onplay              Atom = 0x51706
232
+	Onplaying           Atom = 0x51709
233
+	Onpopstate          Atom = 0x5200a
234
+	Onprogress          Atom = 0x52a0a
235
+	Onratechange        Atom = 0x53e0c
236
+	Onreset             Atom = 0x54a07
237
+	Onresize            Atom = 0x55108
238
+	Onscroll            Atom = 0x55f08
239
+	Onseeked            Atom = 0x56708
240
+	Onseeking           Atom = 0x56f09
241
+	Onselect            Atom = 0x57808
242
+	Onshow              Atom = 0x58206
243
+	Onsort              Atom = 0x58b06
244
+	Onstalled           Atom = 0x59509
245
+	Onstorage           Atom = 0x59e09
246
+	Onsubmit            Atom = 0x5a708
247
+	Onsuspend           Atom = 0x5bb09
248
+	Ontimeupdate        Atom = 0xdb0c
249
+	Ontoggle            Atom = 0x5c408
250
+	Onunload            Atom = 0x5cc08
251
+	Onvolumechange      Atom = 0x5d40e
252
+	Onwaiting           Atom = 0x5e209
253
+	Open                Atom = 0x3cf04
254
+	Optgroup            Atom = 0xf608
255
+	Optimum             Atom = 0x5eb07
256
+	Option              Atom = 0x60006
257
+	Output              Atom = 0x49c06
258
+	P                   Atom = 0xc01
259
+	Param               Atom = 0xc05
260
+	Pattern             Atom = 0x5107
261
+	Ping                Atom = 0x7704
262
+	Placeholder         Atom = 0xc30b
263
+	Plaintext           Atom = 0xfd09
264
+	Poster              Atom = 0x15706
265
+	Pre                 Atom = 0x25e03
266
+	Preload             Atom = 0x25e07
267
+	Progress            Atom = 0x52c08
268
+	Prompt              Atom = 0x5fa06
269
+	Public              Atom = 0x41e06
270
+	Q                   Atom = 0x13101
271
+	Radiogroup          Atom = 0x30a
272
+	Readonly            Atom = 0x2fb08
273
+	Rel                 Atom = 0x25f03
274
+	Required            Atom = 0x1d008
275
+	Reversed            Atom = 0x5a08
276
+	Rows                Atom = 0x9204
277
+	Rowspan             Atom = 0x9207
278
+	Rp                  Atom = 0x1c602
279
+	Rt                  Atom = 0x13f02
280
+	Ruby                Atom = 0xaf04
281
+	S                   Atom = 0x2c01
282
+	Samp                Atom = 0x4e04
283
+	Sandbox             Atom = 0xbb07
284
+	Scope               Atom = 0x2bd05
285
+	Scoped              Atom = 0x2bd06
286
+	Script              Atom = 0x3d406
287
+	Seamless            Atom = 0x31c08
288
+	Section             Atom = 0x4e207
289
+	Select              Atom = 0x57a06
290
+	Selected            Atom = 0x57a08
291
+	Shape               Atom = 0x4f905
292
+	Size                Atom = 0x55504
293
+	Sizes               Atom = 0x55505
294
+	Small               Atom = 0x18f05
295
+	Sortable            Atom = 0x58d08
296
+	Sorted              Atom = 0x19906
297
+	Source              Atom = 0x1aa06
298
+	Spacer              Atom = 0x2db06
299
+	Span                Atom = 0x9504
300
+	Spellcheck          Atom = 0x3230a
301
+	Src                 Atom = 0x3c303
302
+	Srcdoc              Atom = 0x3c306
303
+	Srclang             Atom = 0x41107
304
+	Start               Atom = 0x38605
305
+	Step                Atom = 0x5f704
306
+	Strike              Atom = 0x53306
307
+	Strong              Atom = 0x55906
308
+	Style               Atom = 0x61105
309
+	Sub                 Atom = 0x5a903
310
+	Summary             Atom = 0x61607
311
+	Sup                 Atom = 0x61d03
312
+	Svg                 Atom = 0x62003
313
+	System              Atom = 0x62306
314
+	Tabindex            Atom = 0x46308
315
+	Table               Atom = 0x42d05
316
+	Target              Atom = 0x24b06
317
+	Tbody               Atom = 0x2e05
318
+	Td                  Atom = 0x4702
319
+	Template            Atom = 0x62608
320
+	Textarea            Atom = 0x2f608
321
+	Tfoot               Atom = 0x8c05
322
+	Th                  Atom = 0x22e02
323
+	Thead               Atom = 0x2d405
324
+	Time                Atom = 0xdd04
325
+	Title               Atom = 0xa105
326
+	Tr                  Atom = 0x10502
327
+	Track               Atom = 0x10505
328
+	Translate           Atom = 0x14009
329
+	Tt                  Atom = 0x5302
330
+	Type                Atom = 0x21404
331
+	Typemustmatch       Atom = 0x2140d
332
+	U                   Atom = 0xb01
333
+	Ul                  Atom = 0x8a02
334
+	Usemap              Atom = 0x51106
335
+	Value               Atom = 0x4005
336
+	Var                 Atom = 0x11503
337
+	Video               Atom = 0x28105
338
+	Wbr                 Atom = 0x12103
339
+	Width               Atom = 0x50705
340
+	Wrap                Atom = 0x58704
341
+	Xmp                 Atom = 0xc103
342
+)
343
+
344
+const hash0 = 0xc17da63e
345
+
346
+const maxAtomLen = 19
347
+
348
+var table = [1 << 9]Atom{
349
+	0x1:   0x48a0b, // onmousemove
350
+	0x2:   0x5e209, // onwaiting
351
+	0x3:   0x1fa13, // onautocompleteerror
352
+	0x4:   0x5fa06, // prompt
353
+	0x7:   0x5eb07, // optimum
354
+	0x8:   0x1604,  // mark
355
+	0xa:   0x5ad07, // itemref
356
+	0xb:   0x4fe0a, // onpageshow
357
+	0xc:   0x57a06, // select
358
+	0xd:   0x17b09, // draggable
359
+	0xe:   0x3e03,  // nav
360
+	0xf:   0x17507, // command
361
+	0x11:  0xb01,   // u
362
+	0x14:  0x2d507, // headers
363
+	0x15:  0x44a08, // datalist
364
+	0x17:  0x4e04,  // samp
365
+	0x1a:  0x3fb09, // onkeydown
366
+	0x1b:  0x55f08, // onscroll
367
+	0x1c:  0x15003, // col
368
+	0x20:  0x3c908, // itemprop
369
+	0x21:  0x2780a, // http-equiv
370
+	0x22:  0x61d03, // sup
371
+	0x24:  0x1d008, // required
372
+	0x2b:  0x25e07, // preload
373
+	0x2c:  0x6040d, // onbeforeprint
374
+	0x2d:  0x3600b, // ondragenter
375
+	0x2e:  0x50902, // dt
376
+	0x2f:  0x5a708, // onsubmit
377
+	0x30:  0x27002, // hr
378
+	0x31:  0x32f0d, // oncontextmenu
379
+	0x33:  0x29c05, // image
380
+	0x34:  0x50d07, // onpause
381
+	0x35:  0x25906, // hgroup
382
+	0x36:  0x7704,  // ping
383
+	0x37:  0x57808, // onselect
384
+	0x3a:  0x11303, // div
385
+	0x3b:  0x1fa0e, // onautocomplete
386
+	0x40:  0x2eb02, // mi
387
+	0x41:  0x31c08, // seamless
388
+	0x42:  0x2807,  // charset
389
+	0x43:  0x8502,  // id
390
+	0x44:  0x5200a, // onpopstate
391
+	0x45:  0x3ef03, // del
392
+	0x46:  0x2cb07, // marquee
393
+	0x47:  0x3309,  // accesskey
394
+	0x49:  0x8d06,  // footer
395
+	0x4a:  0x44e04, // list
396
+	0x4b:  0x2b005, // ismap
397
+	0x51:  0x33804, // menu
398
+	0x52:  0x2f04,  // body
399
+	0x55:  0x9a08,  // frameset
400
+	0x56:  0x54a07, // onreset
401
+	0x57:  0x12705, // blink
402
+	0x58:  0xa105,  // title
403
+	0x59:  0x38807, // article
404
+	0x5b:  0x22e02, // th
405
+	0x5d:  0x13101, // q
406
+	0x5e:  0x3cf04, // open
407
+	0x5f:  0x2fa04, // area
408
+	0x61:  0x44206, // onload
409
+	0x62:  0xda04,  // font
410
+	0x63:  0xd604,  // base
411
+	0x64:  0x16207, // colspan
412
+	0x65:  0x53707, // keytype
413
+	0x66:  0x11e02, // dl
414
+	0x68:  0x1b008, // fieldset
415
+	0x6a:  0x2eb03, // min
416
+	0x6b:  0x11503, // var
417
+	0x6f:  0x2d506, // header
418
+	0x70:  0x13f02, // rt
419
+	0x71:  0x15008, // colgroup
420
+	0x72:  0x23502, // mn
421
+	0x74:  0x13a07, // onabort
422
+	0x75:  0x3906,  // keygen
423
+	0x76:  0x4c209, // onoffline
424
+	0x77:  0x21f09, // challenge
425
+	0x78:  0x2b203, // map
426
+	0x7a:  0x2e902, // h4
427
+	0x7b:  0x3b607, // onerror
428
+	0x7c:  0x2e109, // maxlength
429
+	0x7d:  0x2f505, // mtext
430
+	0x7e:  0xbb07,  // sandbox
431
+	0x7f:  0x58b06, // onsort
432
+	0x80:  0x100a,  // malignmark
433
+	0x81:  0x45d04, // meta
434
+	0x82:  0x7b05,  // async
435
+	0x83:  0x2a702, // h3
436
+	0x84:  0x26702, // dd
437
+	0x85:  0x27004, // href
438
+	0x86:  0x6e0a,  // mediagroup
439
+	0x87:  0x19406, // coords
440
+	0x88:  0x41107, // srclang
441
+	0x89:  0x34d0a, // ondblclick
442
+	0x8a:  0x4005,  // value
443
+	0x8c:  0xe908,  // oncancel
444
+	0x8e:  0x3230a, // spellcheck
445
+	0x8f:  0x9a05,  // frame
446
+	0x91:  0x12403, // big
447
+	0x94:  0x1f606, // action
448
+	0x95:  0x6903,  // dir
449
+	0x97:  0x2fb08, // readonly
450
+	0x99:  0x42d05, // table
451
+	0x9a:  0x61607, // summary
452
+	0x9b:  0x12103, // wbr
453
+	0x9c:  0x30a,   // radiogroup
454
+	0x9d:  0x6c04,  // name
455
+	0x9f:  0x62306, // system
456
+	0xa1:  0x15d05, // color
457
+	0xa2:  0x7f06,  // canvas
458
+	0xa3:  0x25504, // html
459
+	0xa5:  0x56f09, // onseeking
460
+	0xac:  0x4f905, // shape
461
+	0xad:  0x25f03, // rel
462
+	0xae:  0x28510, // oncanplaythrough
463
+	0xaf:  0x3760a, // ondragover
464
+	0xb0:  0x62608, // template
465
+	0xb1:  0x1d80d, // foreignObject
466
+	0xb3:  0x9204,  // rows
467
+	0xb6:  0x44e07, // listing
468
+	0xb7:  0x49c06, // output
469
+	0xb9:  0x3310b, // contextmenu
470
+	0xbb:  0x11f03, // low
471
+	0xbc:  0x1c602, // rp
472
+	0xbd:  0x5bb09, // onsuspend
473
+	0xbe:  0x13606, // button
474
+	0xbf:  0x4db04, // desc
475
+	0xc1:  0x4e207, // section
476
+	0xc2:  0x52a0a, // onprogress
477
+	0xc3:  0x59e09, // onstorage
478
+	0xc4:  0x2d204, // math
479
+	0xc5:  0x4503,  // alt
480
+	0xc7:  0x8a02,  // ul
481
+	0xc8:  0x5107,  // pattern
482
+	0xc9:  0x4b60c, // onmousewheel
483
+	0xca:  0x35709, // ondragend
484
+	0xcb:  0xaf04,  // ruby
485
+	0xcc:  0xc01,   // p
486
+	0xcd:  0x31707, // onclose
487
+	0xce:  0x24205, // meter
488
+	0xcf:  0x11807, // bgsound
489
+	0xd2:  0x25106, // height
490
+	0xd4:  0x101,   // b
491
+	0xd5:  0x2c308, // itemtype
492
+	0xd8:  0x1bb07, // caption
493
+	0xd9:  0x10c08, // disabled
494
+	0xdb:  0x33808, // menuitem
495
+	0xdc:  0x62003, // svg
496
+	0xdd:  0x18f05, // small
497
+	0xde:  0x44a04, // data
498
+	0xe0:  0x4cb08, // ononline
499
+	0xe1:  0x2a206, // mglyph
500
+	0xe3:  0x6505,  // embed
501
+	0xe4:  0x10502, // tr
502
+	0xe5:  0x46b0b, // onloadstart
503
+	0xe7:  0x3c306, // srcdoc
504
+	0xeb:  0x5c408, // ontoggle
505
+	0xed:  0xe703,  // bdo
506
+	0xee:  0x4702,  // td
507
+	0xef:  0x8305,  // aside
508
+	0xf0:  0x29402, // h2
509
+	0xf1:  0x52c08, // progress
510
+	0xf2:  0x12c0a, // blockquote
511
+	0xf4:  0xf005,  // label
512
+	0xf5:  0x601,   // i
513
+	0xf7:  0x9207,  // rowspan
514
+	0xfb:  0x51709, // onplaying
515
+	0xfd:  0x2a103, // img
516
+	0xfe:  0xf608,  // optgroup
517
+	0xff:  0x42307, // content
518
+	0x101: 0x53e0c, // onratechange
519
+	0x103: 0x3da0c, // onhashchange
520
+	0x104: 0x4807,  // details
521
+	0x106: 0x40008, // download
522
+	0x109: 0x14009, // translate
523
+	0x10b: 0x4230f, // contenteditable
524
+	0x10d: 0x36b0b, // ondragleave
525
+	0x10e: 0x2106,  // accept
526
+	0x10f: 0x57a08, // selected
527
+	0x112: 0x1f20a, // formaction
528
+	0x113: 0x5b506, // center
529
+	0x115: 0x45510, // onloadedmetadata
530
+	0x116: 0x12804, // link
531
+	0x117: 0xdd04,  // time
532
+	0x118: 0x19f0b, // crossorigin
533
+	0x119: 0x3bd07, // onfocus
534
+	0x11a: 0x58704, // wrap
535
+	0x11b: 0x42204, // icon
536
+	0x11d: 0x28105, // video
537
+	0x11e: 0x4de05, // class
538
+	0x121: 0x5d40e, // onvolumechange
539
+	0x122: 0xaa06,  // onblur
540
+	0x123: 0x2b909, // itemscope
541
+	0x124: 0x61105, // style
542
+	0x127: 0x41e06, // public
543
+	0x129: 0x2320e, // formnovalidate
544
+	0x12a: 0x58206, // onshow
545
+	0x12c: 0x51706, // onplay
546
+	0x12d: 0x3c804, // cite
547
+	0x12e: 0x2bc02, // ms
548
+	0x12f: 0xdb0c,  // ontimeupdate
549
+	0x130: 0x10904, // kind
550
+	0x131: 0x2470a, // formtarget
551
+	0x135: 0x3af07, // onended
552
+	0x136: 0x26506, // hidden
553
+	0x137: 0x2c01,  // s
554
+	0x139: 0x2280a, // formmethod
555
+	0x13a: 0x3e805, // input
556
+	0x13c: 0x50b02, // h6
557
+	0x13d: 0xc902,  // ol
558
+	0x13e: 0x3420b, // oncuechange
559
+	0x13f: 0x1e50d, // foreignobject
560
+	0x143: 0x4e70e, // onbeforeunload
561
+	0x144: 0x2bd05, // scope
562
+	0x145: 0x39609, // onemptied
563
+	0x146: 0x14b05, // defer
564
+	0x147: 0xc103,  // xmp
565
+	0x148: 0x39f10, // ondurationchange
566
+	0x149: 0x1903,  // kbd
567
+	0x14c: 0x47609, // onmessage
568
+	0x14d: 0x60006, // option
569
+	0x14e: 0x2eb09, // minlength
570
+	0x14f: 0x32807, // checked
571
+	0x150: 0xce08,  // autoplay
572
+	0x152: 0x202,   // br
573
+	0x153: 0x2360a, // novalidate
574
+	0x156: 0x6307,  // noembed
575
+	0x159: 0x31007, // onclick
576
+	0x15a: 0x47f0b, // onmousedown
577
+	0x15b: 0x3a708, // onchange
578
+	0x15e: 0x3f209, // oninvalid
579
+	0x15f: 0x2bd06, // scoped
580
+	0x160: 0x18808, // controls
581
+	0x161: 0x30b05, // muted
582
+	0x162: 0x58d08, // sortable
583
+	0x163: 0x51106, // usemap
584
+	0x164: 0x1b80a, // figcaption
585
+	0x165: 0x35706, // ondrag
586
+	0x166: 0x26b04, // high
587
+	0x168: 0x3c303, // src
588
+	0x169: 0x15706, // poster
589
+	0x16b: 0x1670e, // annotation-xml
590
+	0x16c: 0x5f704, // step
591
+	0x16d: 0x4,     // abbr
592
+	0x16e: 0x1b06,  // dialog
593
+	0x170: 0x1202,  // li
594
+	0x172: 0x3ed02, // mo
595
+	0x175: 0x1d803, // for
596
+	0x176: 0x1a803, // ins
597
+	0x178: 0x55504, // size
598
+	0x179: 0x43210, // onlanguagechange
599
+	0x17a: 0x8607,  // default
600
+	0x17b: 0x1a03,  // bdi
601
+	0x17c: 0x4d30a, // onpagehide
602
+	0x17d: 0x6907,  // dirname
603
+	0x17e: 0x21404, // type
604
+	0x17f: 0x1f204, // form
605
+	0x181: 0x28509, // oncanplay
606
+	0x182: 0x6103,  // dfn
607
+	0x183: 0x46308, // tabindex
608
+	0x186: 0x6502,  // em
609
+	0x187: 0x27404, // lang
610
+	0x189: 0x39108, // dropzone
611
+	0x18a: 0x4080a, // onkeypress
612
+	0x18b: 0x23c08, // datetime
613
+	0x18c: 0x16204, // cols
614
+	0x18d: 0x1,     // a
615
+	0x18e: 0x4420c, // onloadeddata
616
+	0x190: 0xa605,  // audio
617
+	0x192: 0x2e05,  // tbody
618
+	0x193: 0x22c06, // method
619
+	0x195: 0xf404,  // loop
620
+	0x196: 0x29606, // iframe
621
+	0x198: 0x2d504, // head
622
+	0x19e: 0x5f108, // manifest
623
+	0x19f: 0xb309,  // autofocus
624
+	0x1a0: 0x14904, // code
625
+	0x1a1: 0x55906, // strong
626
+	0x1a2: 0x30308, // multiple
627
+	0x1a3: 0xc05,   // param
628
+	0x1a6: 0x21107, // enctype
629
+	0x1a7: 0x5b304, // face
630
+	0x1a8: 0xfd09,  // plaintext
631
+	0x1a9: 0x26e02, // h1
632
+	0x1aa: 0x59509, // onstalled
633
+	0x1ad: 0x3d406, // script
634
+	0x1ae: 0x2db06, // spacer
635
+	0x1af: 0x55108, // onresize
636
+	0x1b0: 0x4a20b, // onmouseover
637
+	0x1b1: 0x5cc08, // onunload
638
+	0x1b2: 0x56708, // onseeked
639
+	0x1b4: 0x2140d, // typemustmatch
640
+	0x1b5: 0x1cc06, // figure
641
+	0x1b6: 0x4950a, // onmouseout
642
+	0x1b7: 0x25e03, // pre
643
+	0x1b8: 0x50705, // width
644
+	0x1b9: 0x19906, // sorted
645
+	0x1bb: 0x5704,  // nobr
646
+	0x1be: 0x5302,  // tt
647
+	0x1bf: 0x1105,  // align
648
+	0x1c0: 0x3e607, // oninput
649
+	0x1c3: 0x41807, // onkeyup
650
+	0x1c6: 0x1c00c, // onafterprint
651
+	0x1c7: 0x210e,  // accept-charset
652
+	0x1c8: 0x33c06, // itemid
653
+	0x1c9: 0x3e809, // inputmode
654
+	0x1cb: 0x53306, // strike
655
+	0x1cc: 0x5a903, // sub
656
+	0x1cd: 0x10505, // track
657
+	0x1ce: 0x38605, // start
658
+	0x1d0: 0xd608,  // basefont
659
+	0x1d6: 0x1aa06, // source
660
+	0x1d7: 0x18206, // legend
661
+	0x1d8: 0x2d405, // thead
662
+	0x1da: 0x8c05,  // tfoot
663
+	0x1dd: 0x1ec06, // object
664
+	0x1de: 0x6e05,  // media
665
+	0x1df: 0x1670a, // annotation
666
+	0x1e0: 0x20d0b, // formenctype
667
+	0x1e2: 0x3d208, // noscript
668
+	0x1e4: 0x55505, // sizes
669
+	0x1e5: 0x1fc0c, // autocomplete
670
+	0x1e6: 0x9504,  // span
671
+	0x1e7: 0x9808,  // noframes
672
+	0x1e8: 0x24b06, // target
673
+	0x1e9: 0x38f06, // ondrop
674
+	0x1ea: 0x2b306, // applet
675
+	0x1ec: 0x5a08,  // reversed
676
+	0x1f0: 0x2a907, // isindex
677
+	0x1f3: 0x27008, // hreflang
678
+	0x1f5: 0x2f302, // h5
679
+	0x1f6: 0x4f307, // address
680
+	0x1fa: 0x2e103, // max
681
+	0x1fb: 0xc30b,  // placeholder
682
+	0x1fc: 0x2f608, // textarea
683
+	0x1fe: 0x4ad09, // onmouseup
684
+	0x1ff: 0x3800b, // ondragstart
685
+}
686
+
687
+const atomText = "abbradiogrouparamalignmarkbdialogaccept-charsetbodyaccesskey" +
688
+	"genavaluealtdetailsampatternobreversedfnoembedirnamediagroup" +
689
+	"ingasyncanvasidefaultfooterowspanoframesetitleaudionblurubya" +
690
+	"utofocusandboxmplaceholderautoplaybasefontimeupdatebdoncance" +
691
+	"labelooptgrouplaintextrackindisabledivarbgsoundlowbrbigblink" +
692
+	"blockquotebuttonabortranslatecodefercolgroupostercolorcolspa" +
693
+	"nnotation-xmlcommandraggablegendcontrolsmallcoordsortedcross" +
694
+	"originsourcefieldsetfigcaptionafterprintfigurequiredforeignO" +
695
+	"bjectforeignobjectformactionautocompleteerrorformenctypemust" +
696
+	"matchallengeformmethodformnovalidatetimeterformtargetheightm" +
697
+	"lhgroupreloadhiddenhigh1hreflanghttp-equivideoncanplaythroug" +
698
+	"h2iframeimageimglyph3isindexismappletitemscopeditemtypemarqu" +
699
+	"eematheaderspacermaxlength4minlength5mtextareadonlymultiplem" +
700
+	"utedonclickoncloseamlesspellcheckedoncontextmenuitemidoncuec" +
701
+	"hangeondblclickondragendondragenterondragleaveondragoverondr" +
702
+	"agstarticleondropzonemptiedondurationchangeonendedonerroronf" +
703
+	"ocusrcdocitempropenoscriptonhashchangeoninputmodeloninvalido" +
704
+	"nkeydownloadonkeypressrclangonkeyupublicontenteditableonlang" +
705
+	"uagechangeonloadeddatalistingonloadedmetadatabindexonloadsta" +
706
+	"rtonmessageonmousedownonmousemoveonmouseoutputonmouseoveronm" +
707
+	"ouseuponmousewheelonofflineononlineonpagehidesclassectionbef" +
708
+	"oreunloaddresshapeonpageshowidth6onpausemaponplayingonpopsta" +
709
+	"teonprogresstrikeytypeonratechangeonresetonresizestrongonscr" +
710
+	"ollonseekedonseekingonselectedonshowraponsortableonstalledon" +
711
+	"storageonsubmitemrefacenteronsuspendontoggleonunloadonvolume" +
712
+	"changeonwaitingoptimumanifestepromptoptionbeforeprintstylesu" +
713
+	"mmarysupsvgsystemplate"

+ 351
- 0
vendor/golang.org/x/net/html/atom/table_test.go View File

@@ -0,0 +1,351 @@
1
+// generated by go run gen.go -test; DO NOT EDIT
2
+
3
+package atom
4
+
5
+var testAtomList = []string{
6
+	"a",
7
+	"abbr",
8
+	"abbr",
9
+	"accept",
10
+	"accept-charset",
11
+	"accesskey",
12
+	"action",
13
+	"address",
14
+	"align",
15
+	"alt",
16
+	"annotation",
17
+	"annotation-xml",
18
+	"applet",
19
+	"area",
20
+	"article",
21
+	"aside",
22
+	"async",
23
+	"audio",
24
+	"autocomplete",
25
+	"autofocus",
26
+	"autoplay",
27
+	"b",
28
+	"base",
29
+	"basefont",
30
+	"bdi",
31
+	"bdo",
32
+	"bgsound",
33
+	"big",
34
+	"blink",
35
+	"blockquote",
36
+	"body",
37
+	"br",
38
+	"button",
39
+	"canvas",
40
+	"caption",
41
+	"center",
42
+	"challenge",
43
+	"charset",
44
+	"checked",
45
+	"cite",
46
+	"cite",
47
+	"class",
48
+	"code",
49
+	"col",
50
+	"colgroup",
51
+	"color",
52
+	"cols",
53
+	"colspan",
54
+	"command",
55
+	"command",
56
+	"content",
57
+	"contenteditable",
58
+	"contextmenu",
59
+	"controls",
60
+	"coords",
61
+	"crossorigin",
62
+	"data",
63
+	"data",
64
+	"datalist",
65
+	"datetime",
66
+	"dd",
67
+	"default",
68
+	"defer",
69
+	"del",
70
+	"desc",
71
+	"details",
72
+	"dfn",
73
+	"dialog",
74
+	"dir",
75
+	"dirname",
76
+	"disabled",
77
+	"div",
78
+	"dl",
79
+	"download",
80
+	"draggable",
81
+	"dropzone",
82
+	"dt",
83
+	"em",
84
+	"embed",
85
+	"enctype",
86
+	"face",
87
+	"fieldset",
88
+	"figcaption",
89
+	"figure",
90
+	"font",
91
+	"footer",
92
+	"for",
93
+	"foreignObject",
94
+	"foreignobject",
95
+	"form",
96
+	"form",
97
+	"formaction",
98
+	"formenctype",
99
+	"formmethod",
100
+	"formnovalidate",
101
+	"formtarget",
102
+	"frame",
103
+	"frameset",
104
+	"h1",
105
+	"h2",
106
+	"h3",
107
+	"h4",
108
+	"h5",
109
+	"h6",
110
+	"head",
111
+	"header",
112
+	"headers",
113
+	"height",
114
+	"hgroup",
115
+	"hidden",
116
+	"high",
117
+	"hr",
118
+	"href",
119
+	"hreflang",
120
+	"html",
121
+	"http-equiv",
122
+	"i",
123
+	"icon",
124
+	"id",
125
+	"iframe",
126
+	"image",
127
+	"img",
128
+	"input",
129
+	"inputmode",
130
+	"ins",
131
+	"isindex",
132
+	"ismap",
133
+	"itemid",
134
+	"itemprop",
135
+	"itemref",
136
+	"itemscope",
137
+	"itemtype",
138
+	"kbd",
139
+	"keygen",
140
+	"keytype",
141
+	"kind",
142
+	"label",
143
+	"label",
144
+	"lang",
145
+	"legend",
146
+	"li",
147
+	"link",
148
+	"list",
149
+	"listing",
150
+	"loop",
151
+	"low",
152
+	"malignmark",
153
+	"manifest",
154
+	"map",
155
+	"mark",
156
+	"marquee",
157
+	"math",
158
+	"max",
159
+	"maxlength",
160
+	"media",
161
+	"mediagroup",
162
+	"menu",
163
+	"menuitem",
164
+	"meta",
165
+	"meter",
166
+	"method",
167
+	"mglyph",
168
+	"mi",
169
+	"min",
170
+	"minlength",
171
+	"mn",
172
+	"mo",
173
+	"ms",
174
+	"mtext",
175
+	"multiple",
176
+	"muted",
177
+	"name",
178
+	"nav",
179
+	"nobr",
180
+	"noembed",
181
+	"noframes",
182
+	"noscript",
183
+	"novalidate",
184
+	"object",
185
+	"ol",
186
+	"onabort",
187
+	"onafterprint",
188
+	"onautocomplete",
189
+	"onautocompleteerror",
190
+	"onbeforeprint",
191
+	"onbeforeunload",
192
+	"onblur",
193
+	"oncancel",
194
+	"oncanplay",
195
+	"oncanplaythrough",
196
+	"onchange",
197
+	"onclick",
198
+	"onclose",
199
+	"oncontextmenu",
200
+	"oncuechange",
201
+	"ondblclick",
202
+	"ondrag",
203
+	"ondragend",
204
+	"ondragenter",
205
+	"ondragleave",
206
+	"ondragover",
207
+	"ondragstart",
208
+	"ondrop",
209
+	"ondurationchange",
210
+	"onemptied",
211
+	"onended",
212
+	"onerror",
213
+	"onfocus",
214
+	"onhashchange",
215
+	"oninput",
216
+	"oninvalid",
217
+	"onkeydown",
218
+	"onkeypress",
219
+	"onkeyup",
220
+	"onlanguagechange",
221
+	"onload",
222
+	"onloadeddata",
223
+	"onloadedmetadata",
224
+	"onloadstart",
225
+	"onmessage",
226
+	"onmousedown",
227
+	"onmousemove",
228
+	"onmouseout",
229
+	"onmouseover",
230
+	"onmouseup",
231
+	"onmousewheel",
232
+	"onoffline",
233
+	"ononline",
234
+	"onpagehide",
235
+	"onpageshow",
236
+	"onpause",
237
+	"onplay",
238
+	"onplaying",
239
+	"onpopstate",
240
+	"onprogress",
241
+	"onratechange",
242
+	"onreset",
243
+	"onresize",
244
+	"onscroll",
245
+	"onseeked",
246
+	"onseeking",
247
+	"onselect",
248
+	"onshow",
249
+	"onsort",
250
+	"onstalled",
251
+	"onstorage",
252
+	"onsubmit",
253
+	"onsuspend",
254
+	"ontimeupdate",
255
+	"ontoggle",
256
+	"onunload",
257
+	"onvolumechange",
258
+	"onwaiting",
259
+	"open",
260
+	"optgroup",
261
+	"optimum",
262
+	"option",
263
+	"output",
264
+	"p",
265
+	"param",
266
+	"pattern",
267
+	"ping",
268
+	"placeholder",
269
+	"plaintext",
270
+	"poster",
271
+	"pre",
272
+	"preload",
273
+	"progress",
274
+	"prompt",
275
+	"public",
276
+	"q",
277
+	"radiogroup",
278
+	"readonly",
279
+	"rel",
280
+	"required",
281
+	"reversed",
282
+	"rows",
283
+	"rowspan",
284
+	"rp",
285
+	"rt",
286
+	"ruby",
287
+	"s",
288
+	"samp",
289
+	"sandbox",
290
+	"scope",
291
+	"scoped",
292
+	"script",
293
+	"seamless",
294
+	"section",
295
+	"select",
296
+	"selected",
297
+	"shape",
298
+	"size",
299
+	"sizes",
300
+	"small",
301
+	"sortable",
302
+	"sorted",
303
+	"source",
304
+	"spacer",
305
+	"span",
306
+	"span",
307
+	"spellcheck",
308
+	"src",
309
+	"srcdoc",
310
+	"srclang",
311
+	"start",
312
+	"step",
313
+	"strike",
314
+	"strong",
315
+	"style",
316
+	"style",
317
+	"sub",
318
+	"summary",
319
+	"sup",
320
+	"svg",
321
+	"system",
322
+	"tabindex",
323
+	"table",
324
+	"target",
325
+	"tbody",
326
+	"td",
327
+	"template",
328
+	"textarea",
329
+	"tfoot",
330
+	"th",
331
+	"thead",
332
+	"time",
333
+	"title",
334
+	"title",
335
+	"tr",
336
+	"track",
337
+	"translate",
338
+	"tt",
339
+	"type",
340
+	"typemustmatch",
341
+	"u",
342
+	"ul",
343
+	"usemap",
344
+	"value",
345
+	"var",
346
+	"video",
347
+	"wbr",
348
+	"width",
349
+	"wrap",
350
+	"xmp",
351
+}

+ 257
- 0
vendor/golang.org/x/net/html/charset/charset.go View File

@@ -0,0 +1,257 @@
1
+// Copyright 2013 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+// Package charset provides common text encodings for HTML documents.
6
+//
7
+// The mapping from encoding labels to encodings is defined at
8
+// https://encoding.spec.whatwg.org/.
9
+package charset // import "golang.org/x/net/html/charset"
10
+
11
+import (
12
+	"bytes"
13
+	"fmt"
14
+	"io"
15
+	"mime"
16
+	"strings"
17
+	"unicode/utf8"
18
+
19
+	"golang.org/x/net/html"
20
+	"golang.org/x/text/encoding"
21
+	"golang.org/x/text/encoding/charmap"
22
+	"golang.org/x/text/encoding/htmlindex"
23
+	"golang.org/x/text/transform"
24
+)
25
+
26
+// Lookup returns the encoding with the specified label, and its canonical
27
+// name. It returns nil and the empty string if label is not one of the
28
+// standard encodings for HTML. Matching is case-insensitive and ignores
29
+// leading and trailing whitespace. Encoders will use HTML escape sequences for
30
+// runes that are not supported by the character set.
31
+func Lookup(label string) (e encoding.Encoding, name string) {
32
+	e, err := htmlindex.Get(label)
33
+	if err != nil {
34
+		return nil, ""
35
+	}
36
+	name, _ = htmlindex.Name(e)
37
+	return &htmlEncoding{e}, name
38
+}
39
+
40
+type htmlEncoding struct{ encoding.Encoding }
41
+
42
+func (h *htmlEncoding) NewEncoder() *encoding.Encoder {
43
+	// HTML requires a non-terminating legacy encoder. We use HTML escapes to
44
+	// substitute unsupported code points.
45
+	return encoding.HTMLEscapeUnsupported(h.Encoding.NewEncoder())
46
+}
47
+
48
+// DetermineEncoding determines the encoding of an HTML document by examining
49
+// up to the first 1024 bytes of content and the declared Content-Type.
50
+//
51
+// See http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#determining-the-character-encoding
52
+func DetermineEncoding(content []byte, contentType string) (e encoding.Encoding, name string, certain bool) {
53
+	if len(content) > 1024 {
54
+		content = content[:1024]
55
+	}
56
+
57
+	for _, b := range boms {
58
+		if bytes.HasPrefix(content, b.bom) {
59
+			e, name = Lookup(b.enc)
60
+			return e, name, true
61
+		}
62
+	}
63
+
64
+	if _, params, err := mime.ParseMediaType(contentType); err == nil {
65
+		if cs, ok := params["charset"]; ok {
66
+			if e, name = Lookup(cs); e != nil {
67
+				return e, name, true
68
+			}
69
+		}
70
+	}
71
+
72
+	if len(content) > 0 {
73
+		e, name = prescan(content)
74
+		if e != nil {
75
+			return e, name, false
76
+		}
77
+	}
78
+
79
+	// Try to detect UTF-8.
80
+	// First eliminate any partial rune at the end.
81
+	for i := len(content) - 1; i >= 0 && i > len(content)-4; i-- {
82
+		b := content[i]
83
+		if b < 0x80 {
84
+			break
85
+		}
86
+		if utf8.RuneStart(b) {
87
+			content = content[:i]
88
+			break
89
+		}
90
+	}
91
+	hasHighBit := false
92
+	for _, c := range content {
93
+		if c >= 0x80 {
94
+			hasHighBit = true
95
+			break
96
+		}
97
+	}
98
+	if hasHighBit && utf8.Valid(content) {
99
+		return encoding.Nop, "utf-8", false
100
+	}
101
+
102
+	// TODO: change default depending on user's locale?
103
+	return charmap.Windows1252, "windows-1252", false
104
+}
105
+
106
+// NewReader returns an io.Reader that converts the content of r to UTF-8.
107
+// It calls DetermineEncoding to find out what r's encoding is.
108
+func NewReader(r io.Reader, contentType string) (io.Reader, error) {
109
+	preview := make([]byte, 1024)
110
+	n, err := io.ReadFull(r, preview)
111
+	switch {
112
+	case err == io.ErrUnexpectedEOF:
113
+		preview = preview[:n]
114
+		r = bytes.NewReader(preview)
115
+	case err != nil:
116
+		return nil, err
117
+	default:
118
+		r = io.MultiReader(bytes.NewReader(preview), r)
119
+	}
120
+
121
+	if e, _, _ := DetermineEncoding(preview, contentType); e != encoding.Nop {
122
+		r = transform.NewReader(r, e.NewDecoder())
123
+	}
124
+	return r, nil
125
+}
126
+
127
+// NewReaderLabel returns a reader that converts from the specified charset to
128
+// UTF-8. It uses Lookup to find the encoding that corresponds to label, and
129
+// returns an error if Lookup returns nil. It is suitable for use as
130
+// encoding/xml.Decoder's CharsetReader function.
131
+func NewReaderLabel(label string, input io.Reader) (io.Reader, error) {
132
+	e, _ := Lookup(label)
133
+	if e == nil {
134
+		return nil, fmt.Errorf("unsupported charset: %q", label)
135
+	}
136
+	return transform.NewReader(input, e.NewDecoder()), nil
137
+}
138
+
139
+func prescan(content []byte) (e encoding.Encoding, name string) {
140
+	z := html.NewTokenizer(bytes.NewReader(content))
141
+	for {
142
+		switch z.Next() {
143
+		case html.ErrorToken:
144
+			return nil, ""
145
+
146
+		case html.StartTagToken, html.SelfClosingTagToken:
147
+			tagName, hasAttr := z.TagName()
148
+			if !bytes.Equal(tagName, []byte("meta")) {
149
+				continue
150
+			}
151
+			attrList := make(map[string]bool)
152
+			gotPragma := false
153
+
154
+			const (
155
+				dontKnow = iota
156
+				doNeedPragma
157
+				doNotNeedPragma
158
+			)
159
+			needPragma := dontKnow
160
+
161
+			name = ""
162
+			e = nil
163
+			for hasAttr {
164
+				var key, val []byte
165
+				key, val, hasAttr = z.TagAttr()
166
+				ks := string(key)
167
+				if attrList[ks] {
168
+					continue
169
+				}
170
+				attrList[ks] = true
171
+				for i, c := range val {
172
+					if 'A' <= c && c <= 'Z' {
173
+						val[i] = c + 0x20
174
+					}
175
+				}
176
+
177
+				switch ks {
178
+				case "http-equiv":
179
+					if bytes.Equal(val, []byte("content-type")) {
180
+						gotPragma = true
181
+					}
182
+
183
+				case "content":
184
+					if e == nil {
185
+						name = fromMetaElement(string(val))
186
+						if name != "" {
187
+							e, name = Lookup(name)
188
+							if e != nil {
189
+								needPragma = doNeedPragma
190
+							}
191
+						}
192
+					}
193
+
194
+				case "charset":
195
+					e, name = Lookup(string(val))
196
+					needPragma = doNotNeedPragma
197
+				}
198
+			}
199
+
200
+			if needPragma == dontKnow || needPragma == doNeedPragma && !gotPragma {
201
+				continue
202
+			}
203
+
204
+			if strings.HasPrefix(name, "utf-16") {
205
+				name = "utf-8"
206
+				e = encoding.Nop
207
+			}
208
+
209
+			if e != nil {
210
+				return e, name
211
+			}
212
+		}
213
+	}
214
+}
215
+
216
+func fromMetaElement(s string) string {
217
+	for s != "" {
218
+		csLoc := strings.Index(s, "charset")
219
+		if csLoc == -1 {
220
+			return ""
221
+		}
222
+		s = s[csLoc+len("charset"):]
223
+		s = strings.TrimLeft(s, " \t\n\f\r")
224
+		if !strings.HasPrefix(s, "=") {
225
+			continue
226
+		}
227
+		s = s[1:]
228
+		s = strings.TrimLeft(s, " \t\n\f\r")
229
+		if s == "" {
230
+			return ""
231
+		}
232
+		if q := s[0]; q == '"' || q == '\'' {
233
+			s = s[1:]
234
+			closeQuote := strings.IndexRune(s, rune(q))
235
+			if closeQuote == -1 {
236
+				return ""
237
+			}
238
+			return s[:closeQuote]
239
+		}
240
+
241
+		end := strings.IndexAny(s, "; \t\n\f\r")
242
+		if end == -1 {
243
+			end = len(s)
244
+		}
245
+		return s[:end]
246
+	}
247
+	return ""
248
+}
249
+
250
+var boms = []struct {
251
+	bom []byte
252
+	enc string
253
+}{
254
+	{[]byte{0xfe, 0xff}, "utf-16be"},
255
+	{[]byte{0xff, 0xfe}, "utf-16le"},
256
+	{[]byte{0xef, 0xbb, 0xbf}, "utf-8"},
257
+}

+ 237
- 0
vendor/golang.org/x/net/html/charset/charset_test.go View File

@@ -0,0 +1,237 @@
1
+// Copyright 2013 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package charset
6
+
7
+import (
8
+	"bytes"
9
+	"encoding/xml"
10
+	"io/ioutil"
11
+	"runtime"
12
+	"strings"
13
+	"testing"
14
+
15
+	"golang.org/x/text/transform"
16
+)
17
+
18
+func transformString(t transform.Transformer, s string) (string, error) {
19
+	r := transform.NewReader(strings.NewReader(s), t)
20
+	b, err := ioutil.ReadAll(r)
21
+	return string(b), err
22
+}
23
+
24
+type testCase struct {
25
+	utf8, other, otherEncoding string
26
+}
27
+
28
+// testCases for encoding and decoding.
29
+var testCases = []testCase{
30
+	{"Résumé", "Résumé", "utf8"},
31
+	{"Résumé", "R\xe9sum\xe9", "latin1"},
32
+	{"これは漢字です。", "S0\x8c0o0\"oW[g0Y0\x020", "UTF-16LE"},
33
+	{"これは漢字です。", "0S0\x8c0oo\"[W0g0Y0\x02", "UTF-16BE"},
34
+	{"Hello, world", "Hello, world", "ASCII"},
35
+	{"Gdańsk", "Gda\xf1sk", "ISO-8859-2"},
36
+	{"Ââ Čč Đđ Ŋŋ Õõ Šš Žž Åå Ää", "\xc2\xe2 \xc8\xe8 \xa9\xb9 \xaf\xbf \xd5\xf5 \xaa\xba \xac\xbc \xc5\xe5 \xc4\xe4", "ISO-8859-10"},
37
+	{"สำหรับ", "\xca\xd3\xcb\xc3\u047a", "ISO-8859-11"},
38
+	{"latviešu", "latvie\xf0u", "ISO-8859-13"},
39
+	{"Seònaid", "Se\xf2naid", "ISO-8859-14"},
40
+	{"€1 is cheap", "\xa41 is cheap", "ISO-8859-15"},
41
+	{"românește", "rom\xe2ne\xbate", "ISO-8859-16"},
42
+	{"nutraĵo", "nutra\xbco", "ISO-8859-3"},
43
+	{"Kalâdlit", "Kal\xe2dlit", "ISO-8859-4"},
44
+	{"русский", "\xe0\xe3\xe1\xe1\xda\xd8\xd9", "ISO-8859-5"},
45
+	{"ελληνικά", "\xe5\xeb\xeb\xe7\xed\xe9\xea\xdc", "ISO-8859-7"},
46
+	{"Kağan", "Ka\xf0an", "ISO-8859-9"},
47
+	{"Résumé", "R\x8esum\x8e", "macintosh"},
48
+	{"Gdańsk", "Gda\xf1sk", "windows-1250"},
49
+	{"русский", "\xf0\xf3\xf1\xf1\xea\xe8\xe9", "windows-1251"},
50
+	{"Résumé", "R\xe9sum\xe9", "windows-1252"},
51
+	{"ελληνικά", "\xe5\xeb\xeb\xe7\xed\xe9\xea\xdc", "windows-1253"},
52
+	{"Kağan", "Ka\xf0an", "windows-1254"},
53
+	{"עִבְרִית", "\xf2\xc4\xe1\xc0\xf8\xc4\xe9\xfa", "windows-1255"},
54
+	{"العربية", "\xc7\xe1\xda\xd1\xc8\xed\xc9", "windows-1256"},
55
+	{"latviešu", "latvie\xf0u", "windows-1257"},
56
+	{"Việt", "Vi\xea\xf2t", "windows-1258"},
57
+	{"สำหรับ", "\xca\xd3\xcb\xc3\u047a", "windows-874"},
58
+	{"русский", "\xd2\xd5\xd3\xd3\xcb\xc9\xca", "KOI8-R"},
59
+	{"українська", "\xd5\xcb\xd2\xc1\xa7\xce\xd3\xd8\xcb\xc1", "KOI8-U"},
60
+	{"Hello 常用國字標準字體表", "Hello \xb1`\xa5\u03b0\xea\xa6r\xbc\u0437\u01e6r\xc5\xe9\xaa\xed", "big5"},
61
+	{"Hello 常用國字標準字體表", "Hello \xb3\xa3\xd3\xc3\x87\xf8\xd7\xd6\x98\xcb\x9c\xca\xd7\xd6\xf3\x77\xb1\xed", "gbk"},
62
+	{"Hello 常用國字標準字體表", "Hello \xb3\xa3\xd3\xc3\x87\xf8\xd7\xd6\x98\xcb\x9c\xca\xd7\xd6\xf3\x77\xb1\xed", "gb18030"},
63
+	{"עִבְרִית", "\x81\x30\xfb\x30\x81\x30\xf6\x34\x81\x30\xf9\x33\x81\x30\xf6\x30\x81\x30\xfb\x36\x81\x30\xf6\x34\x81\x30\xfa\x31\x81\x30\xfb\x38", "gb18030"},
64
+	{"㧯", "\x82\x31\x89\x38", "gb18030"},
65
+	{"これは漢字です。", "\x82\xb1\x82\xea\x82\xcd\x8a\xbf\x8e\x9a\x82\xc5\x82\xb7\x81B", "SJIS"},
66
+	{"Hello, 世界!", "Hello, \x90\xa2\x8aE!", "SJIS"},
67
+	{"イウエオカ", "\xb2\xb3\xb4\xb5\xb6", "SJIS"},
68
+	{"これは漢字です。", "\xa4\xb3\xa4\xec\xa4\u03f4\xc1\xbb\xfa\xa4\u01e4\xb9\xa1\xa3", "EUC-JP"},
69
+	{"Hello, 世界!", "Hello, \x1b$B@$3&\x1b(B!", "ISO-2022-JP"},
70
+	{"다음과 같은 조건을 따라야 합니다: 저작자표시", "\xb4\xd9\xc0\xbd\xb0\xfa \xb0\xb0\xc0\xba \xc1\xb6\xb0\xc7\xc0\xbb \xb5\xfb\xb6\xf3\xbe\xdf \xc7մϴ\xd9: \xc0\xfa\xc0\xdb\xc0\xdaǥ\xbd\xc3", "EUC-KR"},
71
+}
72
+
73
+func TestDecode(t *testing.T) {
74
+	testCases := append(testCases, []testCase{
75
+		// Replace multi-byte maximum subpart of ill-formed subsequence with
76
+		// single replacement character (WhatWG requirement).
77
+		{"Rés\ufffdumé", "Rés\xe1\x80umé", "utf8"},
78
+	}...)
79
+	for _, tc := range testCases {
80
+		e, _ := Lookup(tc.otherEncoding)
81
+		if e == nil {
82
+			t.Errorf("%s: not found", tc.otherEncoding)
83
+			continue
84
+		}
85
+		s, err := transformString(e.NewDecoder(), tc.other)
86
+		if err != nil {
87
+			t.Errorf("%s: decode %q: %v", tc.otherEncoding, tc.other, err)
88
+			continue
89
+		}
90
+		if s != tc.utf8 {
91
+			t.Errorf("%s: got %q, want %q", tc.otherEncoding, s, tc.utf8)
92
+		}
93
+	}
94
+}
95
+
96
+func TestEncode(t *testing.T) {
97
+	testCases := append(testCases, []testCase{
98
+		// Use Go-style replacement.
99
+		{"Rés\xe1\x80umé", "Rés\ufffd\ufffdumé", "utf8"},
100
+		// U+0144 LATIN SMALL LETTER N WITH ACUTE not supported by encoding.
101
+		{"Gdańsk", "Gda&#324;sk", "ISO-8859-11"},
102
+		{"\ufffd", "&#65533;", "ISO-8859-11"},
103
+		{"a\xe1\x80b", "a&#65533;&#65533;b", "ISO-8859-11"},
104
+	}...)
105
+	for _, tc := range testCases {
106
+		e, _ := Lookup(tc.otherEncoding)
107
+		if e == nil {
108
+			t.Errorf("%s: not found", tc.otherEncoding)
109
+			continue
110
+		}
111
+		s, err := transformString(e.NewEncoder(), tc.utf8)
112
+		if err != nil {
113
+			t.Errorf("%s: encode %q: %s", tc.otherEncoding, tc.utf8, err)
114
+			continue
115
+		}
116
+		if s != tc.other {
117
+			t.Errorf("%s: got %q, want %q", tc.otherEncoding, s, tc.other)
118
+		}
119
+	}
120
+}
121
+
122
+var sniffTestCases = []struct {
123
+	filename, declared, want string
124
+}{
125
+	{"HTTP-charset.html", "text/html; charset=iso-8859-15", "iso-8859-15"},
126
+	{"UTF-16LE-BOM.html", "", "utf-16le"},
127
+	{"UTF-16BE-BOM.html", "", "utf-16be"},
128
+	{"meta-content-attribute.html", "text/html", "iso-8859-15"},
129
+	{"meta-charset-attribute.html", "text/html", "iso-8859-15"},
130
+	{"No-encoding-declaration.html", "text/html", "utf-8"},
131
+	{"HTTP-vs-UTF-8-BOM.html", "text/html; charset=iso-8859-15", "utf-8"},
132
+	{"HTTP-vs-meta-content.html", "text/html; charset=iso-8859-15", "iso-8859-15"},
133
+	{"HTTP-vs-meta-charset.html", "text/html; charset=iso-8859-15", "iso-8859-15"},
134
+	{"UTF-8-BOM-vs-meta-content.html", "text/html", "utf-8"},
135
+	{"UTF-8-BOM-vs-meta-charset.html", "text/html", "utf-8"},
136
+}
137
+
138
+func TestSniff(t *testing.T) {
139
+	switch runtime.GOOS {
140
+	case "nacl": // platforms that don't permit direct file system access
141
+		t.Skipf("not supported on %q", runtime.GOOS)
142
+	}
143
+
144
+	for _, tc := range sniffTestCases {
145
+		content, err := ioutil.ReadFile("testdata/" + tc.filename)
146
+		if err != nil {
147
+			t.Errorf("%s: error reading file: %v", tc.filename, err)
148
+			continue
149
+		}
150
+
151
+		_, name, _ := DetermineEncoding(content, tc.declared)
152
+		if name != tc.want {
153
+			t.Errorf("%s: got %q, want %q", tc.filename, name, tc.want)
154
+			continue
155
+		}
156
+	}
157
+}
158
+
159
+func TestReader(t *testing.T) {
160
+	switch runtime.GOOS {
161
+	case "nacl": // platforms that don't permit direct file system access
162
+		t.Skipf("not supported on %q", runtime.GOOS)
163
+	}
164
+
165
+	for _, tc := range sniffTestCases {
166
+		content, err := ioutil.ReadFile("testdata/" + tc.filename)
167
+		if err != nil {
168
+			t.Errorf("%s: error reading file: %v", tc.filename, err)
169
+			continue
170
+		}
171
+
172
+		r, err := NewReader(bytes.NewReader(content), tc.declared)
173
+		if err != nil {
174
+			t.Errorf("%s: error creating reader: %v", tc.filename, err)
175
+			continue
176
+		}
177
+
178
+		got, err := ioutil.ReadAll(r)
179
+		if err != nil {
180
+			t.Errorf("%s: error reading from charset.NewReader: %v", tc.filename, err)
181
+			continue
182
+		}
183
+
184
+		e, _ := Lookup(tc.want)
185
+		want, err := ioutil.ReadAll(transform.NewReader(bytes.NewReader(content), e.NewDecoder()))
186
+		if err != nil {
187
+			t.Errorf("%s: error decoding with hard-coded charset name: %v", tc.filename, err)
188
+			continue
189
+		}
190
+
191
+		if !bytes.Equal(got, want) {
192
+			t.Errorf("%s: got %q, want %q", tc.filename, got, want)
193
+			continue
194
+		}
195
+	}
196
+}
197
+
198
+var metaTestCases = []struct {
199
+	meta, want string
200
+}{
201
+	{"", ""},
202
+	{"text/html", ""},
203
+	{"text/html; charset utf-8", ""},
204
+	{"text/html; charset=latin-2", "latin-2"},
205
+	{"text/html; charset; charset = utf-8", "utf-8"},
206
+	{`charset="big5"`, "big5"},
207
+	{"charset='shift_jis'", "shift_jis"},
208
+}
209
+
210
+func TestFromMeta(t *testing.T) {
211
+	for _, tc := range metaTestCases {
212
+		got := fromMetaElement(tc.meta)
213
+		if got != tc.want {
214
+			t.Errorf("%q: got %q, want %q", tc.meta, got, tc.want)
215
+		}
216
+	}
217
+}
218
+
219
+func TestXML(t *testing.T) {
220
+	const s = "<?xml version=\"1.0\" encoding=\"windows-1252\"?><a><Word>r\xe9sum\xe9</Word></a>"
221
+
222
+	d := xml.NewDecoder(strings.NewReader(s))
223
+	d.CharsetReader = NewReaderLabel
224
+
225
+	var a struct {
226
+		Word string
227
+	}
228
+	err := d.Decode(&a)
229
+	if err != nil {
230
+		t.Fatalf("Decode: %v", err)
231
+	}
232
+
233
+	want := "résumé"
234
+	if a.Word != want {
235
+		t.Errorf("got %q, want %q", a.Word, want)
236
+	}
237
+}

+ 48
- 0
vendor/golang.org/x/net/html/charset/testdata/HTTP-charset.html View File

@@ -0,0 +1,48 @@
1
+<!DOCTYPE html>
2
+<html  lang="en" >
3
+<head>
4
+  <title>HTTP charset</title>
5
+<link rel='author' title='Richard Ishida' href='mailto:ishida@w3.org'>
6
+<link rel='help' href='http://www.w3.org/TR/html5/syntax.html#the-input-byte-stream'>
7
+<link rel="stylesheet" type="text/css" href="./generatedtests.css">
8
+<script src="http://w3c-test.org/resources/testharness.js"></script>
9
+<script src="http://w3c-test.org/resources/testharnessreport.js"></script>
10
+<meta name='flags' content='http'>
11
+<meta name="assert" content="The character encoding of a page can be set using the HTTP header charset declaration.">
12
+<style type='text/css'>
13
+.test div { width: 50px; }</style>
14
+<link rel="stylesheet" type="text/css" href="the-input-byte-stream/support/encodingtests-15.css">
15
+</head>
16
+<body>
17
+<p class='title'>HTTP charset</p>
18
+
19
+
20
+<div id='log'></div>
21
+
22
+
23
+<div class='test'><div id='box' class='ýäè'>&#xA0;</div></div>
24
+
25
+
26
+
27
+
28
+
29
+<div class='description'>
30
+<p class="assertion" title="Assertion">The character encoding of a page can be set using the HTTP header charset declaration.</p>
31
+<div class="notes"><p><p>The test contains a div with a class name that contains the following sequence of bytes: 0xC3 0xBD 0xC3 0xA4 0xC3 0xA8. These represent different sequences of characters in ISO 8859-15, ISO 8859-1 and UTF-8. The external, UTF-8-encoded stylesheet contains a selector <code>.test div.&#x00C3;&#x0153;&#x00C3;&#x20AC;&#x00C3;&#x0161;</code>. This matches the sequence of bytes above when they are interpreted as ISO 8859-15. If the class name matches the selector then the test will pass.</p><p>The only character encoding declaration for this HTML file is in the HTTP header, which sets the encoding to ISO 8859-15.</p></p>
32
+</div>
33
+</div>
34
+<div class="nexttest"><div><a href="generate?test=the-input-byte-stream-003">Next test</a></div><div class="doctype">HTML5</div>
35
+<p class="jump">the-input-byte-stream-001<br /><a href="/International/tests/html5/the-input-byte-stream/results-basics#basics" target="_blank">Result summary &amp; related tests</a><br /><a href="http://w3c-test.org/framework/details/i18n-html5/the-input-byte-stream-001" target="_blank">Detailed results for this test</a><br/>	<a href="http://www.w3.org/TR/html5/syntax.html#the-input-byte-stream" target="_blank">Link to spec</a></p>
36
+<div class='prereq'>Assumptions: <ul><li>The default encoding for the browser you are testing is not set to ISO 8859-15.</li>
37
+				<li>The test is read from a server that supports HTTP.</li></ul></div>
38
+</div>
39
+<script>
40
+test(function() {
41
+assert_equals(document.getElementById('box').offsetWidth, 100);
42
+}, " ");
43
+</script>
44
+
45
+</body>
46
+</html>
47
+
48
+

+ 48
- 0
vendor/golang.org/x/net/html/charset/testdata/HTTP-vs-UTF-8-BOM.html View File

@@ -0,0 +1,48 @@
1
+<!DOCTYPE html>
2
+<html  lang="en" >
3
+<head>
4
+  <title>HTTP vs UTF-8 BOM</title>
5
+<link rel='author' title='Richard Ishida' href='mailto:ishida@w3.org'>
6
+<link rel='help' href='http://www.w3.org/TR/html5/syntax.html#the-input-byte-stream'>
7
+<link rel="stylesheet" type="text/css" href="./generatedtests.css">
8
+<script src="http://w3c-test.org/resources/testharness.js"></script>
9
+<script src="http://w3c-test.org/resources/testharnessreport.js"></script>
10
+<meta name='flags' content='http'>
11
+<meta name="assert" content="A character encoding set in the HTTP header has lower precedence than the UTF-8 signature.">
12
+<style type='text/css'>
13
+.test div { width: 50px; }</style>
14
+<link rel="stylesheet" type="text/css" href="the-input-byte-stream/support/encodingtests-utf8.css">
15
+</head>
16
+<body>
17
+<p class='title'>HTTP vs UTF-8 BOM</p>
18
+
19
+
20
+<div id='log'></div>
21
+
22
+
23
+<div class='test'><div id='box' class='ýäè'>&#xA0;</div></div>
24
+
25
+
26
+
27
+
28
+
29
+<div class='description'>
30
+<p class="assertion" title="Assertion">A character encoding set in the HTTP header has lower precedence than the UTF-8 signature.</p>
31
+<div class="notes"><p><p>The HTTP header attempts to set the character encoding to ISO 8859-15. The page starts with a UTF-8 signature.</p><p>The test contains a div with a class name that contains the following sequence of bytes: 0xC3 0xBD 0xC3 0xA4 0xC3 0xA8. These represent different sequences of characters in ISO 8859-15, ISO 8859-1 and UTF-8. The external, UTF-8-encoded stylesheet contains a selector <code>.test div.&#x00FD;&#x00E4;&#x00E8;</code>. This matches the sequence of bytes above when they are interpreted as UTF-8. If the class name matches the selector then the test will pass.</p><p>If the test is unsuccessful, the characters &#x00EF;&#x00BB;&#x00BF; should appear at the top of the page.  These represent the bytes that make up the UTF-8 signature when encountered in the ISO 8859-15 encoding.</p></p>
32
+</div>
33
+</div>
34
+<div class="nexttest"><div><a href="generate?test=the-input-byte-stream-022">Next test</a></div><div class="doctype">HTML5</div>
35
+<p class="jump">the-input-byte-stream-034<br /><a href="/International/tests/html5/the-input-byte-stream/results-basics#precedence" target="_blank">Result summary &amp; related tests</a><br /><a href="http://w3c-test.org/framework/details/i18n-html5/the-input-byte-stream-034" target="_blank">Detailed results for this test</a><br/>	<a href="http://www.w3.org/TR/html5/syntax.html#the-input-byte-stream" target="_blank">Link to spec</a></p>
36
+<div class='prereq'>Assumptions: <ul><li>The default encoding for the browser you are testing is not set to ISO 8859-15.</li>
37
+				<li>The test is read from a server that supports HTTP.</li></ul></div>
38
+</div>
39
+<script>
40
+test(function() {
41
+assert_equals(document.getElementById('box').offsetWidth, 100);
42
+}, " ");
43
+</script>
44
+
45
+</body>
46
+</html>
47
+
48
+

+ 49
- 0
vendor/golang.org/x/net/html/charset/testdata/HTTP-vs-meta-charset.html View File

@@ -0,0 +1,49 @@
1
+<!DOCTYPE html>
2
+<html  lang="en" >
3
+<head>
4
+ <meta charset="iso-8859-1" > <title>HTTP vs meta charset</title>
5
+<link rel='author' title='Richard Ishida' href='mailto:ishida@w3.org'>
6
+<link rel='help' href='http://www.w3.org/TR/html5/syntax.html#the-input-byte-stream'>
7
+<link rel="stylesheet" type="text/css" href="./generatedtests.css">
8
+<script src="http://w3c-test.org/resources/testharness.js"></script>
9
+<script src="http://w3c-test.org/resources/testharnessreport.js"></script>
10
+<meta name='flags' content='http'>
11
+<meta name="assert" content="The HTTP header has a higher precedence than an encoding declaration in a meta charset attribute.">
12
+<style type='text/css'>
13
+.test div { width: 50px; }.test div { width: 90px; }
14
+</style>
15
+<link rel="stylesheet" type="text/css" href="the-input-byte-stream/support/encodingtests-15.css">
16
+</head>
17
+<body>
18
+<p class='title'>HTTP vs meta charset</p>
19
+
20
+
21
+<div id='log'></div>
22
+
23
+
24
+<div class='test'><div id='box' class='ýäè'>&#xA0;</div></div>
25
+
26
+
27
+
28
+
29
+
30
+<div class='description'>
31
+<p class="assertion" title="Assertion">The HTTP header has a higher precedence than an encoding declaration in a meta charset attribute.</p>
32
+<div class="notes"><p><p>The HTTP header attempts to set the character encoding to ISO 8859-15. The page contains an encoding declaration in a meta charset attribute that attempts to set the character encoding to ISO 8859-1.</p><p>The test contains a div with a class name that contains the following sequence of bytes: 0xC3 0xBD 0xC3 0xA4 0xC3 0xA8. These represent different sequences of characters in ISO 8859-15, ISO 8859-1 and UTF-8. The external, UTF-8-encoded stylesheet contains a selector <code>.test div.&#x00C3;&#x0153;&#x00C3;&#x20AC;&#x00C3;&#x0161;</code>. This matches the sequence of bytes above when they are interpreted as ISO 8859-15. If the class name matches the selector then the test will pass.</p></p>
33
+</div>
34
+</div>
35
+<div class="nexttest"><div><a href="generate?test=the-input-byte-stream-037">Next test</a></div><div class="doctype">HTML5</div>
36
+<p class="jump">the-input-byte-stream-018<br /><a href="/International/tests/html5/the-input-byte-stream/results-basics#precedence" target="_blank">Result summary &amp; related tests</a><br /><a href="http://w3c-test.org/framework/details/i18n-html5/the-input-byte-stream-018" target="_blank">Detailed results for this test</a><br/>	<a href="http://www.w3.org/TR/html5/syntax.html#the-input-byte-stream" target="_blank">Link to spec</a></p>
37
+<div class='prereq'>Assumptions: <ul><li>The default encoding for the browser you are testing is not set to ISO 8859-15.</li>
38
+				<li>The test is read from a server that supports HTTP.</li></ul></div>
39
+</div>
40
+<script>
41
+test(function() {
42
+assert_equals(document.getElementById('box').offsetWidth, 100);
43
+}, " ");
44
+</script>
45
+
46
+</body>
47
+</html>
48
+
49
+

+ 49
- 0
vendor/golang.org/x/net/html/charset/testdata/HTTP-vs-meta-content.html View File

@@ -0,0 +1,49 @@
1
+<!DOCTYPE html>
2
+<html  lang="en" >
3
+<head>
4
+ <meta http-equiv="content-type" content="text/html;charset=iso-8859-1" > <title>HTTP vs meta content</title>
5
+<link rel='author' title='Richard Ishida' href='mailto:ishida@w3.org'>
6
+<link rel='help' href='http://www.w3.org/TR/html5/syntax.html#the-input-byte-stream'>
7
+<link rel="stylesheet" type="text/css" href="./generatedtests.css">
8
+<script src="http://w3c-test.org/resources/testharness.js"></script>
9
+<script src="http://w3c-test.org/resources/testharnessreport.js"></script>
10
+<meta name='flags' content='http'>
11
+<meta name="assert" content="The HTTP header has a higher precedence than an encoding declaration in a meta content attribute.">
12
+<style type='text/css'>
13
+.test div { width: 50px; }.test div { width: 90px; }
14
+</style>
15
+<link rel="stylesheet" type="text/css" href="the-input-byte-stream/support/encodingtests-15.css">
16
+</head>
17
+<body>
18
+<p class='title'>HTTP vs meta content</p>
19
+
20
+
21
+<div id='log'></div>
22
+
23
+
24
+<div class='test'><div id='box' class='ýäè'>&#xA0;</div></div>
25
+
26
+
27
+
28
+
29
+
30
+<div class='description'>
31
+<p class="assertion" title="Assertion">The HTTP header has a higher precedence than an encoding declaration in a meta content attribute.</p>
32
+<div class="notes"><p><p>The HTTP header attempts to set the character encoding to ISO 8859-15. The page contains an encoding declaration in a meta content attribute that attempts to set the character encoding to ISO 8859-1.</p><p>The test contains a div with a class name that contains the following sequence of bytes: 0xC3 0xBD 0xC3 0xA4 0xC3 0xA8. These represent different sequences of characters in ISO 8859-15, ISO 8859-1 and UTF-8. The external, UTF-8-encoded stylesheet contains a selector <code>.test div.&#x00C3;&#x0153;&#x00C3;&#x20AC;&#x00C3;&#x0161;</code>. This matches the sequence of bytes above when they are interpreted as ISO 8859-15. If the class name matches the selector then the test will pass.</p></p>
33
+</div>
34
+</div>
35
+<div class="nexttest"><div><a href="generate?test=the-input-byte-stream-018">Next test</a></div><div class="doctype">HTML5</div>
36
+<p class="jump">the-input-byte-stream-016<br /><a href="/International/tests/html5/the-input-byte-stream/results-basics#precedence" target="_blank">Result summary &amp; related tests</a><br /><a href="http://w3c-test.org/framework/details/i18n-html5/the-input-byte-stream-016" target="_blank">Detailed results for this test</a><br/>	<a href="http://www.w3.org/TR/html5/syntax.html#the-input-byte-stream" target="_blank">Link to spec</a></p>
37
+<div class='prereq'>Assumptions: <ul><li>The default encoding for the browser you are testing is not set to ISO 8859-15.</li>
38
+				<li>The test is read from a server that supports HTTP.</li></ul></div>
39
+</div>
40
+<script>
41
+test(function() {
42
+assert_equals(document.getElementById('box').offsetWidth, 100);
43
+}, " ");
44
+</script>
45
+
46
+</body>
47
+</html>
48
+
49
+

+ 47
- 0
vendor/golang.org/x/net/html/charset/testdata/No-encoding-declaration.html View File

@@ -0,0 +1,47 @@
1
+<!DOCTYPE html>
2
+<html  lang="en" >
3
+<head>
4
+  <title>No encoding declaration</title>
5
+<link rel='author' title='Richard Ishida' href='mailto:ishida@w3.org'>
6
+<link rel='help' href='http://www.w3.org/TR/html5/syntax.html#the-input-byte-stream'>
7
+<link rel="stylesheet" type="text/css" href="./generatedtests.css">
8
+<script src="http://w3c-test.org/resources/testharness.js"></script>
9
+<script src="http://w3c-test.org/resources/testharnessreport.js"></script>
10
+<meta name='flags' content='http'>
11
+<meta name="assert" content="A page with no encoding information in HTTP, BOM, XML declaration or meta element will be treated as UTF-8.">
12
+<style type='text/css'>
13
+.test div { width: 50px; }</style>
14
+<link rel="stylesheet" type="text/css" href="the-input-byte-stream/support/encodingtests-utf8.css">
15
+</head>
16
+<body>
17
+<p class='title'>No encoding declaration</p>
18
+
19
+
20
+<div id='log'></div>
21
+
22
+
23
+<div class='test'><div id='box' class='ýäè'>&#xA0;</div></div>
24
+
25
+
26
+
27
+
28
+
29
+<div class='description'>
30
+<p class="assertion" title="Assertion">A page with no encoding information in HTTP, BOM, XML declaration or meta element will be treated as UTF-8.</p>
31
+<div class="notes"><p><p>The test on this page contains a div with a class name that contains the following sequence of bytes: 0xC3 0xBD 0xC3 0xA4 0xC3 0xA8. These represent different sequences of characters in ISO 8859-15, ISO 8859-1 and UTF-8. The external, UTF-8-encoded stylesheet contains a selector <code>.test div.&#x00FD;&#x00E4;&#x00E8;</code>. This matches the sequence of bytes above when they are interpreted as UTF-8. If the class name matches the selector then the test will pass.</p></p>
32
+</div>
33
+</div>
34
+<div class="nexttest"><div><a href="generate?test=the-input-byte-stream-034">Next test</a></div><div class="doctype">HTML5</div>
35
+<p class="jump">the-input-byte-stream-015<br /><a href="/International/tests/html5/the-input-byte-stream/results-basics#basics" target="_blank">Result summary &amp; related tests</a><br /><a href="http://w3c-test.org/framework/details/i18n-html5/the-input-byte-stream-015" target="_blank">Detailed results for this test</a><br/>	<a href="http://www.w3.org/TR/html5/syntax.html#the-input-byte-stream" target="_blank">Link to spec</a></p>
36
+<div class='prereq'>Assumptions: <ul><li>The test is read from a server that supports HTTP.</li></ul></div>
37
+</div>
38
+<script>
39
+test(function() {
40
+assert_equals(document.getElementById('box').offsetWidth, 100);
41
+}, " ");
42
+</script>
43
+
44
+</body>
45
+</html>
46
+
47
+

+ 9
- 0
vendor/golang.org/x/net/html/charset/testdata/README View File

@@ -0,0 +1,9 @@
1
+These test cases come from
2
+http://www.w3.org/International/tests/repository/html5/the-input-byte-stream/results-basics
3
+
4
+Distributed under both the W3C Test Suite License
5
+(http://www.w3.org/Consortium/Legal/2008/04-testsuite-license)
6
+and the W3C 3-clause BSD License
7
+(http://www.w3.org/Consortium/Legal/2008/03-bsd-license).
8
+To contribute to a W3C Test Suite, see the policies and contribution
9
+forms (http://www.w3.org/2004/10/27-testcases).

BIN
vendor/golang.org/x/net/html/charset/testdata/UTF-16BE-BOM.html View File


BIN
vendor/golang.org/x/net/html/charset/testdata/UTF-16LE-BOM.html View File


+ 49
- 0
vendor/golang.org/x/net/html/charset/testdata/UTF-8-BOM-vs-meta-charset.html View File

@@ -0,0 +1,49 @@
1
+<!DOCTYPE html>
2
+<html  lang="en" >
3
+<head>
4
+ <meta charset="iso-8859-15"> <title>UTF-8 BOM vs meta charset</title>
5
+<link rel='author' title='Richard Ishida' href='mailto:ishida@w3.org'>
6
+<link rel='help' href='http://www.w3.org/TR/html5/syntax.html#the-input-byte-stream'>
7
+<link rel="stylesheet" type="text/css" href="./generatedtests.css">
8
+<script src="http://w3c-test.org/resources/testharness.js"></script>
9
+<script src="http://w3c-test.org/resources/testharnessreport.js"></script>
10
+<meta name='flags' content='http'>
11
+<meta name="assert" content="A page with a UTF-8 BOM will be recognized as UTF-8 even if the meta charset attribute declares a different encoding.">
12
+<style type='text/css'>
13
+.test div { width: 50px; }.test div { width: 90px; }
14
+</style>
15
+<link rel="stylesheet" type="text/css" href="the-input-byte-stream/support/encodingtests-utf8.css">
16
+</head>
17
+<body>
18
+<p class='title'>UTF-8 BOM vs meta charset</p>
19
+
20
+
21
+<div id='log'></div>
22
+
23
+
24
+<div class='test'><div id='box' class='ýäè'>&#xA0;</div></div>
25
+
26
+
27
+
28
+
29
+
30
+<div class='description'>
31
+<p class="assertion" title="Assertion">A page with a UTF-8 BOM will be recognized as UTF-8 even if the meta charset attribute declares a different encoding.</p>
32
+<div class="notes"><p><p>The page contains an encoding declaration in a meta charset attribute that attempts to set the character encoding to ISO 8859-15, but the file starts with a UTF-8 signature.</p><p>The test contains a div with a class name that contains the following sequence of bytes: 0xC3 0xBD 0xC3 0xA4 0xC3 0xA8. These represent different sequences of characters in ISO 8859-15, ISO 8859-1 and UTF-8. The external, UTF-8-encoded stylesheet contains a selector <code>.test div.&#x00FD;&#x00E4;&#x00E8;</code>. This matches the sequence of bytes above when they are interpreted as UTF-8. If the class name matches the selector then the test will pass.</p></p>
33
+</div>
34
+</div>
35
+<div class="nexttest"><div><a href="generate?test=the-input-byte-stream-024">Next test</a></div><div class="doctype">HTML5</div>
36
+<p class="jump">the-input-byte-stream-038<br /><a href="/International/tests/html5/the-input-byte-stream/results-basics#precedence" target="_blank">Result summary &amp; related tests</a><br /><a href="http://w3c-test.org/framework/details/i18n-html5/the-input-byte-stream-038" target="_blank">Detailed results for this test</a><br/>	<a href="http://www.w3.org/TR/html5/syntax.html#the-input-byte-stream" target="_blank">Link to spec</a></p>
37
+<div class='prereq'>Assumptions: <ul><li>The default encoding for the browser you are testing is not set to ISO 8859-15.</li>
38
+				<li>The test is read from a server that supports HTTP.</li></ul></div>
39
+</div>
40
+<script>
41
+test(function() {
42
+assert_equals(document.getElementById('box').offsetWidth, 100);
43
+}, " ");
44
+</script>
45
+
46
+</body>
47
+</html>
48
+
49
+

+ 48
- 0
vendor/golang.org/x/net/html/charset/testdata/UTF-8-BOM-vs-meta-content.html View File

@@ -0,0 +1,48 @@
1
+<!DOCTYPE html>
2
+<html  lang="en" >
3
+<head>
4
+ <meta http-equiv="content-type" content="text/html; charset=iso-8859-15"> <title>UTF-8 BOM vs meta content</title>
5
+<link rel='author' title='Richard Ishida' href='mailto:ishida@w3.org'>
6
+<link rel='help' href='http://www.w3.org/TR/html5/syntax.html#the-input-byte-stream'>
7
+<link rel="stylesheet" type="text/css" href="./generatedtests.css">
8
+<script src="http://w3c-test.org/resources/testharness.js"></script>
9
+<script src="http://w3c-test.org/resources/testharnessreport.js"></script>
10
+<meta name='flags' content='http'>
11
+<meta name="assert" content="A page with a UTF-8 BOM will be recognized as UTF-8 even if the meta content attribute declares a different encoding.">
12
+<style type='text/css'>
13
+.test div { width: 50px; }</style>
14
+<link rel="stylesheet" type="text/css" href="the-input-byte-stream/support/encodingtests-utf8.css">
15
+</head>
16
+<body>
17
+<p class='title'>UTF-8 BOM vs meta content</p>
18
+
19
+
20
+<div id='log'></div>
21
+
22
+
23
+<div class='test'><div id='box' class='ýäè'>&#xA0;</div></div>
24
+
25
+
26
+
27
+
28
+
29
+<div class='description'>
30
+<p class="assertion" title="Assertion">A page with a UTF-8 BOM will be recognized as UTF-8 even if the meta content attribute declares a different encoding.</p>
31
+<div class="notes"><p><p>The page contains an encoding declaration in a meta content attribute that attempts to set the character encoding to ISO 8859-15, but the file starts with a UTF-8 signature.</p><p>The test contains a div with a class name that contains the following sequence of bytes: 0xC3 0xBD 0xC3 0xA4 0xC3 0xA8. These represent different sequences of characters in ISO 8859-15, ISO 8859-1 and UTF-8. The external, UTF-8-encoded stylesheet contains a selector <code>.test div.&#x00FD;&#x00E4;&#x00E8;</code>. This matches the sequence of bytes above when they are interpreted as UTF-8. If the class name matches the selector then the test will pass.</p></p>
32
+</div>
33
+</div>
34
+<div class="nexttest"><div><a href="generate?test=the-input-byte-stream-038">Next test</a></div><div class="doctype">HTML5</div>
35
+<p class="jump">the-input-byte-stream-037<br /><a href="/International/tests/html5/the-input-byte-stream/results-basics#precedence" target="_blank">Result summary &amp; related tests</a><br /><a href="http://w3c-test.org/framework/details/i18n-html5/the-input-byte-stream-037" target="_blank">Detailed results for this test</a><br/>	<a href="http://www.w3.org/TR/html5/syntax.html#the-input-byte-stream" target="_blank">Link to spec</a></p>
36
+<div class='prereq'>Assumptions: <ul><li>The default encoding for the browser you are testing is not set to ISO 8859-15.</li>
37
+				<li>The test is read from a server that supports HTTP.</li></ul></div>
38
+</div>
39
+<script>
40
+test(function() {
41
+assert_equals(document.getElementById('box').offsetWidth, 100);
42
+}, " ");
43
+</script>
44
+
45
+</body>
46
+</html>
47
+
48
+

+ 48
- 0
vendor/golang.org/x/net/html/charset/testdata/meta-charset-attribute.html View File

@@ -0,0 +1,48 @@
1
+<!DOCTYPE html>
2
+<html  lang="en" >
3
+<head>
4
+ <meta charset="iso-8859-15"> <title>meta charset attribute</title>
5
+<link rel='author' title='Richard Ishida' href='mailto:ishida@w3.org'>
6
+<link rel='help' href='http://www.w3.org/TR/html5/syntax.html#the-input-byte-stream'>
7
+<link rel="stylesheet" type="text/css" href="./generatedtests.css">
8
+<script src="http://w3c-test.org/resources/testharness.js"></script>
9
+<script src="http://w3c-test.org/resources/testharnessreport.js"></script>
10
+<meta name='flags' content='http'>
11
+<meta name="assert" content="The character encoding of the page can be set by a meta element with charset attribute.">
12
+<style type='text/css'>
13
+.test div { width: 50px; }</style>
14
+<link rel="stylesheet" type="text/css" href="the-input-byte-stream/support/encodingtests-15.css">
15
+</head>
16
+<body>
17
+<p class='title'>meta charset attribute</p>
18
+
19
+
20
+<div id='log'></div>
21
+
22
+
23
+<div class='test'><div id='box' class='ýäè'>&#xA0;</div></div>
24
+
25
+
26
+
27
+
28
+
29
+<div class='description'>
30
+<p class="assertion" title="Assertion">The character encoding of the page can be set by a meta element with charset attribute.</p>
31
+<div class="notes"><p><p>The only character encoding declaration for this HTML file is in the charset attribute of the meta element, which declares the encoding to be ISO 8859-15.</p><p>The test contains a div with a class name that contains the following sequence of bytes: 0xC3 0xBD 0xC3 0xA4 0xC3 0xA8. These represent different sequences of characters in ISO 8859-15, ISO 8859-1 and UTF-8. The external, UTF-8-encoded stylesheet contains a selector <code>.test div.&#x00C3;&#x0153;&#x00C3;&#x20AC;&#x00C3;&#x0161;</code>. This matches the sequence of bytes above when they are interpreted as ISO 8859-15. If the class name matches the selector then the test will pass.</p></p>
32
+</div>
33
+</div>
34
+<div class="nexttest"><div><a href="generate?test=the-input-byte-stream-015">Next test</a></div><div class="doctype">HTML5</div>
35
+<p class="jump">the-input-byte-stream-009<br /><a href="/International/tests/html5/the-input-byte-stream/results-basics#basics" target="_blank">Result summary &amp; related tests</a><br /><a href="http://w3c-test.org/framework/details/i18n-html5/the-input-byte-stream-009" target="_blank">Detailed results for this test</a><br/>	<a href="http://www.w3.org/TR/html5/syntax.html#the-input-byte-stream" target="_blank">Link to spec</a></p>
36
+<div class='prereq'>Assumptions: <ul><li>The default encoding for the browser you are testing is not set to ISO 8859-15.</li>
37
+				<li>The test is read from a server that supports HTTP.</li></ul></div>
38
+</div>
39
+<script>
40
+test(function() {
41
+assert_equals(document.getElementById('box').offsetWidth, 100);
42
+}, " ");
43
+</script>
44
+
45
+</body>
46
+</html>
47
+
48
+

+ 48
- 0
vendor/golang.org/x/net/html/charset/testdata/meta-content-attribute.html View File

@@ -0,0 +1,48 @@
1
+<!DOCTYPE html>
2
+<html  lang="en" >
3
+<head>
4
+ <meta http-equiv="content-type" content="text/html; charset=iso-8859-15"> <title>meta content attribute</title>
5
+<link rel='author' title='Richard Ishida' href='mailto:ishida@w3.org'>
6
+<link rel='help' href='http://www.w3.org/TR/html5/syntax.html#the-input-byte-stream'>
7
+<link rel="stylesheet" type="text/css" href="./generatedtests.css">
8
+<script src="http://w3c-test.org/resources/testharness.js"></script>
9
+<script src="http://w3c-test.org/resources/testharnessreport.js"></script>
10
+<meta name='flags' content='http'>
11
+<meta name="assert" content="The character encoding of the page can be set by a meta element with http-equiv and content attributes.">
12
+<style type='text/css'>
13
+.test div { width: 50px; }</style>
14
+<link rel="stylesheet" type="text/css" href="the-input-byte-stream/support/encodingtests-15.css">
15
+</head>
16
+<body>
17
+<p class='title'>meta content attribute</p>
18
+
19
+
20
+<div id='log'></div>
21
+
22
+
23
+<div class='test'><div id='box' class='ýäè'>&#xA0;</div></div>
24
+
25
+
26
+
27
+
28
+
29
+<div class='description'>
30
+<p class="assertion" title="Assertion">The character encoding of the page can be set by a meta element with http-equiv and content attributes.</p>
31
+<div class="notes"><p><p>The only character encoding declaration for this HTML file is in the content attribute of the meta element, which declares the encoding to be ISO 8859-15.</p><p>The test contains a div with a class name that contains the following sequence of bytes: 0xC3 0xBD 0xC3 0xA4 0xC3 0xA8. These represent different sequences of characters in ISO 8859-15, ISO 8859-1 and UTF-8. The external, UTF-8-encoded stylesheet contains a selector <code>.test div.&#x00C3;&#x0153;&#x00C3;&#x20AC;&#x00C3;&#x0161;</code>. This matches the sequence of bytes above when they are interpreted as ISO 8859-15. If the class name matches the selector then the test will pass.</p></p>
32
+</div>
33
+</div>
34
+<div class="nexttest"><div><a href="generate?test=the-input-byte-stream-009">Next test</a></div><div class="doctype">HTML5</div>
35
+<p class="jump">the-input-byte-stream-007<br /><a href="/International/tests/html5/the-input-byte-stream/results-basics#basics" target="_blank">Result summary &amp; related tests</a><br /><a href="http://w3c-test.org/framework/details/i18n-html5/the-input-byte-stream-007" target="_blank">Detailed results for this test</a><br/>	<a href="http://www.w3.org/TR/html5/syntax.html#the-input-byte-stream" target="_blank">Link to spec</a></p>
36
+<div class='prereq'>Assumptions: <ul><li>The default encoding for the browser you are testing is not set to ISO 8859-15.</li>
37
+				<li>The test is read from a server that supports HTTP.</li></ul></div>
38
+</div>
39
+<script>
40
+test(function() {
41
+assert_equals(document.getElementById('box').offsetWidth, 100);
42
+}, " ");
43
+</script>
44
+
45
+</body>
46
+</html>
47
+
48
+

+ 102
- 0
vendor/golang.org/x/net/html/const.go View File

@@ -0,0 +1,102 @@
1
+// Copyright 2011 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package html
6
+
7
+// Section 12.2.3.2 of the HTML5 specification says "The following elements
8
+// have varying levels of special parsing rules".
9
+// https://html.spec.whatwg.org/multipage/syntax.html#the-stack-of-open-elements
10
+var isSpecialElementMap = map[string]bool{
11
+	"address":    true,
12
+	"applet":     true,
13
+	"area":       true,
14
+	"article":    true,
15
+	"aside":      true,
16
+	"base":       true,
17
+	"basefont":   true,
18
+	"bgsound":    true,
19
+	"blockquote": true,
20
+	"body":       true,
21
+	"br":         true,
22
+	"button":     true,
23
+	"caption":    true,
24
+	"center":     true,
25
+	"col":        true,
26
+	"colgroup":   true,
27
+	"dd":         true,
28
+	"details":    true,
29
+	"dir":        true,
30
+	"div":        true,
31
+	"dl":         true,
32
+	"dt":         true,
33
+	"embed":      true,
34
+	"fieldset":   true,
35
+	"figcaption": true,
36
+	"figure":     true,
37
+	"footer":     true,
38
+	"form":       true,
39
+	"frame":      true,
40
+	"frameset":   true,
41
+	"h1":         true,
42
+	"h2":         true,
43
+	"h3":         true,
44
+	"h4":         true,
45
+	"h5":         true,
46
+	"h6":         true,
47
+	"head":       true,
48
+	"header":     true,
49
+	"hgroup":     true,
50
+	"hr":         true,
51
+	"html":       true,
52
+	"iframe":     true,
53
+	"img":        true,
54
+	"input":      true,
55
+	"isindex":    true,
56
+	"li":         true,
57
+	"link":       true,
58
+	"listing":    true,
59
+	"marquee":    true,
60
+	"menu":       true,
61
+	"meta":       true,
62
+	"nav":        true,
63
+	"noembed":    true,
64
+	"noframes":   true,
65
+	"noscript":   true,
66
+	"object":     true,
67
+	"ol":         true,
68
+	"p":          true,
69
+	"param":      true,
70
+	"plaintext":  true,
71
+	"pre":        true,
72
+	"script":     true,
73
+	"section":    true,
74
+	"select":     true,
75
+	"source":     true,
76
+	"style":      true,
77
+	"summary":    true,
78
+	"table":      true,
79
+	"tbody":      true,
80
+	"td":         true,
81
+	"template":   true,
82
+	"textarea":   true,
83
+	"tfoot":      true,
84
+	"th":         true,
85
+	"thead":      true,
86
+	"title":      true,
87
+	"tr":         true,
88
+	"track":      true,
89
+	"ul":         true,
90
+	"wbr":        true,
91
+	"xmp":        true,
92
+}
93
+
94
+func isSpecialElement(element *Node) bool {
95
+	switch element.Namespace {
96
+	case "", "html":
97
+		return isSpecialElementMap[element.Data]
98
+	case "svg":
99
+		return element.Data == "foreignObject"
100
+	}
101
+	return false
102
+}

+ 106
- 0
vendor/golang.org/x/net/html/doc.go View File

@@ -0,0 +1,106 @@
1
+// Copyright 2010 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+/*
6
+Package html implements an HTML5-compliant tokenizer and parser.
7
+
8
+Tokenization is done by creating a Tokenizer for an io.Reader r. It is the
9
+caller's responsibility to ensure that r provides UTF-8 encoded HTML.
10
+
11
+	z := html.NewTokenizer(r)
12
+
13
+Given a Tokenizer z, the HTML is tokenized by repeatedly calling z.Next(),
14
+which parses the next token and returns its type, or an error:
15
+
16
+	for {
17
+		tt := z.Next()
18
+		if tt == html.ErrorToken {
19
+			// ...
20
+			return ...
21
+		}
22
+		// Process the current token.
23
+	}
24
+
25
+There are two APIs for retrieving the current token. The high-level API is to
26
+call Token; the low-level API is to call Text or TagName / TagAttr. Both APIs
27
+allow optionally calling Raw after Next but before Token, Text, TagName, or
28
+TagAttr. In EBNF notation, the valid call sequence per token is:
29
+
30
+	Next {Raw} [ Token | Text | TagName {TagAttr} ]
31
+
32
+Token returns an independent data structure that completely describes a token.
33
+Entities (such as "&lt;") are unescaped, tag names and attribute keys are
34
+lower-cased, and attributes are collected into a []Attribute. For example:
35
+
36
+	for {
37
+		if z.Next() == html.ErrorToken {
38
+			// Returning io.EOF indicates success.
39
+			return z.Err()
40
+		}
41
+		emitToken(z.Token())
42
+	}
43
+
44
+The low-level API performs fewer allocations and copies, but the contents of
45
+the []byte values returned by Text, TagName and TagAttr may change on the next
46
+call to Next. For example, to extract an HTML page's anchor text:
47
+
48
+	depth := 0
49
+	for {
50
+		tt := z.Next()
51
+		switch tt {
52
+		case ErrorToken:
53
+			return z.Err()
54
+		case TextToken:
55
+			if depth > 0 {
56
+				// emitBytes should copy the []byte it receives,
57
+				// if it doesn't process it immediately.
58
+				emitBytes(z.Text())
59
+			}
60
+		case StartTagToken, EndTagToken:
61
+			tn, _ := z.TagName()
62
+			if len(tn) == 1 && tn[0] == 'a' {
63
+				if tt == StartTagToken {
64
+					depth++
65
+				} else {
66
+					depth--
67
+				}
68
+			}
69
+		}
70
+	}
71
+
72
+Parsing is done by calling Parse with an io.Reader, which returns the root of
73
+the parse tree (the document element) as a *Node. It is the caller's
74
+responsibility to ensure that the Reader provides UTF-8 encoded HTML. For
75
+example, to process each anchor node in depth-first order:
76
+
77
+	doc, err := html.Parse(r)
78
+	if err != nil {
79
+		// ...
80
+	}
81
+	var f func(*html.Node)
82
+	f = func(n *html.Node) {
83
+		if n.Type == html.ElementNode && n.Data == "a" {
84
+			// Do something with n...
85
+		}
86
+		for c := n.FirstChild; c != nil; c = c.NextSibling {
87
+			f(c)
88
+		}
89
+	}
90
+	f(doc)
91
+
92
+The relevant specifications include:
93
+https://html.spec.whatwg.org/multipage/syntax.html and
94
+https://html.spec.whatwg.org/multipage/syntax.html#tokenization
95
+*/
96
+package html // import "golang.org/x/net/html"
97
+
98
+// The tokenization algorithm implemented by this package is not a line-by-line
99
+// transliteration of the relatively verbose state-machine in the WHATWG
100
+// specification. A more direct approach is used instead, where the program
101
+// counter implies the state, such as whether it is tokenizing a tag or a text
102
+// node. Specification compliance is verified by checking expected and actual
103
+// outputs over a test suite rather than aiming for algorithmic fidelity.
104
+
105
+// TODO(nigeltao): Does a DOM API belong in this package or a separate one?
106
+// TODO(nigeltao): How does parsing interact with a JavaScript engine?

+ 156
- 0
vendor/golang.org/x/net/html/doctype.go View File

@@ -0,0 +1,156 @@
1
+// Copyright 2011 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package html
6
+
7
+import (
8
+	"strings"
9
+)
10
+
11
+// parseDoctype parses the data from a DoctypeToken into a name,
12
+// public identifier, and system identifier. It returns a Node whose Type
13
+// is DoctypeNode, whose Data is the name, and which has attributes
14
+// named "system" and "public" for the two identifiers if they were present.
15
+// quirks is whether the document should be parsed in "quirks mode".
16
+func parseDoctype(s string) (n *Node, quirks bool) {
17
+	n = &Node{Type: DoctypeNode}
18
+
19
+	// Find the name.
20
+	space := strings.IndexAny(s, whitespace)
21
+	if space == -1 {
22
+		space = len(s)
23
+	}
24
+	n.Data = s[:space]
25
+	// The comparison to "html" is case-sensitive.
26
+	if n.Data != "html" {
27
+		quirks = true
28
+	}
29
+	n.Data = strings.ToLower(n.Data)
30
+	s = strings.TrimLeft(s[space:], whitespace)
31
+
32
+	if len(s) < 6 {
33
+		// It can't start with "PUBLIC" or "SYSTEM".
34
+		// Ignore the rest of the string.
35
+		return n, quirks || s != ""
36
+	}
37
+
38
+	key := strings.ToLower(s[:6])
39
+	s = s[6:]
40
+	for key == "public" || key == "system" {
41
+		s = strings.TrimLeft(s, whitespace)
42
+		if s == "" {
43
+			break
44
+		}
45
+		quote := s[0]
46
+		if quote != '"' && quote != '\'' {
47
+			break
48
+		}
49
+		s = s[1:]
50
+		q := strings.IndexRune(s, rune(quote))
51
+		var id string
52
+		if q == -1 {
53
+			id = s
54
+			s = ""
55
+		} else {
56
+			id = s[:q]
57
+			s = s[q+1:]
58
+		}
59
+		n.Attr = append(n.Attr, Attribute{Key: key, Val: id})
60
+		if key == "public" {
61
+			key = "system"
62
+		} else {
63
+			key = ""
64
+		}
65
+	}
66
+
67
+	if key != "" || s != "" {
68
+		quirks = true
69
+	} else if len(n.Attr) > 0 {
70
+		if n.Attr[0].Key == "public" {
71
+			public := strings.ToLower(n.Attr[0].Val)
72
+			switch public {
73
+			case "-//w3o//dtd w3 html strict 3.0//en//", "-/w3d/dtd html 4.0 transitional/en", "html":
74
+				quirks = true
75
+			default:
76
+				for _, q := range quirkyIDs {
77
+					if strings.HasPrefix(public, q) {
78
+						quirks = true
79
+						break
80
+					}
81
+				}
82
+			}
83
+			// The following two public IDs only cause quirks mode if there is no system ID.
84
+			if len(n.Attr) == 1 && (strings.HasPrefix(public, "-//w3c//dtd html 4.01 frameset//") ||
85
+				strings.HasPrefix(public, "-//w3c//dtd html 4.01 transitional//")) {
86
+				quirks = true
87
+			}
88
+		}
89
+		if lastAttr := n.Attr[len(n.Attr)-1]; lastAttr.Key == "system" &&
90
+			strings.ToLower(lastAttr.Val) == "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd" {
91
+			quirks = true
92
+		}
93
+	}
94
+
95
+	return n, quirks
96
+}
97
+
98
+// quirkyIDs is a list of public doctype identifiers that cause a document
99
+// to be interpreted in quirks mode. The identifiers should be in lower case.
100
+var quirkyIDs = []string{
101
+	"+//silmaril//dtd html pro v0r11 19970101//",
102
+	"-//advasoft ltd//dtd html 3.0 aswedit + extensions//",
103
+	"-//as//dtd html 3.0 aswedit + extensions//",
104
+	"-//ietf//dtd html 2.0 level 1//",
105
+	"-//ietf//dtd html 2.0 level 2//",
106
+	"-//ietf//dtd html 2.0 strict level 1//",
107
+	"-//ietf//dtd html 2.0 strict level 2//",
108
+	"-//ietf//dtd html 2.0 strict//",
109
+	"-//ietf//dtd html 2.0//",
110
+	"-//ietf//dtd html 2.1e//",
111
+	"-//ietf//dtd html 3.0//",
112
+	"-//ietf//dtd html 3.2 final//",
113
+	"-//ietf//dtd html 3.2//",
114
+	"-//ietf//dtd html 3//",
115
+	"-//ietf//dtd html level 0//",
116
+	"-//ietf//dtd html level 1//",
117
+	"-//ietf//dtd html level 2//",
118
+	"-//ietf//dtd html level 3//",
119
+	"-//ietf//dtd html strict level 0//",
120
+	"-//ietf//dtd html strict level 1//",
121
+	"-//ietf//dtd html strict level 2//",
122
+	"-//ietf//dtd html strict level 3//",
123
+	"-//ietf//dtd html strict//",
124
+	"-//ietf//dtd html//",
125
+	"-//metrius//dtd metrius presentational//",
126
+	"-//microsoft//dtd internet explorer 2.0 html strict//",
127
+	"-//microsoft//dtd internet explorer 2.0 html//",
128
+	"-//microsoft//dtd internet explorer 2.0 tables//",
129
+	"-//microsoft//dtd internet explorer 3.0 html strict//",
130
+	"-//microsoft//dtd internet explorer 3.0 html//",
131
+	"-//microsoft//dtd internet explorer 3.0 tables//",
132
+	"-//netscape comm. corp.//dtd html//",
133
+	"-//netscape comm. corp.//dtd strict html//",
134
+	"-//o'reilly and associates//dtd html 2.0//",
135
+	"-//o'reilly and associates//dtd html extended 1.0//",
136
+	"-//o'reilly and associates//dtd html extended relaxed 1.0//",
137
+	"-//softquad software//dtd hotmetal pro 6.0::19990601::extensions to html 4.0//",
138
+	"-//softquad//dtd hotmetal pro 4.0::19971010::extensions to html 4.0//",
139
+	"-//spyglass//dtd html 2.0 extended//",
140
+	"-//sq//dtd html 2.0 hotmetal + extensions//",
141
+	"-//sun microsystems corp.//dtd hotjava html//",
142
+	"-//sun microsystems corp.//dtd hotjava strict html//",
143
+	"-//w3c//dtd html 3 1995-03-24//",
144
+	"-//w3c//dtd html 3.2 draft//",
145
+	"-//w3c//dtd html 3.2 final//",
146
+	"-//w3c//dtd html 3.2//",
147
+	"-//w3c//dtd html 3.2s draft//",
148
+	"-//w3c//dtd html 4.0 frameset//",
149
+	"-//w3c//dtd html 4.0 transitional//",
150
+	"-//w3c//dtd html experimental 19960712//",
151
+	"-//w3c//dtd html experimental 970421//",
152
+	"-//w3c//dtd w3 html//",
153
+	"-//w3o//dtd w3 html 3.0//",
154
+	"-//webtechs//dtd mozilla html 2.0//",
155
+	"-//webtechs//dtd mozilla html//",
156
+}

+ 2253
- 0
vendor/golang.org/x/net/html/entity.go
File diff suppressed because it is too large
View File


+ 29
- 0
vendor/golang.org/x/net/html/entity_test.go View File

@@ -0,0 +1,29 @@
1
+// Copyright 2010 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package html
6
+
7
+import (
8
+	"testing"
9
+	"unicode/utf8"
10
+)
11
+
12
+func TestEntityLength(t *testing.T) {
13
+	// We verify that the length of UTF-8 encoding of each value is <= 1 + len(key).
14
+	// The +1 comes from the leading "&". This property implies that the length of
15
+	// unescaped text is <= the length of escaped text.
16
+	for k, v := range entity {
17
+		if 1+len(k) < utf8.RuneLen(v) {
18
+			t.Error("escaped entity &" + k + " is shorter than its UTF-8 encoding " + string(v))
19
+		}
20
+		if len(k) > longestEntityWithoutSemicolon && k[len(k)-1] != ';' {
21
+			t.Errorf("entity name %s is %d characters, but longestEntityWithoutSemicolon=%d", k, len(k), longestEntityWithoutSemicolon)
22
+		}
23
+	}
24
+	for k, v := range entity2 {
25
+		if 1+len(k) < utf8.RuneLen(v[0])+utf8.RuneLen(v[1]) {
26
+			t.Error("escaped entity &" + k + " is shorter than its UTF-8 encoding " + string(v[0]) + string(v[1]))
27
+		}
28
+	}
29
+}

+ 258
- 0
vendor/golang.org/x/net/html/escape.go View File

@@ -0,0 +1,258 @@
1
+// Copyright 2010 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package html
6
+
7
+import (
8
+	"bytes"
9
+	"strings"
10
+	"unicode/utf8"
11
+)
12
+
13
+// These replacements permit compatibility with old numeric entities that
14
+// assumed Windows-1252 encoding.
15
+// https://html.spec.whatwg.org/multipage/syntax.html#consume-a-character-reference
16
+var replacementTable = [...]rune{
17
+	'\u20AC', // First entry is what 0x80 should be replaced with.
18
+	'\u0081',
19
+	'\u201A',
20
+	'\u0192',
21
+	'\u201E',
22
+	'\u2026',
23
+	'\u2020',
24
+	'\u2021',
25
+	'\u02C6',
26
+	'\u2030',
27
+	'\u0160',
28
+	'\u2039',
29
+	'\u0152',
30
+	'\u008D',
31
+	'\u017D',
32
+	'\u008F',
33
+	'\u0090',
34
+	'\u2018',
35
+	'\u2019',
36
+	'\u201C',
37
+	'\u201D',
38
+	'\u2022',
39
+	'\u2013',
40
+	'\u2014',
41
+	'\u02DC',
42
+	'\u2122',
43
+	'\u0161',
44
+	'\u203A',
45
+	'\u0153',
46
+	'\u009D',
47
+	'\u017E',
48
+	'\u0178', // Last entry is 0x9F.
49
+	// 0x00->'\uFFFD' is handled programmatically.
50
+	// 0x0D->'\u000D' is a no-op.
51
+}
52
+
53
+// unescapeEntity reads an entity like "&lt;" from b[src:] and writes the
54
+// corresponding "<" to b[dst:], returning the incremented dst and src cursors.
55
+// Precondition: b[src] == '&' && dst <= src.
56
+// attribute should be true if parsing an attribute value.
57
+func unescapeEntity(b []byte, dst, src int, attribute bool) (dst1, src1 int) {
58
+	// https://html.spec.whatwg.org/multipage/syntax.html#consume-a-character-reference
59
+
60
+	// i starts at 1 because we already know that s[0] == '&'.
61
+	i, s := 1, b[src:]
62
+
63
+	if len(s) <= 1 {
64
+		b[dst] = b[src]
65
+		return dst + 1, src + 1
66
+	}
67
+
68
+	if s[i] == '#' {
69
+		if len(s) <= 3 { // We need to have at least "&#.".
70
+			b[dst] = b[src]
71
+			return dst + 1, src + 1
72
+		}
73
+		i++
74
+		c := s[i]
75
+		hex := false
76
+		if c == 'x' || c == 'X' {
77
+			hex = true
78
+			i++
79
+		}
80
+
81
+		x := '\x00'
82
+		for i < len(s) {
83
+			c = s[i]
84
+			i++
85
+			if hex {
86
+				if '0' <= c && c <= '9' {
87
+					x = 16*x + rune(c) - '0'
88
+					continue
89
+				} else if 'a' <= c && c <= 'f' {
90
+					x = 16*x + rune(c) - 'a' + 10
91
+					continue
92
+				} else if 'A' <= c && c <= 'F' {
93
+					x = 16*x + rune(c) - 'A' + 10
94
+					continue
95
+				}
96
+			} else if '0' <= c && c <= '9' {
97
+				x = 10*x + rune(c) - '0'
98
+				continue
99
+			}
100
+			if c != ';' {
101
+				i--
102
+			}
103
+			break
104
+		}
105
+
106
+		if i <= 3 { // No characters matched.
107
+			b[dst] = b[src]
108
+			return dst + 1, src + 1
109
+		}
110
+
111
+		if 0x80 <= x && x <= 0x9F {
112
+			// Replace characters from Windows-1252 with UTF-8 equivalents.
113
+			x = replacementTable[x-0x80]
114
+		} else if x == 0 || (0xD800 <= x && x <= 0xDFFF) || x > 0x10FFFF {
115
+			// Replace invalid characters with the replacement character.
116
+			x = '\uFFFD'
117
+		}
118
+
119
+		return dst + utf8.EncodeRune(b[dst:], x), src + i
120
+	}
121
+
122
+	// Consume the maximum number of characters possible, with the
123
+	// consumed characters matching one of the named references.
124
+
125
+	for i < len(s) {
126
+		c := s[i]
127
+		i++
128
+		// Lower-cased characters are more common in entities, so we check for them first.
129
+		if 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || '0' <= c && c <= '9' {
130
+			continue
131
+		}
132
+		if c != ';' {
133
+			i--
134
+		}
135
+		break
136
+	}
137
+
138
+	entityName := string(s[1:i])
139
+	if entityName == "" {
140
+		// No-op.
141
+	} else if attribute && entityName[len(entityName)-1] != ';' && len(s) > i && s[i] == '=' {
142
+		// No-op.
143
+	} else if x := entity[entityName]; x != 0 {
144
+		return dst + utf8.EncodeRune(b[dst:], x), src + i
145
+	} else if x := entity2[entityName]; x[0] != 0 {
146
+		dst1 := dst + utf8.EncodeRune(b[dst:], x[0])
147
+		return dst1 + utf8.EncodeRune(b[dst1:], x[1]), src + i
148
+	} else if !attribute {
149
+		maxLen := len(entityName) - 1
150
+		if maxLen > longestEntityWithoutSemicolon {
151
+			maxLen = longestEntityWithoutSemicolon
152
+		}
153
+		for j := maxLen; j > 1; j-- {
154
+			if x := entity[entityName[:j]]; x != 0 {
155
+				return dst + utf8.EncodeRune(b[dst:], x), src + j + 1
156
+			}
157
+		}
158
+	}
159
+
160
+	dst1, src1 = dst+i, src+i
161
+	copy(b[dst:dst1], b[src:src1])
162
+	return dst1, src1
163
+}
164
+
165
+// unescape unescapes b's entities in-place, so that "a&lt;b" becomes "a<b".
166
+// attribute should be true if parsing an attribute value.
167
+func unescape(b []byte, attribute bool) []byte {
168
+	for i, c := range b {
169
+		if c == '&' {
170
+			dst, src := unescapeEntity(b, i, i, attribute)
171
+			for src < len(b) {
172
+				c := b[src]
173
+				if c == '&' {
174
+					dst, src = unescapeEntity(b, dst, src, attribute)
175
+				} else {
176
+					b[dst] = c
177
+					dst, src = dst+1, src+1
178
+				}
179
+			}
180
+			return b[0:dst]
181
+		}
182
+	}
183
+	return b
184
+}
185
+
186
+// lower lower-cases the A-Z bytes in b in-place, so that "aBc" becomes "abc".
187
+func lower(b []byte) []byte {
188
+	for i, c := range b {
189
+		if 'A' <= c && c <= 'Z' {
190
+			b[i] = c + 'a' - 'A'
191
+		}
192
+	}
193
+	return b
194
+}
195
+
196
+const escapedChars = "&'<>\"\r"
197
+
198
+func escape(w writer, s string) error {
199
+	i := strings.IndexAny(s, escapedChars)
200
+	for i != -1 {
201
+		if _, err := w.WriteString(s[:i]); err != nil {
202
+			return err
203
+		}
204
+		var esc string
205
+		switch s[i] {
206
+		case '&':
207
+			esc = "&amp;"
208
+		case '\'':
209
+			// "&#39;" is shorter than "&apos;" and apos was not in HTML until HTML5.
210
+			esc = "&#39;"
211
+		case '<':
212
+			esc = "&lt;"
213
+		case '>':
214
+			esc = "&gt;"
215
+		case '"':
216
+			// "&#34;" is shorter than "&quot;".
217
+			esc = "&#34;"
218
+		case '\r':
219
+			esc = "&#13;"
220
+		default:
221
+			panic("unrecognized escape character")
222
+		}
223
+		s = s[i+1:]
224
+		if _, err := w.WriteString(esc); err != nil {
225
+			return err
226
+		}
227
+		i = strings.IndexAny(s, escapedChars)
228
+	}
229
+	_, err := w.WriteString(s)
230
+	return err
231
+}
232
+
233
+// EscapeString escapes special characters like "<" to become "&lt;". It
234
+// escapes only five such characters: <, >, &, ' and ".
235
+// UnescapeString(EscapeString(s)) == s always holds, but the converse isn't
236
+// always true.
237
+func EscapeString(s string) string {
238
+	if strings.IndexAny(s, escapedChars) == -1 {
239
+		return s
240
+	}
241
+	var buf bytes.Buffer
242
+	escape(&buf, s)
243
+	return buf.String()
244
+}
245
+
246
+// UnescapeString unescapes entities like "&lt;" to become "<". It unescapes a
247
+// larger range of entities than EscapeString escapes. For example, "&aacute;"
248
+// unescapes to "á", as does "&#225;" and "&xE1;".
249
+// UnescapeString(EscapeString(s)) == s always holds, but the converse isn't
250
+// always true.
251
+func UnescapeString(s string) string {
252
+	for _, c := range s {
253
+		if c == '&' {
254
+			return string(unescape([]byte(s), false))
255
+		}
256
+	}
257
+	return s
258
+}

+ 97
- 0
vendor/golang.org/x/net/html/escape_test.go View File

@@ -0,0 +1,97 @@
1
+// Copyright 2013 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package html
6
+
7
+import "testing"
8
+
9
+type unescapeTest struct {
10
+	// A short description of the test case.
11
+	desc string
12
+	// The HTML text.
13
+	html string
14
+	// The unescaped text.
15
+	unescaped string
16
+}
17
+
18
+var unescapeTests = []unescapeTest{
19
+	// Handle no entities.
20
+	{
21
+		"copy",
22
+		"A\ttext\nstring",
23
+		"A\ttext\nstring",
24
+	},
25
+	// Handle simple named entities.
26
+	{
27
+		"simple",
28
+		"&amp; &gt; &lt;",
29
+		"& > <",
30
+	},
31
+	// Handle hitting the end of the string.
32
+	{
33
+		"stringEnd",
34
+		"&amp &amp",
35
+		"& &",
36
+	},
37
+	// Handle entities with two codepoints.
38
+	{
39
+		"multiCodepoint",
40
+		"text &gesl; blah",
41
+		"text \u22db\ufe00 blah",
42
+	},
43
+	// Handle decimal numeric entities.
44
+	{
45
+		"decimalEntity",
46
+		"Delta = &#916; ",
47
+		"Delta = Δ ",
48
+	},
49
+	// Handle hexadecimal numeric entities.
50
+	{
51
+		"hexadecimalEntity",
52
+		"Lambda = &#x3bb; = &#X3Bb ",
53
+		"Lambda = λ = λ ",
54
+	},
55
+	// Handle numeric early termination.
56
+	{
57
+		"numericEnds",
58
+		"&# &#x &#128;43 &copy = &#169f = &#xa9",
59
+		"&# &#x €43 © = ©f = ©",
60
+	},
61
+	// Handle numeric ISO-8859-1 entity replacements.
62
+	{
63
+		"numericReplacements",
64
+		"Footnote&#x87;",
65
+		"Footnote‡",
66
+	},
67
+}
68
+
69
+func TestUnescape(t *testing.T) {
70
+	for _, tt := range unescapeTests {
71
+		unescaped := UnescapeString(tt.html)
72
+		if unescaped != tt.unescaped {
73
+			t.Errorf("TestUnescape %s: want %q, got %q", tt.desc, tt.unescaped, unescaped)
74
+		}
75
+	}
76
+}
77
+
78
+func TestUnescapeEscape(t *testing.T) {
79
+	ss := []string{
80
+		``,
81
+		`abc def`,
82
+		`a & b`,
83
+		`a&amp;b`,
84
+		`a &amp b`,
85
+		`&quot;`,
86
+		`"`,
87
+		`"<&>"`,
88
+		`&quot;&lt;&amp;&gt;&quot;`,
89
+		`3&5==1 && 0<1, "0&lt;1", a+acute=&aacute;`,
90
+		`The special characters are: <, >, &, ' and "`,
91
+	}
92
+	for _, s := range ss {
93
+		if got := UnescapeString(EscapeString(s)); got != s {
94
+			t.Errorf("got %q want %q", got, s)
95
+		}
96
+	}
97
+}

+ 40
- 0
vendor/golang.org/x/net/html/example_test.go View File

@@ -0,0 +1,40 @@
1
+// Copyright 2012 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+// This example demonstrates parsing HTML data and walking the resulting tree.
6
+package html_test
7
+
8
+import (
9
+	"fmt"
10
+	"log"
11
+	"strings"
12
+
13
+	"golang.org/x/net/html"
14
+)
15
+
16
+func ExampleParse() {
17
+	s := `<p>Links:</p><ul><li><a href="foo">Foo</a><li><a href="/bar/baz">BarBaz</a></ul>`
18
+	doc, err := html.Parse(strings.NewReader(s))
19
+	if err != nil {
20
+		log.Fatal(err)
21
+	}
22
+	var f func(*html.Node)
23
+	f = func(n *html.Node) {
24
+		if n.Type == html.ElementNode && n.Data == "a" {
25
+			for _, a := range n.Attr {
26
+				if a.Key == "href" {
27
+					fmt.Println(a.Val)
28
+					break
29
+				}
30
+			}
31
+		}
32
+		for c := n.FirstChild; c != nil; c = c.NextSibling {
33
+			f(c)
34
+		}
35
+	}
36
+	f(doc)
37
+	// Output:
38
+	// foo
39
+	// /bar/baz
40
+}

+ 226
- 0
vendor/golang.org/x/net/html/foreign.go View File

@@ -0,0 +1,226 @@
1
+// Copyright 2011 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package html
6
+
7
+import (
8
+	"strings"
9
+)
10
+
11
+func adjustAttributeNames(aa []Attribute, nameMap map[string]string) {
12
+	for i := range aa {
13
+		if newName, ok := nameMap[aa[i].Key]; ok {
14
+			aa[i].Key = newName
15
+		}
16
+	}
17
+}
18
+
19
+func adjustForeignAttributes(aa []Attribute) {
20
+	for i, a := range aa {
21
+		if a.Key == "" || a.Key[0] != 'x' {
22
+			continue
23
+		}
24
+		switch a.Key {
25
+		case "xlink:actuate", "xlink:arcrole", "xlink:href", "xlink:role", "xlink:show",
26
+			"xlink:title", "xlink:type", "xml:base", "xml:lang", "xml:space", "xmlns:xlink":
27
+			j := strings.Index(a.Key, ":")
28
+			aa[i].Namespace = a.Key[:j]
29
+			aa[i].Key = a.Key[j+1:]
30
+		}
31
+	}
32
+}
33
+
34
+func htmlIntegrationPoint(n *Node) bool {
35
+	if n.Type != ElementNode {
36
+		return false
37
+	}
38
+	switch n.Namespace {
39
+	case "math":
40
+		if n.Data == "annotation-xml" {
41
+			for _, a := range n.Attr {
42
+				if a.Key == "encoding" {
43
+					val := strings.ToLower(a.Val)
44
+					if val == "text/html" || val == "application/xhtml+xml" {
45
+						return true
46
+					}
47
+				}
48
+			}
49
+		}
50
+	case "svg":
51
+		switch n.Data {
52
+		case "desc", "foreignObject", "title":
53
+			return true
54
+		}
55
+	}
56
+	return false
57
+}
58
+
59
+func mathMLTextIntegrationPoint(n *Node) bool {
60
+	if n.Namespace != "math" {
61
+		return false
62
+	}
63
+	switch n.Data {
64
+	case "mi", "mo", "mn", "ms", "mtext":
65
+		return true
66
+	}
67
+	return false
68
+}
69
+
70
+// Section 12.2.5.5.
71
+var breakout = map[string]bool{
72
+	"b":          true,
73
+	"big":        true,
74
+	"blockquote": true,
75
+	"body":       true,
76
+	"br":         true,
77
+	"center":     true,
78
+	"code":       true,
79
+	"dd":         true,
80
+	"div":        true,
81
+	"dl":         true,
82
+	"dt":         true,
83
+	"em":         true,
84
+	"embed":      true,
85
+	"h1":         true,
86
+	"h2":         true,
87
+	"h3":         true,
88
+	"h4":         true,
89
+	"h5":         true,
90
+	"h6":         true,
91
+	"head":       true,
92
+	"hr":         true,
93
+	"i":          true,
94
+	"img":        true,
95
+	"li":         true,
96
+	"listing":    true,
97
+	"menu":       true,
98
+	"meta":       true,
99
+	"nobr":       true,
100
+	"ol":         true,
101
+	"p":          true,
102
+	"pre":        true,
103
+	"ruby":       true,
104
+	"s":          true,
105
+	"small":      true,
106
+	"span":       true,
107
+	"strong":     true,
108
+	"strike":     true,
109
+	"sub":        true,
110
+	"sup":        true,
111
+	"table":      true,
112
+	"tt":         true,
113
+	"u":          true,
114
+	"ul":         true,
115
+	"var":        true,
116
+}
117
+
118
+// Section 12.2.5.5.
119
+var svgTagNameAdjustments = map[string]string{
120
+	"altglyph":            "altGlyph",
121
+	"altglyphdef":         "altGlyphDef",
122
+	"altglyphitem":        "altGlyphItem",
123
+	"animatecolor":        "animateColor",
124
+	"animatemotion":       "animateMotion",
125
+	"animatetransform":    "animateTransform",
126
+	"clippath":            "clipPath",
127
+	"feblend":             "feBlend",
128
+	"fecolormatrix":       "feColorMatrix",
129
+	"fecomponenttransfer": "feComponentTransfer",
130
+	"fecomposite":         "feComposite",
131
+	"feconvolvematrix":    "feConvolveMatrix",
132
+	"fediffuselighting":   "feDiffuseLighting",
133
+	"fedisplacementmap":   "feDisplacementMap",
134
+	"fedistantlight":      "feDistantLight",
135
+	"feflood":             "feFlood",
136
+	"fefunca":             "feFuncA",
137
+	"fefuncb":             "feFuncB",
138
+	"fefuncg":             "feFuncG",
139
+	"fefuncr":             "feFuncR",
140
+	"fegaussianblur":      "feGaussianBlur",
141
+	"feimage":             "feImage",
142
+	"femerge":             "feMerge",
143
+	"femergenode":         "feMergeNode",
144
+	"femorphology":        "feMorphology",
145
+	"feoffset":            "feOffset",
146
+	"fepointlight":        "fePointLight",
147
+	"fespecularlighting":  "feSpecularLighting",
148
+	"fespotlight":         "feSpotLight",
149
+	"fetile":              "feTile",
150
+	"feturbulence":        "feTurbulence",
151
+	"foreignobject":       "foreignObject",
152
+	"glyphref":            "glyphRef",
153
+	"lineargradient":      "linearGradient",
154
+	"radialgradient":      "radialGradient",
155
+	"textpath":            "textPath",
156
+}
157
+
158
+// Section 12.2.5.1
159
+var mathMLAttributeAdjustments = map[string]string{
160
+	"definitionurl": "definitionURL",
161
+}
162
+
163
+var svgAttributeAdjustments = map[string]string{
164
+	"attributename":             "attributeName",
165
+	"attributetype":             "attributeType",
166
+	"basefrequency":             "baseFrequency",
167
+	"baseprofile":               "baseProfile",
168
+	"calcmode":                  "calcMode",
169
+	"clippathunits":             "clipPathUnits",
170
+	"contentscripttype":         "contentScriptType",
171
+	"contentstyletype":          "contentStyleType",
172
+	"diffuseconstant":           "diffuseConstant",
173
+	"edgemode":                  "edgeMode",
174
+	"externalresourcesrequired": "externalResourcesRequired",
175
+	"filterres":                 "filterRes",
176
+	"filterunits":               "filterUnits",
177
+	"glyphref":                  "glyphRef",
178
+	"gradienttransform":         "gradientTransform",
179
+	"gradientunits":             "gradientUnits",
180
+	"kernelmatrix":              "kernelMatrix",
181
+	"kernelunitlength":          "kernelUnitLength",
182
+	"keypoints":                 "keyPoints",
183
+	"keysplines":                "keySplines",
184
+	"keytimes":                  "keyTimes",
185
+	"lengthadjust":              "lengthAdjust",
186
+	"limitingconeangle":         "limitingConeAngle",
187
+	"markerheight":              "markerHeight",
188
+	"markerunits":               "markerUnits",
189
+	"markerwidth":               "markerWidth",
190
+	"maskcontentunits":          "maskContentUnits",
191
+	"maskunits":                 "maskUnits",
192
+	"numoctaves":                "numOctaves",
193
+	"pathlength":                "pathLength",
194
+	"patterncontentunits":       "patternContentUnits",
195
+	"patterntransform":          "patternTransform",
196
+	"patternunits":              "patternUnits",
197
+	"pointsatx":                 "pointsAtX",
198
+	"pointsaty":                 "pointsAtY",
199
+	"pointsatz":                 "pointsAtZ",
200
+	"preservealpha":             "preserveAlpha",
201
+	"preserveaspectratio":       "preserveAspectRatio",
202
+	"primitiveunits":            "primitiveUnits",
203
+	"refx":                      "refX",
204
+	"refy":                      "refY",
205
+	"repeatcount":               "repeatCount",
206
+	"repeatdur":                 "repeatDur",
207
+	"requiredextensions":        "requiredExtensions",
208
+	"requiredfeatures":          "requiredFeatures",
209
+	"specularconstant":          "specularConstant",
210
+	"specularexponent":          "specularExponent",
211
+	"spreadmethod":              "spreadMethod",
212
+	"startoffset":               "startOffset",
213
+	"stddeviation":              "stdDeviation",
214
+	"stitchtiles":               "stitchTiles",
215
+	"surfacescale":              "surfaceScale",
216
+	"systemlanguage":            "systemLanguage",
217
+	"tablevalues":               "tableValues",
218
+	"targetx":                   "targetX",
219
+	"targety":                   "targetY",
220
+	"textlength":                "textLength",
221
+	"viewbox":                   "viewBox",
222
+	"viewtarget":                "viewTarget",
223
+	"xchannelselector":          "xChannelSelector",
224
+	"ychannelselector":          "yChannelSelector",
225
+	"zoomandpan":                "zoomAndPan",
226
+}

+ 193
- 0
vendor/golang.org/x/net/html/node.go View File

@@ -0,0 +1,193 @@
1
+// Copyright 2011 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package html
6
+
7
+import (
8
+	"golang.org/x/net/html/atom"
9
+)
10
+
11
+// A NodeType is the type of a Node.
12
+type NodeType uint32
13
+
14
+const (
15
+	ErrorNode NodeType = iota
16
+	TextNode
17
+	DocumentNode
18
+	ElementNode
19
+	CommentNode
20
+	DoctypeNode
21
+	scopeMarkerNode
22
+)
23
+
24
+// Section 12.2.3.3 says "scope markers are inserted when entering applet
25
+// elements, buttons, object elements, marquees, table cells, and table
26
+// captions, and are used to prevent formatting from 'leaking'".
27
+var scopeMarker = Node{Type: scopeMarkerNode}
28
+
29
+// A Node consists of a NodeType and some Data (tag name for element nodes,
30
+// content for text) and are part of a tree of Nodes. Element nodes may also
31
+// have a Namespace and contain a slice of Attributes. Data is unescaped, so
32
+// that it looks like "a<b" rather than "a&lt;b". For element nodes, DataAtom
33
+// is the atom for Data, or zero if Data is not a known tag name.
34
+//
35
+// An empty Namespace implies a "http://www.w3.org/1999/xhtml" namespace.
36
+// Similarly, "math" is short for "http://www.w3.org/1998/Math/MathML", and
37
+// "svg" is short for "http://www.w3.org/2000/svg".
38
+type Node struct {
39
+	Parent, FirstChild, LastChild, PrevSibling, NextSibling *Node
40
+
41
+	Type      NodeType
42
+	DataAtom  atom.Atom
43
+	Data      string
44
+	Namespace string
45
+	Attr      []Attribute
46
+}
47
+
48
+// InsertBefore inserts newChild as a child of n, immediately before oldChild
49
+// in the sequence of n's children. oldChild may be nil, in which case newChild
50
+// is appended to the end of n's children.
51
+//
52
+// It will panic if newChild already has a parent or siblings.
53
+func (n *Node) InsertBefore(newChild, oldChild *Node) {
54
+	if newChild.Parent != nil || newChild.PrevSibling != nil || newChild.NextSibling != nil {
55
+		panic("html: InsertBefore called for an attached child Node")
56
+	}
57
+	var prev, next *Node
58
+	if oldChild != nil {
59
+		prev, next = oldChild.PrevSibling, oldChild
60
+	} else {
61
+		prev = n.LastChild
62
+	}
63
+	if prev != nil {
64
+		prev.NextSibling = newChild
65
+	} else {
66
+		n.FirstChild = newChild
67
+	}
68
+	if next != nil {
69
+		next.PrevSibling = newChild
70
+	} else {
71
+		n.LastChild = newChild
72
+	}
73
+	newChild.Parent = n
74
+	newChild.PrevSibling = prev
75
+	newChild.NextSibling = next
76
+}
77
+
78
+// AppendChild adds a node c as a child of n.
79
+//
80
+// It will panic if c already has a parent or siblings.
81
+func (n *Node) AppendChild(c *Node) {
82
+	if c.Parent != nil || c.PrevSibling != nil || c.NextSibling != nil {
83
+		panic("html: AppendChild called for an attached child Node")
84
+	}
85
+	last := n.LastChild
86
+	if last != nil {
87
+		last.NextSibling = c
88
+	} else {
89
+		n.FirstChild = c
90
+	}
91
+	n.LastChild = c
92
+	c.Parent = n
93
+	c.PrevSibling = last
94
+}
95
+
96
+// RemoveChild removes a node c that is a child of n. Afterwards, c will have
97
+// no parent and no siblings.
98
+//
99
+// It will panic if c's parent is not n.
100
+func (n *Node) RemoveChild(c *Node) {
101
+	if c.Parent != n {
102
+		panic("html: RemoveChild called for a non-child Node")
103
+	}
104
+	if n.FirstChild == c {
105
+		n.FirstChild = c.NextSibling
106
+	}
107
+	if c.NextSibling != nil {
108
+		c.NextSibling.PrevSibling = c.PrevSibling
109
+	}
110
+	if n.LastChild == c {
111
+		n.LastChild = c.PrevSibling
112
+	}
113
+	if c.PrevSibling != nil {
114
+		c.PrevSibling.NextSibling = c.NextSibling
115
+	}
116
+	c.Parent = nil
117
+	c.PrevSibling = nil
118
+	c.NextSibling = nil
119
+}
120
+
121
+// reparentChildren reparents all of src's child nodes to dst.
122
+func reparentChildren(dst, src *Node) {
123
+	for {
124
+		child := src.FirstChild
125
+		if child == nil {
126
+			break
127
+		}
128
+		src.RemoveChild(child)
129
+		dst.AppendChild(child)
130
+	}
131
+}
132
+
133
+// clone returns a new node with the same type, data and attributes.
134
+// The clone has no parent, no siblings and no children.
135
+func (n *Node) clone() *Node {
136
+	m := &Node{
137
+		Type:     n.Type,
138
+		DataAtom: n.DataAtom,
139
+		Data:     n.Data,
140
+		Attr:     make([]Attribute, len(n.Attr)),
141
+	}
142
+	copy(m.Attr, n.Attr)
143
+	return m
144
+}
145
+
146
+// nodeStack is a stack of nodes.
147
+type nodeStack []*Node
148
+
149
+// pop pops the stack. It will panic if s is empty.
150
+func (s *nodeStack) pop() *Node {
151
+	i := len(*s)
152
+	n := (*s)[i-1]
153
+	*s = (*s)[:i-1]
154
+	return n
155
+}
156
+
157
+// top returns the most recently pushed node, or nil if s is empty.
158
+func (s *nodeStack) top() *Node {
159
+	if i := len(*s); i > 0 {
160
+		return (*s)[i-1]
161
+	}
162
+	return nil
163
+}
164
+
165
+// index returns the index of the top-most occurrence of n in the stack, or -1
166
+// if n is not present.
167
+func (s *nodeStack) index(n *Node) int {
168
+	for i := len(*s) - 1; i >= 0; i-- {
169
+		if (*s)[i] == n {
170
+			return i
171
+		}
172
+	}
173
+	return -1
174
+}
175
+
176
+// insert inserts a node at the given index.
177
+func (s *nodeStack) insert(i int, n *Node) {
178
+	(*s) = append(*s, nil)
179
+	copy((*s)[i+1:], (*s)[i:])
180
+	(*s)[i] = n
181
+}
182
+
183
+// remove removes a node from the stack. It is a no-op if n is not present.
184
+func (s *nodeStack) remove(n *Node) {
185
+	i := s.index(n)
186
+	if i == -1 {
187
+		return
188
+	}
189
+	copy((*s)[i:], (*s)[i+1:])
190
+	j := len(*s) - 1
191
+	(*s)[j] = nil
192
+	*s = (*s)[:j]
193
+}

+ 146
- 0
vendor/golang.org/x/net/html/node_test.go View File

@@ -0,0 +1,146 @@
1
+// Copyright 2010 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package html
6
+
7
+import (
8
+	"fmt"
9
+)
10
+
11
+// checkTreeConsistency checks that a node and its descendants are all
12
+// consistent in their parent/child/sibling relationships.
13
+func checkTreeConsistency(n *Node) error {
14
+	return checkTreeConsistency1(n, 0)
15
+}
16
+
17
+func checkTreeConsistency1(n *Node, depth int) error {
18
+	if depth == 1e4 {
19
+		return fmt.Errorf("html: tree looks like it contains a cycle")
20
+	}
21
+	if err := checkNodeConsistency(n); err != nil {
22
+		return err
23
+	}
24
+	for c := n.FirstChild; c != nil; c = c.NextSibling {
25
+		if err := checkTreeConsistency1(c, depth+1); err != nil {
26
+			return err
27
+		}
28
+	}
29
+	return nil
30
+}
31
+
32
+// checkNodeConsistency checks that a node's parent/child/sibling relationships
33
+// are consistent.
34
+func checkNodeConsistency(n *Node) error {
35
+	if n == nil {
36
+		return nil
37
+	}
38
+
39
+	nParent := 0
40
+	for p := n.Parent; p != nil; p = p.Parent {
41
+		nParent++
42
+		if nParent == 1e4 {
43
+			return fmt.Errorf("html: parent list looks like an infinite loop")
44
+		}
45
+	}
46
+
47
+	nForward := 0
48
+	for c := n.FirstChild; c != nil; c = c.NextSibling {
49
+		nForward++
50
+		if nForward == 1e6 {
51
+			return fmt.Errorf("html: forward list of children looks like an infinite loop")
52
+		}
53
+		if c.Parent != n {
54
+			return fmt.Errorf("html: inconsistent child/parent relationship")
55
+		}
56
+	}
57
+
58
+	nBackward := 0
59
+	for c := n.LastChild; c != nil; c = c.PrevSibling {
60
+		nBackward++
61
+		if nBackward == 1e6 {
62
+			return fmt.Errorf("html: backward list of children looks like an infinite loop")
63
+		}
64
+		if c.Parent != n {
65
+			return fmt.Errorf("html: inconsistent child/parent relationship")
66
+		}
67
+	}
68
+
69
+	if n.Parent != nil {
70
+		if n.Parent == n {
71
+			return fmt.Errorf("html: inconsistent parent relationship")
72
+		}
73
+		if n.Parent == n.FirstChild {
74
+			return fmt.Errorf("html: inconsistent parent/first relationship")
75
+		}
76
+		if n.Parent == n.LastChild {
77
+			return fmt.Errorf("html: inconsistent parent/last relationship")
78
+		}
79
+		if n.Parent == n.PrevSibling {
80
+			return fmt.Errorf("html: inconsistent parent/prev relationship")
81
+		}
82
+		if n.Parent == n.NextSibling {
83
+			return fmt.Errorf("html: inconsistent parent/next relationship")
84
+		}
85
+
86
+		parentHasNAsAChild := false
87
+		for c := n.Parent.FirstChild; c != nil; c = c.NextSibling {
88
+			if c == n {
89
+				parentHasNAsAChild = true
90
+				break
91
+			}
92
+		}
93
+		if !parentHasNAsAChild {
94
+			return fmt.Errorf("html: inconsistent parent/child relationship")
95
+		}
96
+	}
97
+
98
+	if n.PrevSibling != nil && n.PrevSibling.NextSibling != n {
99
+		return fmt.Errorf("html: inconsistent prev/next relationship")
100
+	}
101
+	if n.NextSibling != nil && n.NextSibling.PrevSibling != n {
102
+		return fmt.Errorf("html: inconsistent next/prev relationship")
103
+	}
104
+
105
+	if (n.FirstChild == nil) != (n.LastChild == nil) {
106
+		return fmt.Errorf("html: inconsistent first/last relationship")
107
+	}
108
+	if n.FirstChild != nil && n.FirstChild == n.LastChild {
109
+		// We have a sole child.
110
+		if n.FirstChild.PrevSibling != nil || n.FirstChild.NextSibling != nil {
111
+			return fmt.Errorf("html: inconsistent sole child's sibling relationship")
112
+		}
113
+	}
114
+
115
+	seen := map[*Node]bool{}
116
+
117
+	var last *Node
118
+	for c := n.FirstChild; c != nil; c = c.NextSibling {
119
+		if seen[c] {
120
+			return fmt.Errorf("html: inconsistent repeated child")
121
+		}
122
+		seen[c] = true
123
+		last = c
124
+	}
125
+	if last != n.LastChild {
126
+		return fmt.Errorf("html: inconsistent last relationship")
127
+	}
128
+
129
+	var first *Node
130
+	for c := n.LastChild; c != nil; c = c.PrevSibling {
131
+		if !seen[c] {
132
+			return fmt.Errorf("html: inconsistent missing child")
133
+		}
134
+		delete(seen, c)
135
+		first = c
136
+	}
137
+	if first != n.FirstChild {
138
+		return fmt.Errorf("html: inconsistent first relationship")
139
+	}
140
+
141
+	if len(seen) != 0 {
142
+		return fmt.Errorf("html: inconsistent forwards/backwards child list")
143
+	}
144
+
145
+	return nil
146
+}

+ 10
- 0
vendor/golang.org/x/net/html/offset.go View File

@@ -0,0 +1,10 @@
1
+// The Isomorphic Go Project
2
+// Copyright (c) Wirecog, LLC. All rights reserved.
3
+// Use of this source code is governed by a BSD-style
4
+// license, which can be found in the LICENSE file.
5
+
6
+package html
7
+
8
+func (t *Tokenizer) CurrentOffset() [2]int {
9
+	return [2]int{t.data.start, t.data.end}
10
+}

+ 2094
- 0
vendor/golang.org/x/net/html/parse.go
File diff suppressed because it is too large
View File


+ 388
- 0
vendor/golang.org/x/net/html/parse_test.go View File

@@ -0,0 +1,388 @@
1
+// Copyright 2010 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package html
6
+
7
+import (
8
+	"bufio"
9
+	"bytes"
10
+	"errors"
11
+	"fmt"
12
+	"io"
13
+	"io/ioutil"
14
+	"os"
15
+	"path/filepath"
16
+	"runtime"
17
+	"sort"
18
+	"strings"
19
+	"testing"
20
+
21
+	"golang.org/x/net/html/atom"
22
+)
23
+
24
+// readParseTest reads a single test case from r.
25
+func readParseTest(r *bufio.Reader) (text, want, context string, err error) {
26
+	line, err := r.ReadSlice('\n')
27
+	if err != nil {
28
+		return "", "", "", err
29
+	}
30
+	var b []byte
31
+
32
+	// Read the HTML.
33
+	if string(line) != "#data\n" {
34
+		return "", "", "", fmt.Errorf(`got %q want "#data\n"`, line)
35
+	}
36
+	for {
37
+		line, err = r.ReadSlice('\n')
38
+		if err != nil {
39
+			return "", "", "", err
40
+		}
41
+		if line[0] == '#' {
42
+			break
43
+		}
44
+		b = append(b, line...)
45
+	}
46
+	text = strings.TrimSuffix(string(b), "\n")
47
+	b = b[:0]
48
+
49
+	// Skip the error list.
50
+	if string(line) != "#errors\n" {
51
+		return "", "", "", fmt.Errorf(`got %q want "#errors\n"`, line)
52
+	}
53
+	for {
54
+		line, err = r.ReadSlice('\n')
55
+		if err != nil {
56
+			return "", "", "", err
57
+		}
58
+		if line[0] == '#' {
59
+			break
60
+		}
61
+	}
62
+
63
+	if string(line) == "#document-fragment\n" {
64
+		line, err = r.ReadSlice('\n')
65
+		if err != nil {
66
+			return "", "", "", err
67
+		}
68
+		context = strings.TrimSpace(string(line))
69
+		line, err = r.ReadSlice('\n')
70
+		if err != nil {
71
+			return "", "", "", err
72
+		}
73
+	}
74
+
75
+	// Read the dump of what the parse tree should be.
76
+	if string(line) != "#document\n" {
77
+		return "", "", "", fmt.Errorf(`got %q want "#document\n"`, line)
78
+	}
79
+	inQuote := false
80
+	for {
81
+		line, err = r.ReadSlice('\n')
82
+		if err != nil && err != io.EOF {
83
+			return "", "", "", err
84
+		}
85
+		trimmed := bytes.Trim(line, "| \n")
86
+		if len(trimmed) > 0 {
87
+			if line[0] == '|' && trimmed[0] == '"' {
88
+				inQuote = true
89
+			}
90
+			if trimmed[len(trimmed)-1] == '"' && !(line[0] == '|' && len(trimmed) == 1) {
91
+				inQuote = false
92
+			}
93
+		}
94
+		if len(line) == 0 || len(line) == 1 && line[0] == '\n' && !inQuote {
95
+			break
96
+		}
97
+		b = append(b, line...)
98
+	}
99
+	return text, string(b), context, nil
100
+}
101
+
102
+func dumpIndent(w io.Writer, level int) {
103
+	io.WriteString(w, "| ")
104
+	for i := 0; i < level; i++ {
105
+		io.WriteString(w, "  ")
106
+	}
107
+}
108
+
109
+type sortedAttributes []Attribute
110
+
111
+func (a sortedAttributes) Len() int {
112
+	return len(a)
113
+}
114
+
115
+func (a sortedAttributes) Less(i, j int) bool {
116
+	if a[i].Namespace != a[j].Namespace {
117
+		return a[i].Namespace < a[j].Namespace
118
+	}
119
+	return a[i].Key < a[j].Key
120
+}
121
+
122
+func (a sortedAttributes) Swap(i, j int) {
123
+	a[i], a[j] = a[j], a[i]
124
+}
125
+
126
+func dumpLevel(w io.Writer, n *Node, level int) error {
127
+	dumpIndent(w, level)
128
+	switch n.Type {
129
+	case ErrorNode:
130
+		return errors.New("unexpected ErrorNode")
131
+	case DocumentNode:
132
+		return errors.New("unexpected DocumentNode")
133
+	case ElementNode:
134
+		if n.Namespace != "" {
135
+			fmt.Fprintf(w, "<%s %s>", n.Namespace, n.Data)
136
+		} else {
137
+			fmt.Fprintf(w, "<%s>", n.Data)
138
+		}
139
+		attr := sortedAttributes(n.Attr)
140
+		sort.Sort(attr)
141
+		for _, a := range attr {
142
+			io.WriteString(w, "\n")
143
+			dumpIndent(w, level+1)
144
+			if a.Namespace != "" {
145
+				fmt.Fprintf(w, `%s %s="%s"`, a.Namespace, a.Key, a.Val)
146
+			} else {
147
+				fmt.Fprintf(w, `%s="%s"`, a.Key, a.Val)
148
+			}
149
+		}
150
+	case TextNode:
151
+		fmt.Fprintf(w, `"%s"`, n.Data)
152
+	case CommentNode:
153
+		fmt.Fprintf(w, "<!-- %s -->", n.Data)
154
+	case DoctypeNode:
155
+		fmt.Fprintf(w, "<!DOCTYPE %s", n.Data)
156
+		if n.Attr != nil {
157
+			var p, s string
158
+			for _, a := range n.Attr {
159
+				switch a.Key {
160
+				case "public":
161
+					p = a.Val
162
+				case "system":
163
+					s = a.Val
164
+				}
165
+			}
166
+			if p != "" || s != "" {
167
+				fmt.Fprintf(w, ` "%s"`, p)
168
+				fmt.Fprintf(w, ` "%s"`, s)
169
+			}
170
+		}
171
+		io.WriteString(w, ">")
172
+	case scopeMarkerNode:
173
+		return errors.New("unexpected scopeMarkerNode")
174
+	default:
175
+		return errors.New("unknown node type")
176
+	}
177
+	io.WriteString(w, "\n")
178
+	for c := n.FirstChild; c != nil; c = c.NextSibling {
179
+		if err := dumpLevel(w, c, level+1); err != nil {
180
+			return err
181
+		}
182
+	}
183
+	return nil
184
+}
185
+
186
+func dump(n *Node) (string, error) {
187
+	if n == nil || n.FirstChild == nil {
188
+		return "", nil
189
+	}
190
+	var b bytes.Buffer
191
+	for c := n.FirstChild; c != nil; c = c.NextSibling {
192
+		if err := dumpLevel(&b, c, 0); err != nil {
193
+			return "", err
194
+		}
195
+	}
196
+	return b.String(), nil
197
+}
198
+
199
+const testDataDir = "testdata/webkit/"
200
+
201
+func TestParser(t *testing.T) {
202
+	testFiles, err := filepath.Glob(testDataDir + "*.dat")
203
+	if err != nil {
204
+		t.Fatal(err)
205
+	}
206
+	for _, tf := range testFiles {
207
+		f, err := os.Open(tf)
208
+		if err != nil {
209
+			t.Fatal(err)
210
+		}
211
+		defer f.Close()
212
+		r := bufio.NewReader(f)
213
+
214
+		for i := 0; ; i++ {
215
+			text, want, context, err := readParseTest(r)
216
+			if err == io.EOF {
217
+				break
218
+			}
219
+			if err != nil {
220
+				t.Fatal(err)
221
+			}
222
+
223
+			err = testParseCase(text, want, context)
224
+
225
+			if err != nil {
226
+				t.Errorf("%s test #%d %q, %s", tf, i, text, err)
227
+			}
228
+		}
229
+	}
230
+}
231
+
232
+// testParseCase tests one test case from the test files. If the test does not
233
+// pass, it returns an error that explains the failure.
234
+// text is the HTML to be parsed, want is a dump of the correct parse tree,
235
+// and context is the name of the context node, if any.
236
+func testParseCase(text, want, context string) (err error) {
237
+	defer func() {
238
+		if x := recover(); x != nil {
239
+			switch e := x.(type) {
240
+			case error:
241
+				err = e
242
+			default:
243
+				err = fmt.Errorf("%v", e)
244
+			}
245
+		}
246
+	}()
247
+
248
+	var doc *Node
249
+	if context == "" {
250
+		doc, err = Parse(strings.NewReader(text))
251
+		if err != nil {
252
+			return err
253
+		}
254
+	} else {
255
+		contextNode := &Node{
256
+			Type:     ElementNode,
257
+			DataAtom: atom.Lookup([]byte(context)),
258
+			Data:     context,
259
+		}
260
+		nodes, err := ParseFragment(strings.NewReader(text), contextNode)
261
+		if err != nil {
262
+			return err
263
+		}
264
+		doc = &Node{
265
+			Type: DocumentNode,
266
+		}
267
+		for _, n := range nodes {
268
+			doc.AppendChild(n)
269
+		}
270
+	}
271
+
272
+	if err := checkTreeConsistency(doc); err != nil {
273
+		return err
274
+	}
275
+
276
+	got, err := dump(doc)
277
+	if err != nil {
278
+		return err
279
+	}
280
+	// Compare the parsed tree to the #document section.
281
+	if got != want {
282
+		return fmt.Errorf("got vs want:\n----\n%s----\n%s----", got, want)
283
+	}
284
+
285
+	if renderTestBlacklist[text] || context != "" {
286
+		return nil
287
+	}
288
+
289
+	// Check that rendering and re-parsing results in an identical tree.
290
+	pr, pw := io.Pipe()
291
+	go func() {
292
+		pw.CloseWithError(Render(pw, doc))
293
+	}()
294
+	doc1, err := Parse(pr)
295
+	if err != nil {
296
+		return err
297
+	}
298
+	got1, err := dump(doc1)
299
+	if err != nil {
300
+		return err
301
+	}
302
+	if got != got1 {
303
+		return fmt.Errorf("got vs got1:\n----\n%s----\n%s----", got, got1)
304
+	}
305
+
306
+	return nil
307
+}
308
+
309
+// Some test input result in parse trees are not 'well-formed' despite
310
+// following the HTML5 recovery algorithms. Rendering and re-parsing such a
311
+// tree will not result in an exact clone of that tree. We blacklist such
312
+// inputs from the render test.
313
+var renderTestBlacklist = map[string]bool{
314
+	// The second <a> will be reparented to the first <table>'s parent. This
315
+	// results in an <a> whose parent is an <a>, which is not 'well-formed'.
316
+	`<a><table><td><a><table></table><a></tr><a></table><b>X</b>C<a>Y`: true,
317
+	// The same thing with a <p>:
318
+	`<p><table></p>`: true,
319
+	// More cases of <a> being reparented:
320
+	`<a href="blah">aba<table><a href="foo">br<tr><td></td></tr>x</table>aoe`: true,
321
+	`<a><table><a></table><p><a><div><a>`:                                     true,
322
+	`<a><table><td><a><table></table><a></tr><a></table><a>`:                  true,
323
+	// A similar reparenting situation involving <nobr>:
324
+	`<!DOCTYPE html><body><b><nobr>1<table><nobr></b><i><nobr>2<nobr></i>3`: true,
325
+	// A <plaintext> element is reparented, putting it before a table.
326
+	// A <plaintext> element can't have anything after it in HTML.
327
+	`<table><plaintext><td>`:                                   true,
328
+	`<!doctype html><table><plaintext></plaintext>`:            true,
329
+	`<!doctype html><table><tbody><plaintext></plaintext>`:     true,
330
+	`<!doctype html><table><tbody><tr><plaintext></plaintext>`: true,
331
+	// A form inside a table inside a form doesn't work either.
332
+	`<!doctype html><form><table></form><form></table></form>`: true,
333
+	// A script that ends at EOF may escape its own closing tag when rendered.
334
+	`<!doctype html><script><!--<script `:          true,
335
+	`<!doctype html><script><!--<script <`:         true,
336
+	`<!doctype html><script><!--<script <a`:        true,
337
+	`<!doctype html><script><!--<script </`:        true,
338
+	`<!doctype html><script><!--<script </s`:       true,
339
+	`<!doctype html><script><!--<script </script`:  true,
340
+	`<!doctype html><script><!--<script </scripta`: true,
341
+	`<!doctype html><script><!--<script -`:         true,
342
+	`<!doctype html><script><!--<script -a`:        true,
343
+	`<!doctype html><script><!--<script -<`:        true,
344
+	`<!doctype html><script><!--<script --`:        true,
345
+	`<!doctype html><script><!--<script --a`:       true,
346
+	`<!doctype html><script><!--<script --<`:       true,
347
+	`<script><!--<script `:                         true,
348
+	`<script><!--<script <a`:                       true,
349
+	`<script><!--<script </script`:                 true,
350
+	`<script><!--<script </scripta`:                true,
351
+	`<script><!--<script -`:                        true,
352
+	`<script><!--<script -a`:                       true,
353
+	`<script><!--<script --`:                       true,
354
+	`<script><!--<script --a`:                      true,
355
+	`<script><!--<script <`:                        true,
356
+	`<script><!--<script </`:                       true,
357
+	`<script><!--<script </s`:                      true,
358
+	// Reconstructing the active formatting elements results in a <plaintext>
359
+	// element that contains an <a> element.
360
+	`<!doctype html><p><a><plaintext>b`: true,
361
+}
362
+
363
+func TestNodeConsistency(t *testing.T) {
364
+	// inconsistentNode is a Node whose DataAtom and Data do not agree.
365
+	inconsistentNode := &Node{
366
+		Type:     ElementNode,
367
+		DataAtom: atom.Frameset,
368
+		Data:     "table",
369
+	}
370
+	_, err := ParseFragment(strings.NewReader("<p>hello</p>"), inconsistentNode)
371
+	if err == nil {
372
+		t.Errorf("got nil error, want non-nil")
373
+	}
374
+}
375
+
376
+func BenchmarkParser(b *testing.B) {
377
+	buf, err := ioutil.ReadFile("testdata/go1.html")
378
+	if err != nil {
379
+		b.Fatalf("could not read testdata/go1.html: %v", err)
380
+	}
381
+	b.SetBytes(int64(len(buf)))
382
+	runtime.GC()
383
+	b.ReportAllocs()
384
+	b.ResetTimer()
385
+	for i := 0; i < b.N; i++ {
386
+		Parse(bytes.NewBuffer(buf))
387
+	}
388
+}

+ 271
- 0
vendor/golang.org/x/net/html/render.go View File

@@ -0,0 +1,271 @@
1
+// Copyright 2011 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package html
6
+
7
+import (
8
+	"bufio"
9
+	"errors"
10
+	"fmt"
11
+	"io"
12
+	"strings"
13
+)
14
+
15
+type writer interface {
16
+	io.Writer
17
+	io.ByteWriter
18
+	WriteString(string) (int, error)
19
+}
20
+
21
+// Render renders the parse tree n to the given writer.
22
+//
23
+// Rendering is done on a 'best effort' basis: calling Parse on the output of
24
+// Render will always result in something similar to the original tree, but it
25
+// is not necessarily an exact clone unless the original tree was 'well-formed'.
26
+// 'Well-formed' is not easily specified; the HTML5 specification is
27
+// complicated.
28
+//
29
+// Calling Parse on arbitrary input typically results in a 'well-formed' parse
30
+// tree. However, it is possible for Parse to yield a 'badly-formed' parse tree.
31
+// For example, in a 'well-formed' parse tree, no <a> element is a child of
32
+// another <a> element: parsing "<a><a>" results in two sibling elements.
33
+// Similarly, in a 'well-formed' parse tree, no <a> element is a child of a
34
+// <table> element: parsing "<p><table><a>" results in a <p> with two sibling
35
+// children; the <a> is reparented to the <table>'s parent. However, calling
36
+// Parse on "<a><table><a>" does not return an error, but the result has an <a>
37
+// element with an <a> child, and is therefore not 'well-formed'.
38
+//
39
+// Programmatically constructed trees are typically also 'well-formed', but it
40
+// is possible to construct a tree that looks innocuous but, when rendered and
41
+// re-parsed, results in a different tree. A simple example is that a solitary
42
+// text node would become a tree containing <html>, <head> and <body> elements.
43
+// Another example is that the programmatic equivalent of "a<head>b</head>c"
44
+// becomes "<html><head><head/><body>abc</body></html>".
45
+func Render(w io.Writer, n *Node) error {
46
+	if x, ok := w.(writer); ok {
47
+		return render(x, n)
48
+	}
49
+	buf := bufio.NewWriter(w)
50
+	if err := render(buf, n); err != nil {
51
+		return err
52
+	}
53
+	return buf.Flush()
54
+}
55
+
56
+// plaintextAbort is returned from render1 when a <plaintext> element
57
+// has been rendered. No more end tags should be rendered after that.
58
+var plaintextAbort = errors.New("html: internal error (plaintext abort)")
59
+
60
+func render(w writer, n *Node) error {
61
+	err := render1(w, n)
62
+	if err == plaintextAbort {
63
+		err = nil
64
+	}
65
+	return err
66
+}
67
+
68
+func render1(w writer, n *Node) error {
69
+	// Render non-element nodes; these are the easy cases.
70
+	switch n.Type {
71
+	case ErrorNode:
72
+		return errors.New("html: cannot render an ErrorNode node")
73
+	case TextNode:
74
+		return escape(w, n.Data)
75
+	case DocumentNode:
76
+		for c := n.FirstChild; c != nil; c = c.NextSibling {
77
+			if err := render1(w, c); err != nil {
78
+				return err
79
+			}
80
+		}
81
+		return nil
82
+	case ElementNode:
83
+		// No-op.
84
+	case CommentNode:
85
+		if _, err := w.WriteString("<!--"); err != nil {
86
+			return err
87
+		}
88
+		if _, err := w.WriteString(n.Data); err != nil {
89
+			return err
90
+		}
91
+		if _, err := w.WriteString("-->"); err != nil {
92
+			return err
93
+		}
94
+		return nil
95
+	case DoctypeNode:
96
+		if _, err := w.WriteString("<!DOCTYPE "); err != nil {
97
+			return err
98
+		}
99
+		if _, err := w.WriteString(n.Data); err != nil {
100
+			return err
101
+		}
102
+		if n.Attr != nil {
103
+			var p, s string
104
+			for _, a := range n.Attr {
105
+				switch a.Key {
106
+				case "public":
107
+					p = a.Val
108
+				case "system":
109
+					s = a.Val
110
+				}
111
+			}
112
+			if p != "" {
113
+				if _, err := w.WriteString(" PUBLIC "); err != nil {
114
+					return err
115
+				}
116
+				if err := writeQuoted(w, p); err != nil {
117
+					return err
118
+				}
119
+				if s != "" {
120
+					if err := w.WriteByte(' '); err != nil {
121
+						return err
122
+					}
123
+					if err := writeQuoted(w, s); err != nil {
124
+						return err
125
+					}
126
+				}
127
+			} else if s != "" {
128
+				if _, err := w.WriteString(" SYSTEM "); err != nil {
129
+					return err
130
+				}
131
+				if err := writeQuoted(w, s); err != nil {
132
+					return err
133
+				}
134
+			}
135
+		}
136
+		return w.WriteByte('>')
137
+	default:
138
+		return errors.New("html: unknown node type")
139
+	}
140
+
141
+	// Render the <xxx> opening tag.
142
+	if err := w.WriteByte('<'); err != nil {
143
+		return err
144
+	}
145
+	if _, err := w.WriteString(n.Data); err != nil {
146
+		return err
147
+	}
148
+	for _, a := range n.Attr {
149
+		if err := w.WriteByte(' '); err != nil {
150
+			return err
151
+		}
152
+		if a.Namespace != "" {
153
+			if _, err := w.WriteString(a.Namespace); err != nil {
154
+				return err
155
+			}
156
+			if err := w.WriteByte(':'); err != nil {
157
+				return err
158
+			}
159
+		}
160
+		if _, err := w.WriteString(a.Key); err != nil {
161
+			return err
162
+		}
163
+		if _, err := w.WriteString(`="`); err != nil {
164
+			return err
165
+		}
166
+		if err := escape(w, a.Val); err != nil {
167
+			return err
168
+		}
169
+		if err := w.WriteByte('"'); err != nil {
170
+			return err
171
+		}
172
+	}
173
+	if voidElements[n.Data] {
174
+		if n.FirstChild != nil {
175
+			return fmt.Errorf("html: void element <%s> has child nodes", n.Data)
176
+		}
177
+		_, err := w.WriteString("/>")
178
+		return err
179
+	}
180
+	if err := w.WriteByte('>'); err != nil {
181
+		return err
182
+	}
183
+
184
+	// Add initial newline where there is danger of a newline beging ignored.
185
+	if c := n.FirstChild; c != nil && c.Type == TextNode && strings.HasPrefix(c.Data, "\n") {
186
+		switch n.Data {
187
+		case "pre", "listing", "textarea":
188
+			if err := w.WriteByte('\n'); err != nil {
189
+				return err
190
+			}
191
+		}
192
+	}
193
+
194
+	// Render any child nodes.
195
+	switch n.Data {
196
+	case "iframe", "noembed", "noframes", "noscript", "plaintext", "script", "style", "xmp":
197
+		for c := n.FirstChild; c != nil; c = c.NextSibling {
198
+			if c.Type == TextNode {
199
+				if _, err := w.WriteString(c.Data); err != nil {
200
+					return err
201
+				}
202
+			} else {
203
+				if err := render1(w, c); err != nil {
204
+					return err
205
+				}
206
+			}
207
+		}
208
+		if n.Data == "plaintext" {
209
+			// Don't render anything else. <plaintext> must be the
210
+			// last element in the file, with no closing tag.
211
+			return plaintextAbort
212
+		}
213
+	default:
214
+		for c := n.FirstChild; c != nil; c = c.NextSibling {
215
+			if err := render1(w, c); err != nil {
216
+				return err
217
+			}
218
+		}
219
+	}
220
+
221
+	// Render the </xxx> closing tag.
222
+	if _, err := w.WriteString("</"); err != nil {
223
+		return err
224
+	}
225
+	if _, err := w.WriteString(n.Data); err != nil {
226
+		return err
227
+	}
228
+	return w.WriteByte('>')
229
+}
230
+
231
+// writeQuoted writes s to w surrounded by quotes. Normally it will use double
232
+// quotes, but if s contains a double quote, it will use single quotes.
233
+// It is used for writing the identifiers in a doctype declaration.
234
+// In valid HTML, they can't contain both types of quotes.
235
+func writeQuoted(w writer, s string) error {
236
+	var q byte = '"'
237
+	if strings.Contains(s, `"`) {
238
+		q = '\''
239
+	}
240
+	if err := w.WriteByte(q); err != nil {
241
+		return err
242
+	}
243
+	if _, err := w.WriteString(s); err != nil {
244
+		return err
245
+	}
246
+	if err := w.WriteByte(q); err != nil {
247
+		return err
248
+	}
249
+	return nil
250
+}
251
+
252
+// Section 12.1.2, "Elements", gives this list of void elements. Void elements
253
+// are those that can't have any contents.
254
+var voidElements = map[string]bool{
255
+	"area":    true,
256
+	"base":    true,
257
+	"br":      true,
258
+	"col":     true,
259
+	"command": true,
260
+	"embed":   true,
261
+	"hr":      true,
262
+	"img":     true,
263
+	"input":   true,
264
+	"keygen":  true,
265
+	"link":    true,
266
+	"meta":    true,
267
+	"param":   true,
268
+	"source":  true,
269
+	"track":   true,
270
+	"wbr":     true,
271
+}

+ 156
- 0
vendor/golang.org/x/net/html/render_test.go View File

@@ -0,0 +1,156 @@
1
+// Copyright 2010 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package html
6
+
7
+import (
8
+	"bytes"
9
+	"testing"
10
+)
11
+
12
+func TestRenderer(t *testing.T) {
13
+	nodes := [...]*Node{
14
+		0: {
15
+			Type: ElementNode,
16
+			Data: "html",
17
+		},
18
+		1: {
19
+			Type: ElementNode,
20
+			Data: "head",
21
+		},
22
+		2: {
23
+			Type: ElementNode,
24
+			Data: "body",
25
+		},
26
+		3: {
27
+			Type: TextNode,
28
+			Data: "0<1",
29
+		},
30
+		4: {
31
+			Type: ElementNode,
32
+			Data: "p",
33
+			Attr: []Attribute{
34
+				{
35
+					Key: "id",
36
+					Val: "A",
37
+				},
38
+				{
39
+					Key: "foo",
40
+					Val: `abc"def`,
41
+				},
42
+			},
43
+		},
44
+		5: {
45
+			Type: TextNode,
46
+			Data: "2",
47
+		},
48
+		6: {
49
+			Type: ElementNode,
50
+			Data: "b",
51
+			Attr: []Attribute{
52
+				{
53
+					Key: "empty",
54
+					Val: "",
55
+				},
56
+			},
57
+		},
58
+		7: {
59
+			Type: TextNode,
60
+			Data: "3",
61
+		},
62
+		8: {
63
+			Type: ElementNode,
64
+			Data: "i",
65
+			Attr: []Attribute{
66
+				{
67
+					Key: "backslash",
68
+					Val: `\`,
69
+				},
70
+			},
71
+		},
72
+		9: {
73
+			Type: TextNode,
74
+			Data: "&4",
75
+		},
76
+		10: {
77
+			Type: TextNode,
78
+			Data: "5",
79
+		},
80
+		11: {
81
+			Type: ElementNode,
82
+			Data: "blockquote",
83
+		},
84
+		12: {
85
+			Type: ElementNode,
86
+			Data: "br",
87
+		},
88
+		13: {
89
+			Type: TextNode,
90
+			Data: "6",
91
+		},
92
+	}
93
+
94
+	// Build a tree out of those nodes, based on a textual representation.
95
+	// Only the ".\t"s are significant. The trailing HTML-like text is
96
+	// just commentary. The "0:" prefixes are for easy cross-reference with
97
+	// the nodes array.
98
+	treeAsText := [...]string{
99
+		0: `<html>`,
100
+		1: `.	<head>`,
101
+		2: `.	<body>`,
102
+		3: `.	.	"0&lt;1"`,
103
+		4: `.	.	<p id="A" foo="abc&#34;def">`,
104
+		5: `.	.	.	"2"`,
105
+		6: `.	.	.	<b empty="">`,
106
+		7: `.	.	.	.	"3"`,
107
+		8: `.	.	.	<i backslash="\">`,
108
+		9: `.	.	.	.	"&amp;4"`,
109
+		10: `.	.	"5"`,
110
+		11: `.	.	<blockquote>`,
111
+		12: `.	.	<br>`,
112
+		13: `.	.	"6"`,
113
+	}
114
+	if len(nodes) != len(treeAsText) {
115
+		t.Fatal("len(nodes) != len(treeAsText)")
116
+	}
117
+	var stack [8]*Node
118
+	for i, line := range treeAsText {
119
+		level := 0
120
+		for line[0] == '.' {
121
+			// Strip a leading ".\t".
122
+			line = line[2:]
123
+			level++
124
+		}
125
+		n := nodes[i]
126
+		if level == 0 {
127
+			if stack[0] != nil {
128
+				t.Fatal("multiple root nodes")
129
+			}
130
+			stack[0] = n
131
+		} else {
132
+			stack[level-1].AppendChild(n)
133
+			stack[level] = n
134
+			for i := level + 1; i < len(stack); i++ {
135
+				stack[i] = nil
136
+			}
137
+		}
138
+		// At each stage of tree construction, we check all nodes for consistency.
139
+		for j, m := range nodes {
140
+			if err := checkNodeConsistency(m); err != nil {
141
+				t.Fatalf("i=%d, j=%d: %v", i, j, err)
142
+			}
143
+		}
144
+	}
145
+
146
+	want := `<html><head></head><body>0&lt;1<p id="A" foo="abc&#34;def">` +
147
+		`2<b empty="">3</b><i backslash="\">&amp;4</i></p>` +
148
+		`5<blockquote></blockquote><br/>6</body></html>`
149
+	b := new(bytes.Buffer)
150
+	if err := Render(b, nodes[0]); err != nil {
151
+		t.Fatal(err)
152
+	}
153
+	if got := b.String(); got != want {
154
+		t.Errorf("got vs want:\n%s\n%s\n", got, want)
155
+	}
156
+}

+ 2237
- 0
vendor/golang.org/x/net/html/testdata/go1.html
File diff suppressed because it is too large
View File


+ 28
- 0
vendor/golang.org/x/net/html/testdata/webkit/README View File

@@ -0,0 +1,28 @@
1
+The *.dat files in this directory are copied from The WebKit Open Source
2
+Project, specifically $WEBKITROOT/LayoutTests/html5lib/resources.
3
+WebKit is licensed under a BSD style license.
4
+http://webkit.org/coding/bsd-license.html says:
5
+
6
+Copyright (C) 2009 Apple Inc. All rights reserved.
7
+
8
+Redistribution and use in source and binary forms, with or without
9
+modification, are permitted provided that the following conditions are met:
10
+
11
+1. Redistributions of source code must retain the above copyright notice,
12
+this list of conditions and the following disclaimer.
13
+
14
+2. Redistributions in binary form must reproduce the above copyright notice,
15
+this list of conditions and the following disclaimer in the documentation
16
+and/or other materials provided with the distribution.
17
+
18
+THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS "AS IS" AND ANY
19
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+

+ 194
- 0
vendor/golang.org/x/net/html/testdata/webkit/adoption01.dat View File

@@ -0,0 +1,194 @@
1
+#data
2
+<a><p></a></p>
3
+#errors
4
+#document
5
+| <html>
6
+|   <head>
7
+|   <body>
8
+|     <a>
9
+|     <p>
10
+|       <a>
11
+
12
+#data
13
+<a>1<p>2</a>3</p>
14
+#errors
15
+#document
16
+| <html>
17
+|   <head>
18
+|   <body>
19
+|     <a>
20
+|       "1"
21
+|     <p>
22
+|       <a>
23
+|         "2"
24
+|       "3"
25
+
26
+#data
27
+<a>1<button>2</a>3</button>
28
+#errors
29
+#document
30
+| <html>
31
+|   <head>
32
+|   <body>
33
+|     <a>
34
+|       "1"
35
+|     <button>
36
+|       <a>
37
+|         "2"
38
+|       "3"
39
+
40
+#data
41
+<a>1<b>2</a>3</b>
42
+#errors
43
+#document
44
+| <html>
45
+|   <head>
46
+|   <body>
47
+|     <a>
48
+|       "1"
49
+|       <b>
50
+|         "2"
51
+|     <b>
52
+|       "3"
53
+
54
+#data
55
+<a>1<div>2<div>3</a>4</div>5</div>
56
+#errors
57
+#document
58
+| <html>
59
+|   <head>
60
+|   <body>
61
+|     <a>
62
+|       "1"
63
+|     <div>
64
+|       <a>
65
+|         "2"
66
+|       <div>
67
+|         <a>
68
+|           "3"
69
+|         "4"
70
+|       "5"
71
+
72
+#data
73
+<table><a>1<p>2</a>3</p>
74
+#errors
75
+#document
76
+| <html>
77
+|   <head>
78
+|   <body>
79
+|     <a>
80
+|       "1"
81
+|     <p>
82
+|       <a>
83
+|         "2"
84
+|       "3"
85
+|     <table>
86
+
87
+#data
88
+<b><b><a><p></a>
89
+#errors
90
+#document
91
+| <html>
92
+|   <head>
93
+|   <body>
94
+|     <b>
95
+|       <b>
96
+|         <a>
97
+|         <p>
98
+|           <a>
99
+
100
+#data
101
+<b><a><b><p></a>
102
+#errors
103
+#document
104
+| <html>
105
+|   <head>
106
+|   <body>
107
+|     <b>
108
+|       <a>
109
+|         <b>
110
+|       <b>
111
+|         <p>
112
+|           <a>
113
+
114
+#data
115
+<a><b><b><p></a>
116
+#errors
117
+#document
118
+| <html>
119
+|   <head>
120
+|   <body>
121
+|     <a>
122
+|       <b>
123
+|         <b>
124
+|     <b>
125
+|       <b>
126
+|         <p>
127
+|           <a>
128
+
129
+#data
130
+<p>1<s id="A">2<b id="B">3</p>4</s>5</b>
131
+#errors
132
+#document
133
+| <html>
134
+|   <head>
135
+|   <body>
136
+|     <p>
137
+|       "1"
138
+|       <s>
139
+|         id="A"
140
+|         "2"
141
+|         <b>
142
+|           id="B"
143
+|           "3"
144
+|     <s>
145
+|       id="A"
146
+|       <b>
147
+|         id="B"
148
+|         "4"
149
+|     <b>
150
+|       id="B"
151
+|       "5"
152
+
153
+#data
154
+<table><a>1<td>2</td>3</table>
155
+#errors
156
+#document
157
+| <html>
158
+|   <head>
159
+|   <body>
160
+|     <a>
161
+|       "1"
162
+|     <a>
163
+|       "3"
164
+|     <table>
165
+|       <tbody>
166
+|         <tr>
167
+|           <td>
168
+|             "2"
169
+
170
+#data
171
+<table>A<td>B</td>C</table>
172
+#errors
173
+#document
174
+| <html>
175
+|   <head>
176
+|   <body>
177
+|     "AC"
178
+|     <table>
179
+|       <tbody>
180
+|         <tr>
181
+|           <td>
182
+|             "B"
183
+
184
+#data
185
+<a><svg><tr><input></a>
186
+#errors
187
+#document
188
+| <html>
189
+|   <head>
190
+|   <body>
191
+|     <a>
192
+|       <svg svg>
193
+|         <svg tr>
194
+|           <svg input>

+ 31
- 0
vendor/golang.org/x/net/html/testdata/webkit/adoption02.dat View File

@@ -0,0 +1,31 @@
1
+#data
2
+<b>1<i>2<p>3</b>4
3
+#errors
4
+#document
5
+| <html>
6
+|   <head>
7
+|   <body>
8
+|     <b>
9
+|       "1"
10
+|       <i>
11
+|         "2"
12
+|     <i>
13
+|       <p>
14
+|         <b>
15
+|           "3"
16
+|         "4"
17
+
18
+#data
19
+<a><div><style></style><address><a>
20
+#errors
21
+#document
22
+| <html>
23
+|   <head>
24
+|   <body>
25
+|     <a>
26
+|     <div>
27
+|       <a>
28
+|         <style>
29
+|       <address>
30
+|         <a>
31
+|         <a>

+ 135
- 0
vendor/golang.org/x/net/html/testdata/webkit/comments01.dat View File

@@ -0,0 +1,135 @@
1
+#data
2
+FOO<!-- BAR -->BAZ
3
+#errors
4
+#document
5
+| <html>
6
+|   <head>
7
+|   <body>
8
+|     "FOO"
9
+|     <!--  BAR  -->
10
+|     "BAZ"
11
+
12
+#data
13
+FOO<!-- BAR --!>BAZ
14
+#errors
15
+#document
16
+| <html>
17
+|   <head>
18
+|   <body>
19
+|     "FOO"
20
+|     <!--  BAR  -->
21
+|     "BAZ"
22
+
23
+#data
24
+FOO<!-- BAR --   >BAZ
25
+#errors
26
+#document
27
+| <html>
28
+|   <head>
29
+|   <body>
30
+|     "FOO"
31
+|     <!--  BAR --   >BAZ -->
32
+
33
+#data
34
+FOO<!-- BAR -- <QUX> -- MUX -->BAZ
35
+#errors
36
+#document
37
+| <html>
38
+|   <head>
39
+|   <body>
40
+|     "FOO"
41
+|     <!--  BAR -- <QUX> -- MUX  -->
42
+|     "BAZ"
43
+
44
+#data
45
+FOO<!-- BAR -- <QUX> -- MUX --!>BAZ
46
+#errors
47
+#document
48
+| <html>
49
+|   <head>
50
+|   <body>
51
+|     "FOO"
52
+|     <!--  BAR -- <QUX> -- MUX  -->
53
+|     "BAZ"
54
+
55
+#data
56
+FOO<!-- BAR -- <QUX> -- MUX -- >BAZ
57
+#errors
58
+#document
59
+| <html>
60
+|   <head>
61
+|   <body>
62
+|     "FOO"
63
+|     <!--  BAR -- <QUX> -- MUX -- >BAZ -->
64
+
65
+#data
66
+FOO<!---->BAZ
67
+#errors
68
+#document
69
+| <html>
70
+|   <head>
71
+|   <body>
72
+|     "FOO"
73
+|     <!--  -->
74
+|     "BAZ"
75
+
76
+#data
77
+FOO<!--->BAZ
78
+#errors
79
+#document
80
+| <html>
81
+|   <head>
82
+|   <body>
83
+|     "FOO"
84
+|     <!--  -->
85
+|     "BAZ"
86
+
87
+#data
88
+FOO<!-->BAZ
89
+#errors
90
+#document
91
+| <html>
92
+|   <head>
93
+|   <body>
94
+|     "FOO"
95
+|     <!--  -->
96
+|     "BAZ"
97
+
98
+#data
99
+<?xml version="1.0">Hi
100
+#errors
101
+#document
102
+| <!-- ?xml version="1.0" -->
103
+| <html>
104
+|   <head>
105
+|   <body>
106
+|     "Hi"
107
+
108
+#data
109
+<?xml version="1.0">
110
+#errors
111
+#document
112
+| <!-- ?xml version="1.0" -->
113
+| <html>
114
+|   <head>
115
+|   <body>
116
+
117
+#data
118
+<?xml version
119
+#errors
120
+#document
121
+| <!-- ?xml version -->
122
+| <html>
123
+|   <head>
124
+|   <body>
125
+
126
+#data
127
+FOO<!----->BAZ
128
+#errors
129
+#document
130
+| <html>
131
+|   <head>
132
+|   <body>
133
+|     "FOO"
134
+|     <!-- - -->
135
+|     "BAZ"

+ 370
- 0
vendor/golang.org/x/net/html/testdata/webkit/doctype01.dat View File

@@ -0,0 +1,370 @@
1
+#data
2
+<!DOCTYPE html>Hello
3
+#errors
4
+#document
5
+| <!DOCTYPE html>
6
+| <html>
7
+|   <head>
8
+|   <body>
9
+|     "Hello"
10
+
11
+#data
12
+<!dOctYpE HtMl>Hello
13
+#errors
14
+#document
15
+| <!DOCTYPE html>
16
+| <html>
17
+|   <head>
18
+|   <body>
19
+|     "Hello"
20
+
21
+#data
22
+<!DOCTYPEhtml>Hello
23
+#errors
24
+#document
25
+| <!DOCTYPE html>
26
+| <html>
27
+|   <head>
28
+|   <body>
29
+|     "Hello"
30
+
31
+#data
32
+<!DOCTYPE>Hello
33
+#errors
34
+#document
35
+| <!DOCTYPE >
36
+| <html>
37
+|   <head>
38
+|   <body>
39
+|     "Hello"
40
+
41
+#data
42
+<!DOCTYPE >Hello
43
+#errors
44
+#document
45
+| <!DOCTYPE >
46
+| <html>
47
+|   <head>
48
+|   <body>
49
+|     "Hello"
50
+
51
+#data
52
+<!DOCTYPE potato>Hello
53
+#errors
54
+#document
55
+| <!DOCTYPE potato>
56
+| <html>
57
+|   <head>
58
+|   <body>
59
+|     "Hello"
60
+
61
+#data
62
+<!DOCTYPE potato >Hello
63
+#errors
64
+#document
65
+| <!DOCTYPE potato>
66
+| <html>
67
+|   <head>
68
+|   <body>
69
+|     "Hello"
70
+
71
+#data
72
+<!DOCTYPE potato taco>Hello
73
+#errors
74
+#document
75
+| <!DOCTYPE potato>
76
+| <html>
77
+|   <head>
78
+|   <body>
79
+|     "Hello"
80
+
81
+#data
82
+<!DOCTYPE potato taco "ddd>Hello
83
+#errors
84
+#document
85
+| <!DOCTYPE potato>
86
+| <html>
87
+|   <head>
88
+|   <body>
89
+|     "Hello"
90
+
91
+#data
92
+<!DOCTYPE potato sYstEM>Hello
93
+#errors
94
+#document
95
+| <!DOCTYPE potato>
96
+| <html>
97
+|   <head>
98
+|   <body>
99
+|     "Hello"
100
+
101
+#data
102
+<!DOCTYPE potato sYstEM    >Hello
103
+#errors
104
+#document
105
+| <!DOCTYPE potato>
106
+| <html>
107
+|   <head>
108
+|   <body>
109
+|     "Hello"
110
+
111
+#data
112
+<!DOCTYPE   potato       sYstEM  ggg>Hello
113
+#errors
114
+#document
115
+| <!DOCTYPE potato>
116
+| <html>
117
+|   <head>
118
+|   <body>
119
+|     "Hello"
120
+
121
+#data
122
+<!DOCTYPE potato SYSTEM taco  >Hello
123
+#errors
124
+#document
125
+| <!DOCTYPE potato>
126
+| <html>
127
+|   <head>
128
+|   <body>
129
+|     "Hello"
130
+
131
+#data
132
+<!DOCTYPE potato SYSTEM 'taco"'>Hello
133
+#errors
134
+#document
135
+| <!DOCTYPE potato "" "taco"">
136
+| <html>
137
+|   <head>
138
+|   <body>
139
+|     "Hello"
140
+
141
+#data
142
+<!DOCTYPE potato SYSTEM "taco">Hello
143
+#errors
144
+#document
145
+| <!DOCTYPE potato "" "taco">
146
+| <html>
147
+|   <head>
148
+|   <body>
149
+|     "Hello"
150
+
151
+#data
152
+<!DOCTYPE potato SYSTEM "tai'co">Hello
153
+#errors
154
+#document
155
+| <!DOCTYPE potato "" "tai'co">
156
+| <html>
157
+|   <head>
158
+|   <body>
159
+|     "Hello"
160
+
161
+#data
162
+<!DOCTYPE potato SYSTEMtaco "ddd">Hello
163
+#errors
164
+#document
165
+| <!DOCTYPE potato>
166
+| <html>
167
+|   <head>
168
+|   <body>
169
+|     "Hello"
170
+
171
+#data
172
+<!DOCTYPE potato grass SYSTEM taco>Hello
173
+#errors
174
+#document
175
+| <!DOCTYPE potato>
176
+| <html>
177
+|   <head>
178
+|   <body>
179
+|     "Hello"
180
+
181
+#data
182
+<!DOCTYPE potato pUbLIc>Hello
183
+#errors
184
+#document
185
+| <!DOCTYPE potato>
186
+| <html>
187
+|   <head>
188
+|   <body>
189
+|     "Hello"
190
+
191
+#data
192
+<!DOCTYPE potato pUbLIc >Hello
193
+#errors
194
+#document
195
+| <!DOCTYPE potato>
196
+| <html>
197
+|   <head>
198
+|   <body>
199
+|     "Hello"
200
+
201
+#data
202
+<!DOCTYPE potato pUbLIcgoof>Hello
203
+#errors
204
+#document
205
+| <!DOCTYPE potato>
206
+| <html>
207
+|   <head>
208
+|   <body>
209
+|     "Hello"
210
+
211
+#data
212
+<!DOCTYPE potato PUBLIC goof>Hello
213
+#errors
214
+#document
215
+| <!DOCTYPE potato>
216
+| <html>
217
+|   <head>
218
+|   <body>
219
+|     "Hello"
220
+
221
+#data
222
+<!DOCTYPE potato PUBLIC "go'of">Hello
223
+#errors
224
+#document
225
+| <!DOCTYPE potato "go'of" "">
226
+| <html>
227
+|   <head>
228
+|   <body>
229
+|     "Hello"
230
+
231
+#data
232
+<!DOCTYPE potato PUBLIC 'go'of'>Hello
233
+#errors
234
+#document
235
+| <!DOCTYPE potato "go" "">
236
+| <html>
237
+|   <head>
238
+|   <body>
239
+|     "Hello"
240
+
241
+#data
242
+<!DOCTYPE potato PUBLIC 'go:hh   of' >Hello
243
+#errors
244
+#document
245
+| <!DOCTYPE potato "go:hh   of" "">
246
+| <html>
247
+|   <head>
248
+|   <body>
249
+|     "Hello"
250
+
251
+#data
252
+<!DOCTYPE potato PUBLIC "W3C-//dfdf" SYSTEM ggg>Hello
253
+#errors
254
+#document
255
+| <!DOCTYPE potato "W3C-//dfdf" "">
256
+| <html>
257
+|   <head>
258
+|   <body>
259
+|     "Hello"
260
+
261
+#data
262
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
263
+   "http://www.w3.org/TR/html4/strict.dtd">Hello
264
+#errors
265
+#document
266
+| <!DOCTYPE html "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
267
+| <html>
268
+|   <head>
269
+|   <body>
270
+|     "Hello"
271
+
272
+#data
273
+<!DOCTYPE ...>Hello
274
+#errors
275
+#document
276
+| <!DOCTYPE ...>
277
+| <html>
278
+|   <head>
279
+|   <body>
280
+|     "Hello"
281
+
282
+#data
283
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
284
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
285
+#errors
286
+#document
287
+| <!DOCTYPE html "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
288
+| <html>
289
+|   <head>
290
+|   <body>
291
+
292
+#data
293
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
294
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
295
+#errors
296
+#document
297
+| <!DOCTYPE html "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
298
+| <html>
299
+|   <head>
300
+|   <body>
301
+
302
+#data
303
+<!DOCTYPE root-element [SYSTEM OR PUBLIC FPI] "uri" [ 
304
+<!-- internal declarations -->
305
+]>
306
+#errors
307
+#document
308
+| <!DOCTYPE root-element>
309
+| <html>
310
+|   <head>
311
+|   <body>
312
+|     "]>"
313
+
314
+#data
315
+<!DOCTYPE html PUBLIC
316
+  "-//WAPFORUM//DTD XHTML Mobile 1.0//EN"
317
+    "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
318
+#errors
319
+#document
320
+| <!DOCTYPE html "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
321
+| <html>
322
+|   <head>
323
+|   <body>
324
+
325
+#data
326
+<!DOCTYPE HTML SYSTEM "http://www.w3.org/DTD/HTML4-strict.dtd"><body><b>Mine!</b></body>
327
+#errors
328
+#document
329
+| <!DOCTYPE html "" "http://www.w3.org/DTD/HTML4-strict.dtd">
330
+| <html>
331
+|   <head>
332
+|   <body>
333
+|     <b>
334
+|       "Mine!"
335
+
336
+#data
337
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
338
+#errors
339
+#document
340
+| <!DOCTYPE html "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
341
+| <html>
342
+|   <head>
343
+|   <body>
344
+
345
+#data
346
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"'http://www.w3.org/TR/html4/strict.dtd'>
347
+#errors
348
+#document
349
+| <!DOCTYPE html "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
350
+| <html>
351
+|   <head>
352
+|   <body>
353
+
354
+#data
355
+<!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.01//EN"'http://www.w3.org/TR/html4/strict.dtd'>
356
+#errors
357
+#document
358
+| <!DOCTYPE html "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
359
+| <html>
360
+|   <head>
361
+|   <body>
362
+
363
+#data
364
+<!DOCTYPE HTML PUBLIC'-//W3C//DTD HTML 4.01//EN''http://www.w3.org/TR/html4/strict.dtd'>
365
+#errors
366
+#document
367
+| <!DOCTYPE html "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
368
+| <html>
369
+|   <head>
370
+|   <body>

+ 603
- 0
vendor/golang.org/x/net/html/testdata/webkit/entities01.dat View File

@@ -0,0 +1,603 @@
1
+#data
2
+FOO&gt;BAR
3
+#errors
4
+#document
5
+| <html>
6
+|   <head>
7
+|   <body>
8
+|     "FOO>BAR"
9
+
10
+#data
11
+FOO&gtBAR
12
+#errors
13
+#document
14
+| <html>
15
+|   <head>
16
+|   <body>
17
+|     "FOO>BAR"
18
+
19
+#data
20
+FOO&gt BAR
21
+#errors
22
+#document
23
+| <html>
24
+|   <head>
25
+|   <body>
26
+|     "FOO> BAR"
27
+
28
+#data
29
+FOO&gt;;;BAR
30
+#errors
31
+#document
32
+| <html>
33
+|   <head>
34
+|   <body>
35
+|     "FOO>;;BAR"
36
+
37
+#data
38
+I'm &notit; I tell you
39
+#errors
40
+#document
41
+| <html>
42
+|   <head>
43
+|   <body>
44
+|     "I'm ¬it; I tell you"
45
+
46
+#data
47
+I'm &notin; I tell you
48
+#errors
49
+#document
50
+| <html>
51
+|   <head>
52
+|   <body>
53
+|     "I'm ∉ I tell you"
54
+
55
+#data
56
+FOO& BAR
57
+#errors
58
+#document
59
+| <html>
60
+|   <head>
61
+|   <body>
62
+|     "FOO& BAR"
63
+
64
+#data
65
+FOO&<BAR>
66
+#errors
67
+#document
68
+| <html>
69
+|   <head>
70
+|   <body>
71
+|     "FOO&"
72
+|     <bar>
73
+
74
+#data
75
+FOO&&&&gt;BAR
76
+#errors
77
+#document
78
+| <html>
79
+|   <head>
80
+|   <body>
81
+|     "FOO&&&>BAR"
82
+
83
+#data
84
+FOO&#41;BAR
85
+#errors
86
+#document
87
+| <html>
88
+|   <head>
89
+|   <body>
90
+|     "FOO)BAR"
91
+
92
+#data
93
+FOO&#x41;BAR
94
+#errors
95
+#document
96
+| <html>
97
+|   <head>
98
+|   <body>
99
+|     "FOOABAR"
100
+
101
+#data
102
+FOO&#X41;BAR
103
+#errors
104
+#document
105
+| <html>
106
+|   <head>
107
+|   <body>
108
+|     "FOOABAR"
109
+
110
+#data
111
+FOO&#BAR
112
+#errors
113
+#document
114
+| <html>
115
+|   <head>
116
+|   <body>
117
+|     "FOO&#BAR"
118
+
119
+#data
120
+FOO&#ZOO
121
+#errors
122
+#document
123
+| <html>
124
+|   <head>
125
+|   <body>
126
+|     "FOO&#ZOO"
127
+
128
+#data
129
+FOO&#xBAR
130
+#errors
131
+#document
132
+| <html>
133
+|   <head>
134
+|   <body>
135
+|     "FOOºR"
136
+
137
+#data
138
+FOO&#xZOO
139
+#errors
140
+#document
141
+| <html>
142
+|   <head>
143
+|   <body>
144
+|     "FOO&#xZOO"
145
+
146
+#data
147
+FOO&#XZOO
148
+#errors
149
+#document
150
+| <html>
151
+|   <head>
152
+|   <body>
153
+|     "FOO&#XZOO"
154
+
155
+#data
156
+FOO&#41BAR
157
+#errors
158
+#document
159
+| <html>
160
+|   <head>
161
+|   <body>
162
+|     "FOO)BAR"
163
+
164
+#data
165
+FOO&#x41BAR
166
+#errors
167
+#document
168
+| <html>
169
+|   <head>
170
+|   <body>
171
+|     "FOO䆺R"
172
+
173
+#data
174
+FOO&#x41ZOO
175
+#errors
176
+#document
177
+| <html>
178
+|   <head>
179
+|   <body>
180
+|     "FOOAZOO"
181
+
182
+#data
183
+FOO&#x0000;ZOO
184
+#errors
185
+#document
186
+| <html>
187
+|   <head>
188
+|   <body>
189
+|     "FOO�ZOO"
190
+
191
+#data
192
+FOO&#x0078;ZOO
193
+#errors
194
+#document
195
+| <html>
196
+|   <head>
197
+|   <body>
198
+|     "FOOxZOO"
199
+
200
+#data
201
+FOO&#x0079;ZOO
202
+#errors
203
+#document
204
+| <html>
205
+|   <head>
206
+|   <body>
207
+|     "FOOyZOO"
208
+
209
+#data
210
+FOO&#x0080;ZOO
211
+#errors
212
+#document
213
+| <html>
214
+|   <head>
215
+|   <body>
216
+|     "FOO€ZOO"
217
+
218
+#data
219
+FOO&#x0081;ZOO
220
+#errors
221
+#document
222
+| <html>
223
+|   <head>
224
+|   <body>
225
+|     "FOOZOO"
226
+
227
+#data
228
+FOO&#x0082;ZOO
229
+#errors
230
+#document
231
+| <html>
232
+|   <head>
233
+|   <body>
234
+|     "FOO‚ZOO"
235
+
236
+#data
237
+FOO&#x0083;ZOO
238
+#errors
239
+#document
240
+| <html>
241
+|   <head>
242
+|   <body>
243
+|     "FOOƒZOO"
244
+
245
+#data
246
+FOO&#x0084;ZOO
247
+#errors
248
+#document
249
+| <html>
250
+|   <head>
251
+|   <body>
252
+|     "FOO„ZOO"
253
+
254
+#data
255
+FOO&#x0085;ZOO
256
+#errors
257
+#document
258
+| <html>
259
+|   <head>
260
+|   <body>
261
+|     "FOO…ZOO"
262
+
263
+#data
264
+FOO&#x0086;ZOO
265
+#errors
266
+#document
267
+| <html>
268
+|   <head>
269
+|   <body>
270
+|     "FOO†ZOO"
271
+
272
+#data
273
+FOO&#x0087;ZOO
274
+#errors
275
+#document
276
+| <html>
277
+|   <head>
278
+|   <body>
279
+|     "FOO‡ZOO"
280
+
281
+#data
282
+FOO&#x0088;ZOO
283
+#errors
284
+#document
285
+| <html>
286
+|   <head>
287
+|   <body>
288
+|     "FOOˆZOO"
289
+
290
+#data
291
+FOO&#x0089;ZOO
292
+#errors
293
+#document
294
+| <html>
295
+|   <head>
296
+|   <body>
297
+|     "FOO‰ZOO"
298
+
299
+#data
300
+FOO&#x008A;ZOO
301
+#errors
302
+#document
303
+| <html>
304
+|   <head>
305
+|   <body>
306
+|     "FOOŠZOO"
307
+
308
+#data
309
+FOO&#x008B;ZOO
310
+#errors
311
+#document
312
+| <html>
313
+|   <head>
314
+|   <body>
315
+|     "FOO‹ZOO"
316
+
317
+#data
318
+FOO&#x008C;ZOO
319
+#errors
320
+#document
321
+| <html>
322
+|   <head>
323
+|   <body>
324
+|     "FOOŒZOO"
325
+
326
+#data
327
+FOO&#x008D;ZOO
328
+#errors
329
+#document
330
+| <html>
331
+|   <head>
332
+|   <body>
333
+|     "FOOZOO"
334
+
335
+#data
336
+FOO&#x008E;ZOO
337
+#errors
338
+#document
339
+| <html>
340
+|   <head>
341
+|   <body>
342
+|     "FOOŽZOO"
343
+
344
+#data
345
+FOO&#x008F;ZOO
346
+#errors
347
+#document
348
+| <html>
349
+|   <head>
350
+|   <body>
351
+|     "FOOZOO"
352
+
353
+#data
354
+FOO&#x0090;ZOO
355
+#errors
356
+#document
357
+| <html>
358
+|   <head>
359
+|   <body>
360
+|     "FOOZOO"
361
+
362
+#data
363
+FOO&#x0091;ZOO
364
+#errors
365
+#document
366
+| <html>
367
+|   <head>
368
+|   <body>
369
+|     "FOO‘ZOO"
370
+
371
+#data
372
+FOO&#x0092;ZOO
373
+#errors
374
+#document
375
+| <html>
376
+|   <head>
377
+|   <body>
378
+|     "FOO’ZOO"
379
+
380
+#data
381
+FOO&#x0093;ZOO
382
+#errors
383
+#document
384
+| <html>
385
+|   <head>
386
+|   <body>
387
+|     "FOO“ZOO"
388
+
389
+#data
390
+FOO&#x0094;ZOO
391
+#errors
392
+#document
393
+| <html>
394
+|   <head>
395
+|   <body>
396
+|     "FOO”ZOO"
397
+
398
+#data
399
+FOO&#x0095;ZOO
400
+#errors
401
+#document
402
+| <html>
403
+|   <head>
404
+|   <body>
405
+|     "FOO•ZOO"
406
+
407
+#data
408
+FOO&#x0096;ZOO
409
+#errors
410
+#document
411
+| <html>
412
+|   <head>
413
+|   <body>
414
+|     "FOO–ZOO"
415
+
416
+#data
417
+FOO&#x0097;ZOO
418
+#errors
419
+#document
420
+| <html>
421
+|   <head>
422
+|   <body>
423
+|     "FOO—ZOO"
424
+
425
+#data
426
+FOO&#x0098;ZOO
427
+#errors
428
+#document
429
+| <html>
430
+|   <head>
431
+|   <body>
432
+|     "FOO˜ZOO"
433
+
434
+#data
435
+FOO&#x0099;ZOO
436
+#errors
437
+#document
438
+| <html>
439
+|   <head>
440
+|   <body>
441
+|     "FOO™ZOO"
442
+
443
+#data
444
+FOO&#x009A;ZOO
445
+#errors
446
+#document
447
+| <html>
448
+|   <head>
449
+|   <body>
450
+|     "FOOšZOO"
451
+
452
+#data
453
+FOO&#x009B;ZOO
454
+#errors
455
+#document
456
+| <html>
457
+|   <head>
458
+|   <body>
459
+|     "FOO›ZOO"
460
+
461
+#data
462
+FOO&#x009C;ZOO
463
+#errors
464
+#document
465
+| <html>
466
+|   <head>
467
+|   <body>
468
+|     "FOOœZOO"
469
+
470
+#data
471
+FOO&#x009D;ZOO
472
+#errors
473
+#document
474
+| <html>
475
+|   <head>
476
+|   <body>
477
+|     "FOOZOO"
478
+
479
+#data
480
+FOO&#x009E;ZOO
481
+#errors
482
+#document
483
+| <html>
484
+|   <head>
485
+|   <body>
486
+|     "FOOžZOO"
487
+
488
+#data
489
+FOO&#x009F;ZOO
490
+#errors
491
+#document
492
+| <html>
493
+|   <head>
494
+|   <body>
495
+|     "FOOŸZOO"
496
+
497
+#data
498
+FOO&#x00A0;ZOO
499
+#errors
500
+#document
501
+| <html>
502
+|   <head>
503
+|   <body>
504
+|     "FOO ZOO"
505
+
506
+#data
507
+FOO&#xD7FF;ZOO
508
+#errors
509
+#document
510
+| <html>
511
+|   <head>
512
+|   <body>
513
+|     "FOO퟿ZOO"
514
+
515
+#data
516
+FOO&#xD800;ZOO
517
+#errors
518
+#document
519
+| <html>
520
+|   <head>
521
+|   <body>
522
+|     "FOO�ZOO"
523
+
524
+#data
525
+FOO&#xD801;ZOO
526
+#errors
527
+#document
528
+| <html>
529
+|   <head>
530
+|   <body>
531
+|     "FOO�ZOO"
532
+
533
+#data
534
+FOO&#xDFFE;ZOO
535
+#errors
536
+#document
537
+| <html>
538
+|   <head>
539
+|   <body>
540
+|     "FOO�ZOO"
541
+
542
+#data
543
+FOO&#xDFFF;ZOO
544
+#errors
545
+#document
546
+| <html>
547
+|   <head>
548
+|   <body>
549
+|     "FOO�ZOO"
550
+
551
+#data
552
+FOO&#xE000;ZOO
553
+#errors
554
+#document
555
+| <html>
556
+|   <head>
557
+|   <body>
558
+|     "FOOZOO"
559
+
560
+#data
561
+FOO&#x10FFFE;ZOO
562
+#errors
563
+#document
564
+| <html>
565
+|   <head>
566
+|   <body>
567
+|     "FOO􏿾ZOO"
568
+
569
+#data
570
+FOO&#x1087D4;ZOO
571
+#errors
572
+#document
573
+| <html>
574
+|   <head>
575
+|   <body>
576
+|     "FOO􈟔ZOO"
577
+
578
+#data
579
+FOO&#x10FFFF;ZOO
580
+#errors
581
+#document
582
+| <html>
583
+|   <head>
584
+|   <body>
585
+|     "FOO􏿿ZOO"
586
+
587
+#data
588
+FOO&#x110000;ZOO
589
+#errors
590
+#document
591
+| <html>
592
+|   <head>
593
+|   <body>
594
+|     "FOO�ZOO"
595
+
596
+#data
597
+FOO&#xFFFFFF;ZOO
598
+#errors
599
+#document
600
+| <html>
601
+|   <head>
602
+|   <body>
603
+|     "FOO�ZOO"

+ 249
- 0
vendor/golang.org/x/net/html/testdata/webkit/entities02.dat View File

@@ -0,0 +1,249 @@
1
+#data
2
+<div bar="ZZ&gt;YY"></div>
3
+#errors
4
+#document
5
+| <html>
6
+|   <head>
7
+|   <body>
8
+|     <div>
9
+|       bar="ZZ>YY"
10
+
11
+#data
12
+<div bar="ZZ&"></div>
13
+#errors
14
+#document
15
+| <html>
16
+|   <head>
17
+|   <body>
18
+|     <div>
19
+|       bar="ZZ&"
20
+
21
+#data
22
+<div bar='ZZ&'></div>
23
+#errors
24
+#document
25
+| <html>
26
+|   <head>
27
+|   <body>
28
+|     <div>
29
+|       bar="ZZ&"
30
+
31
+#data
32
+<div bar=ZZ&></div>
33
+#errors
34
+#document
35
+| <html>
36
+|   <head>
37
+|   <body>
38
+|     <div>
39
+|       bar="ZZ&"
40
+
41
+#data
42
+<div bar="ZZ&gt=YY"></div>
43
+#errors
44
+#document
45
+| <html>
46
+|   <head>
47
+|   <body>
48
+|     <div>
49
+|       bar="ZZ&gt=YY"
50
+
51
+#data
52
+<div bar="ZZ&gt0YY"></div>
53
+#errors
54
+#document
55
+| <html>
56
+|   <head>
57
+|   <body>
58
+|     <div>
59
+|       bar="ZZ&gt0YY"
60
+
61
+#data
62
+<div bar="ZZ&gt9YY"></div>
63
+#errors
64
+#document
65
+| <html>
66
+|   <head>
67
+|   <body>
68
+|     <div>
69
+|       bar="ZZ&gt9YY"
70
+
71
+#data
72
+<div bar="ZZ&gtaYY"></div>
73
+#errors
74
+#document
75
+| <html>
76
+|   <head>
77
+|   <body>
78
+|     <div>
79
+|       bar="ZZ&gtaYY"
80
+
81
+#data
82
+<div bar="ZZ&gtZYY"></div>
83
+#errors
84
+#document
85
+| <html>
86
+|   <head>
87
+|   <body>
88
+|     <div>
89
+|       bar="ZZ&gtZYY"
90
+
91
+#data
92
+<div bar="ZZ&gt YY"></div>
93
+#errors
94
+#document
95
+| <html>
96
+|   <head>
97
+|   <body>
98
+|     <div>
99
+|       bar="ZZ> YY"
100
+
101
+#data
102
+<div bar="ZZ&gt"></div>
103
+#errors
104
+#document
105
+| <html>
106
+|   <head>
107
+|   <body>
108
+|     <div>
109
+|       bar="ZZ>"
110
+
111
+#data
112
+<div bar='ZZ&gt'></div>
113
+#errors
114
+#document
115
+| <html>
116
+|   <head>
117
+|   <body>
118
+|     <div>
119
+|       bar="ZZ>"
120
+
121
+#data
122
+<div bar=ZZ&gt></div>
123
+#errors
124
+#document
125
+| <html>
126
+|   <head>
127
+|   <body>
128
+|     <div>
129
+|       bar="ZZ>"
130
+
131
+#data
132
+<div bar="ZZ&pound_id=23"></div>
133
+#errors
134
+#document
135
+| <html>
136
+|   <head>
137
+|   <body>
138
+|     <div>
139
+|       bar="ZZ£_id=23"
140
+
141
+#data
142
+<div bar="ZZ&prod_id=23"></div>
143
+#errors
144
+#document
145
+| <html>
146
+|   <head>
147
+|   <body>
148
+|     <div>
149
+|       bar="ZZ&prod_id=23"
150
+
151
+#data
152
+<div bar="ZZ&pound;_id=23"></div>
153
+#errors
154
+#document
155
+| <html>
156
+|   <head>
157
+|   <body>
158
+|     <div>
159
+|       bar="ZZ£_id=23"
160
+
161
+#data
162
+<div bar="ZZ&prod;_id=23"></div>
163
+#errors
164
+#document
165
+| <html>
166
+|   <head>
167
+|   <body>
168
+|     <div>
169
+|       bar="ZZ∏_id=23"
170
+
171
+#data
172
+<div bar="ZZ&pound=23"></div>
173
+#errors
174
+#document
175
+| <html>
176
+|   <head>
177
+|   <body>
178
+|     <div>
179
+|       bar="ZZ&pound=23"
180
+
181
+#data
182
+<div bar="ZZ&prod=23"></div>
183
+#errors
184
+#document
185
+| <html>
186
+|   <head>
187
+|   <body>
188
+|     <div>
189
+|       bar="ZZ&prod=23"
190
+
191
+#data
192
+<div>ZZ&pound_id=23</div>
193
+#errors
194
+#document
195
+| <html>
196
+|   <head>
197
+|   <body>
198
+|     <div>
199
+|       "ZZ£_id=23"
200
+
201
+#data
202
+<div>ZZ&prod_id=23</div>
203
+#errors
204
+#document
205
+| <html>
206
+|   <head>
207
+|   <body>
208
+|     <div>
209
+|       "ZZ&prod_id=23"
210
+
211
+#data
212
+<div>ZZ&pound;_id=23</div>
213
+#errors
214
+#document
215
+| <html>
216
+|   <head>
217
+|   <body>
218
+|     <div>
219
+|       "ZZ£_id=23"
220
+
221
+#data
222
+<div>ZZ&prod;_id=23</div>
223
+#errors
224
+#document
225
+| <html>
226
+|   <head>
227
+|   <body>
228
+|     <div>
229
+|       "ZZ∏_id=23"
230
+
231
+#data
232
+<div>ZZ&pound=23</div>
233
+#errors
234
+#document
235
+| <html>
236
+|   <head>
237
+|   <body>
238
+|     <div>
239
+|       "ZZ£=23"
240
+
241
+#data
242
+<div>ZZ&prod=23</div>
243
+#errors
244
+#document
245
+| <html>
246
+|   <head>
247
+|   <body>
248
+|     <div>
249
+|       "ZZ&prod=23"

+ 246
- 0
vendor/golang.org/x/net/html/testdata/webkit/html5test-com.dat View File

@@ -0,0 +1,246 @@
1
+#data
2
+<div<div>
3
+#errors
4
+#document
5
+| <html>
6
+|   <head>
7
+|   <body>
8
+|     <div<div>
9
+
10
+#data
11
+<div foo<bar=''>
12
+#errors
13
+#document
14
+| <html>
15
+|   <head>
16
+|   <body>
17
+|     <div>
18
+|       foo<bar=""
19
+
20
+#data
21
+<div foo=`bar`>
22
+#errors
23
+#document
24
+| <html>
25
+|   <head>
26
+|   <body>
27
+|     <div>
28
+|       foo="`bar`"
29
+
30
+#data
31
+<div \"foo=''>
32
+#errors
33
+#document
34
+| <html>
35
+|   <head>
36
+|   <body>
37
+|     <div>
38
+|       \"foo=""
39
+
40
+#data
41
+<a href='\nbar'></a>
42
+#errors
43
+#document
44
+| <html>
45
+|   <head>
46
+|   <body>
47
+|     <a>
48
+|       href="\nbar"
49
+
50
+#data
51
+<!DOCTYPE html>
52
+#errors
53
+#document
54
+| <!DOCTYPE html>
55
+| <html>
56
+|   <head>
57
+|   <body>
58
+
59
+#data
60
+&lang;&rang;
61
+#errors
62
+#document
63
+| <html>
64
+|   <head>
65
+|   <body>
66
+|     "⟨⟩"
67
+
68
+#data
69
+&apos;
70
+#errors
71
+#document
72
+| <html>
73
+|   <head>
74
+|   <body>
75
+|     "'"
76
+
77
+#data
78
+&ImaginaryI;
79
+#errors
80
+#document
81
+| <html>
82
+|   <head>
83
+|   <body>
84
+|     "ⅈ"
85
+
86
+#data
87
+&Kopf;
88
+#errors
89
+#document
90
+| <html>
91
+|   <head>
92
+|   <body>
93
+|     "𝕂"
94
+
95
+#data
96
+&notinva;
97
+#errors
98
+#document
99
+| <html>
100
+|   <head>
101
+|   <body>
102
+|     "∉"
103
+
104
+#data
105
+<?import namespace="foo" implementation="#bar">
106
+#errors
107
+#document
108
+| <!-- ?import namespace="foo" implementation="#bar" -->
109
+| <html>
110
+|   <head>
111
+|   <body>
112
+
113
+#data
114
+<!--foo--bar-->
115
+#errors
116
+#document
117
+| <!-- foo--bar -->
118
+| <html>
119
+|   <head>
120
+|   <body>
121
+
122
+#data
123
+<![CDATA[x]]>
124
+#errors
125
+#document
126
+| <!-- [CDATA[x]] -->
127
+| <html>
128
+|   <head>
129
+|   <body>
130
+
131
+#data
132
+<textarea><!--</textarea>--></textarea>
133
+#errors
134
+#document
135
+| <html>
136
+|   <head>
137
+|   <body>
138
+|     <textarea>
139
+|       "<!--"
140
+|     "-->"
141
+
142
+#data
143
+<textarea><!--</textarea>-->
144
+#errors
145
+#document
146
+| <html>
147
+|   <head>
148
+|   <body>
149
+|     <textarea>
150
+|       "<!--"
151
+|     "-->"
152
+
153
+#data
154
+<style><!--</style>--></style>
155
+#errors
156
+#document
157
+| <html>
158
+|   <head>
159
+|     <style>
160
+|       "<!--"
161
+|   <body>
162
+|     "-->"
163
+
164
+#data
165
+<style><!--</style>-->
166
+#errors
167
+#document
168
+| <html>
169
+|   <head>
170
+|     <style>
171
+|       "<!--"
172
+|   <body>
173
+|     "-->"
174
+
175
+#data
176
+<ul><li>A </li> <li>B</li></ul>
177
+#errors
178
+#document
179
+| <html>
180
+|   <head>
181
+|   <body>
182
+|     <ul>
183
+|       <li>
184
+|         "A "
185
+|       " "
186
+|       <li>
187
+|         "B"
188
+
189
+#data
190
+<table><form><input type=hidden><input></form><div></div></table>
191
+#errors
192
+#document
193
+| <html>
194
+|   <head>
195
+|   <body>
196
+|     <input>
197
+|     <div>
198
+|     <table>
199
+|       <form>
200
+|       <input>
201
+|         type="hidden"
202
+
203
+#data
204
+<i>A<b>B<p></i>C</b>D
205
+#errors
206
+#document
207
+| <html>
208
+|   <head>
209
+|   <body>
210
+|     <i>
211
+|       "A"
212
+|       <b>
213
+|         "B"
214
+|     <b>
215
+|     <p>
216
+|       <b>
217
+|         <i>
218
+|         "C"
219
+|       "D"
220
+
221
+#data
222
+<div></div>
223
+#errors
224
+#document
225
+| <html>
226
+|   <head>
227
+|   <body>
228
+|     <div>
229
+
230
+#data
231
+<svg></svg>
232
+#errors
233
+#document
234
+| <html>
235
+|   <head>
236
+|   <body>
237
+|     <svg svg>
238
+
239
+#data
240
+<math></math>
241
+#errors
242
+#document
243
+| <html>
244
+|   <head>
245
+|   <body>
246
+|     <math math>

+ 43
- 0
vendor/golang.org/x/net/html/testdata/webkit/inbody01.dat View File

@@ -0,0 +1,43 @@
1
+#data
2
+<button>1</foo>
3
+#errors
4
+#document
5
+| <html>
6
+|   <head>
7
+|   <body>
8
+|     <button>
9
+|       "1"
10
+
11
+#data
12
+<foo>1<p>2</foo>
13
+#errors
14
+#document
15
+| <html>
16
+|   <head>
17
+|   <body>
18
+|     <foo>
19
+|       "1"
20
+|       <p>
21
+|         "2"
22
+
23
+#data
24
+<dd>1</foo>
25
+#errors
26
+#document
27
+| <html>
28
+|   <head>
29
+|   <body>
30
+|     <dd>
31
+|       "1"
32
+
33
+#data
34
+<foo>1<dd>2</foo>
35
+#errors
36
+#document
37
+| <html>
38
+|   <head>
39
+|   <body>
40
+|     <foo>
41
+|       "1"
42
+|       <dd>
43
+|         "2"

+ 40
- 0
vendor/golang.org/x/net/html/testdata/webkit/isindex.dat View File

@@ -0,0 +1,40 @@
1
+#data
2
+<isindex>
3
+#errors
4
+#document
5
+| <html>
6
+|   <head>
7
+|   <body>
8
+|     <form>
9
+|       <hr>
10
+|       <label>
11
+|         "This is a searchable index. Enter search keywords: "
12
+|         <input>
13
+|           name="isindex"
14
+|       <hr>
15
+
16
+#data
17
+<isindex name="A" action="B" prompt="C" foo="D">
18
+#errors
19
+#document
20
+| <html>
21
+|   <head>
22
+|   <body>
23
+|     <form>
24
+|       action="B"
25
+|       <hr>
26
+|       <label>
27
+|         "C"
28
+|         <input>
29
+|           foo="D"
30
+|           name="isindex"
31
+|       <hr>
32
+
33
+#data
34
+<form><isindex>
35
+#errors
36
+#document
37
+| <html>
38
+|   <head>
39
+|   <body>
40
+|     <form>

BIN
vendor/golang.org/x/net/html/testdata/webkit/pending-spec-changes-plain-text-unsafe.dat View File


+ 52
- 0
vendor/golang.org/x/net/html/testdata/webkit/pending-spec-changes.dat View File

@@ -0,0 +1,52 @@
1
+#data
2
+<input type="hidden"><frameset>
3
+#errors
4
+21: Start tag seen without seeing a doctype first. Expected “<!DOCTYPE html>”.
5
+31: “frameset” start tag seen.
6
+31: End of file seen and there were open elements.
7
+#document
8
+| <html>
9
+|   <head>
10
+|   <frameset>
11
+
12
+#data
13
+<!DOCTYPE html><table><caption><svg>foo</table>bar
14
+#errors
15
+47: End tag “table” did not match the name of the current open element (“svg”).
16
+47: “table” closed but “caption” was still open.
17
+47: End tag “table” seen, but there were open elements.
18
+36: Unclosed element “svg”.
19
+#document
20
+| <!DOCTYPE html>
21
+| <html>
22
+|   <head>
23
+|   <body>
24
+|     <table>
25
+|       <caption>
26
+|         <svg svg>
27
+|           "foo"
28
+|     "bar"
29
+
30
+#data
31
+<table><tr><td><svg><desc><td></desc><circle>
32
+#errors
33
+7: Start tag seen without seeing a doctype first. Expected “<!DOCTYPE html>”.
34
+30: A table cell was implicitly closed, but there were open elements.
35
+26: Unclosed element “desc”.
36
+20: Unclosed element “svg”.
37
+37: Stray end tag “desc”.
38
+45: End of file seen and there were open elements.
39
+45: Unclosed element “circle”.
40
+7: Unclosed element “table”.
41
+#document
42
+| <html>
43
+|   <head>
44
+|   <body>
45
+|     <table>
46
+|       <tbody>
47
+|         <tr>
48
+|           <td>
49
+|             <svg svg>
50
+|               <svg desc>
51
+|           <td>
52
+|             <circle>

BIN
vendor/golang.org/x/net/html/testdata/webkit/plain-text-unsafe.dat View File


+ 308
- 0
vendor/golang.org/x/net/html/testdata/webkit/scriptdata01.dat View File

@@ -0,0 +1,308 @@
1
+#data
2
+FOO<script>'Hello'</script>BAR
3
+#errors
4
+#document
5
+| <html>
6
+|   <head>
7
+|   <body>
8
+|     "FOO"
9
+|     <script>
10
+|       "'Hello'"
11
+|     "BAR"
12
+
13
+#data
14
+FOO<script></script>BAR
15
+#errors
16
+#document
17
+| <html>
18
+|   <head>
19
+|   <body>
20
+|     "FOO"
21
+|     <script>
22
+|     "BAR"
23
+
24
+#data
25
+FOO<script></script >BAR
26
+#errors
27
+#document
28
+| <html>
29
+|   <head>
30
+|   <body>
31
+|     "FOO"
32
+|     <script>
33
+|     "BAR"
34
+
35
+#data
36
+FOO<script></script/>BAR
37
+#errors
38
+#document
39
+| <html>
40
+|   <head>
41
+|   <body>
42
+|     "FOO"
43
+|     <script>
44
+|     "BAR"
45
+
46
+#data
47
+FOO<script></script/ >BAR
48
+#errors
49
+#document
50
+| <html>
51
+|   <head>
52
+|   <body>
53
+|     "FOO"
54
+|     <script>
55
+|     "BAR"
56
+
57
+#data
58
+FOO<script type="text/plain"></scriptx>BAR
59
+#errors
60
+#document
61
+| <html>
62
+|   <head>
63
+|   <body>
64
+|     "FOO"
65
+|     <script>
66
+|       type="text/plain"
67
+|       "</scriptx>BAR"
68
+
69
+#data
70
+FOO<script></script foo=">" dd>BAR
71
+#errors
72
+#document
73
+| <html>
74
+|   <head>
75
+|   <body>
76
+|     "FOO"
77
+|     <script>
78
+|     "BAR"
79
+
80
+#data
81
+FOO<script>'<'</script>BAR
82
+#errors
83
+#document
84
+| <html>
85
+|   <head>
86
+|   <body>
87
+|     "FOO"
88
+|     <script>
89
+|       "'<'"
90
+|     "BAR"
91
+
92
+#data
93
+FOO<script>'<!'</script>BAR
94
+#errors
95
+#document
96
+| <html>
97
+|   <head>
98
+|   <body>
99
+|     "FOO"
100
+|     <script>
101
+|       "'<!'"
102
+|     "BAR"
103
+
104
+#data
105
+FOO<script>'<!-'</script>BAR
106
+#errors
107
+#document
108
+| <html>
109
+|   <head>
110
+|   <body>
111
+|     "FOO"
112
+|     <script>
113
+|       "'<!-'"
114
+|     "BAR"
115
+
116
+#data
117
+FOO<script>'<!--'</script>BAR
118
+#errors
119
+#document
120
+| <html>
121
+|   <head>
122
+|   <body>
123
+|     "FOO"
124
+|     <script>
125
+|       "'<!--'"
126
+|     "BAR"
127
+
128
+#data
129
+FOO<script>'<!---'</script>BAR
130
+#errors
131
+#document
132
+| <html>
133
+|   <head>
134
+|   <body>
135
+|     "FOO"
136
+|     <script>
137
+|       "'<!---'"
138
+|     "BAR"
139
+
140
+#data
141
+FOO<script>'<!-->'</script>BAR
142
+#errors
143
+#document
144
+| <html>
145
+|   <head>
146
+|   <body>
147
+|     "FOO"
148
+|     <script>
149
+|       "'<!-->'"
150
+|     "BAR"
151
+
152
+#data
153
+FOO<script>'<!-->'</script>BAR
154
+#errors
155
+#document
156
+| <html>
157
+|   <head>
158
+|   <body>
159
+|     "FOO"
160
+|     <script>
161
+|       "'<!-->'"
162
+|     "BAR"
163
+
164
+#data
165
+FOO<script>'<!-- potato'</script>BAR
166
+#errors
167
+#document
168
+| <html>
169
+|   <head>
170
+|   <body>
171
+|     "FOO"
172
+|     <script>
173
+|       "'<!-- potato'"
174
+|     "BAR"
175
+
176
+#data
177
+FOO<script>'<!-- <sCrIpt'</script>BAR
178
+#errors
179
+#document
180
+| <html>
181
+|   <head>
182
+|   <body>
183
+|     "FOO"
184
+|     <script>
185
+|       "'<!-- <sCrIpt'"
186
+|     "BAR"
187
+
188
+#data
189
+FOO<script type="text/plain">'<!-- <sCrIpt>'</script>BAR
190
+#errors
191
+#document
192
+| <html>
193
+|   <head>
194
+|   <body>
195
+|     "FOO"
196
+|     <script>
197
+|       type="text/plain"
198
+|       "'<!-- <sCrIpt>'</script>BAR"
199
+
200
+#data
201
+FOO<script type="text/plain">'<!-- <sCrIpt> -'</script>BAR
202
+#errors
203
+#document
204
+| <html>
205
+|   <head>
206
+|   <body>
207
+|     "FOO"
208
+|     <script>
209
+|       type="text/plain"
210
+|       "'<!-- <sCrIpt> -'</script>BAR"
211
+
212
+#data
213
+FOO<script type="text/plain">'<!-- <sCrIpt> --'</script>BAR
214
+#errors
215
+#document
216
+| <html>
217
+|   <head>
218
+|   <body>
219
+|     "FOO"
220
+|     <script>
221
+|       type="text/plain"
222
+|       "'<!-- <sCrIpt> --'</script>BAR"
223
+
224
+#data
225
+FOO<script>'<!-- <sCrIpt> -->'</script>BAR
226
+#errors
227
+#document
228
+| <html>
229
+|   <head>
230
+|   <body>
231
+|     "FOO"
232
+|     <script>
233
+|       "'<!-- <sCrIpt> -->'"
234
+|     "BAR"
235
+
236
+#data
237
+FOO<script type="text/plain">'<!-- <sCrIpt> --!>'</script>BAR
238
+#errors
239
+#document
240
+| <html>
241
+|   <head>
242
+|   <body>
243
+|     "FOO"
244
+|     <script>
245
+|       type="text/plain"
246
+|       "'<!-- <sCrIpt> --!>'</script>BAR"
247
+
248
+#data
249
+FOO<script type="text/plain">'<!-- <sCrIpt> -- >'</script>BAR
250
+#errors
251
+#document
252
+| <html>
253
+|   <head>
254
+|   <body>
255
+|     "FOO"
256
+|     <script>
257
+|       type="text/plain"
258
+|       "'<!-- <sCrIpt> -- >'</script>BAR"
259
+
260
+#data
261
+FOO<script type="text/plain">'<!-- <sCrIpt '</script>BAR
262
+#errors
263
+#document
264
+| <html>
265
+|   <head>
266
+|   <body>
267
+|     "FOO"
268
+|     <script>
269
+|       type="text/plain"
270
+|       "'<!-- <sCrIpt '</script>BAR"
271
+
272
+#data
273
+FOO<script type="text/plain">'<!-- <sCrIpt/'</script>BAR
274
+#errors
275
+#document
276
+| <html>
277
+|   <head>
278
+|   <body>
279
+|     "FOO"
280
+|     <script>
281
+|       type="text/plain"
282
+|       "'<!-- <sCrIpt/'</script>BAR"
283
+
284
+#data
285
+FOO<script type="text/plain">'<!-- <sCrIpt\'</script>BAR
286
+#errors
287
+#document
288
+| <html>
289
+|   <head>
290
+|   <body>
291
+|     "FOO"
292
+|     <script>
293
+|       type="text/plain"
294
+|       "'<!-- <sCrIpt\'"
295
+|     "BAR"
296
+
297
+#data
298
+FOO<script type="text/plain">'<!-- <sCrIpt/'</script>BAR</script>QUX
299
+#errors
300
+#document
301
+| <html>
302
+|   <head>
303
+|   <body>
304
+|     "FOO"
305
+|     <script>
306
+|       type="text/plain"
307
+|       "'<!-- <sCrIpt/'</script>BAR"
308
+|     "QUX"

+ 15
- 0
vendor/golang.org/x/net/html/testdata/webkit/scripted/adoption01.dat View File

@@ -0,0 +1,15 @@
1
+#data
2
+<p><b id="A"><script>document.getElementById("A").id = "B"</script></p>TEXT</b>
3
+#errors
4
+#document
5
+| <html>
6
+|   <head>
7
+|   <body>
8
+|     <p>
9
+|       <b>
10
+|         id="B"
11
+|         <script>
12
+|           "document.getElementById("A").id = "B""
13
+|     <b>
14
+|       id="A"
15
+|       "TEXT"

+ 28
- 0
vendor/golang.org/x/net/html/testdata/webkit/scripted/webkit01.dat View File

@@ -0,0 +1,28 @@
1
+#data
2
+1<script>document.write("2")</script>3
3
+#errors
4
+#document
5
+| <html>
6
+|   <head>
7
+|   <body>
8
+|     "1"
9
+|     <script>
10
+|       "document.write("2")"
11
+|     "23"
12
+
13
+#data
14
+1<script>document.write("<script>document.write('2')</scr"+ "ipt><script>document.write('3')</scr" + "ipt>")</script>4
15
+#errors
16
+#document
17
+| <html>
18
+|   <head>
19
+|   <body>
20
+|     "1"
21
+|     <script>
22
+|       "document.write("<script>document.write('2')</scr"+ "ipt><script>document.write('3')</scr" + "ipt>")"
23
+|     <script>
24
+|       "document.write('2')"
25
+|     "2"
26
+|     <script>
27
+|       "document.write('3')"
28
+|     "34"

+ 212
- 0
vendor/golang.org/x/net/html/testdata/webkit/tables01.dat View File

@@ -0,0 +1,212 @@
1
+#data
2
+<table><th>
3
+#errors
4
+#document
5
+| <html>
6
+|   <head>
7
+|   <body>
8
+|     <table>
9
+|       <tbody>
10
+|         <tr>
11
+|           <th>
12
+
13
+#data
14
+<table><td>
15
+#errors
16
+#document
17
+| <html>
18
+|   <head>
19
+|   <body>
20
+|     <table>
21
+|       <tbody>
22
+|         <tr>
23
+|           <td>
24
+
25
+#data
26
+<table><col foo='bar'>
27
+#errors
28
+#document
29
+| <html>
30
+|   <head>
31
+|   <body>
32
+|     <table>
33
+|       <colgroup>
34
+|         <col>
35
+|           foo="bar"
36
+
37
+#data
38
+<table><colgroup></html>foo
39
+#errors
40
+#document
41
+| <html>
42
+|   <head>
43
+|   <body>
44
+|     "foo"
45
+|     <table>
46
+|       <colgroup>
47
+
48
+#data
49
+<table></table><p>foo
50
+#errors
51
+#document
52
+| <html>
53
+|   <head>
54
+|   <body>
55
+|     <table>
56
+|     <p>
57
+|       "foo"
58
+
59
+#data
60
+<table></body></caption></col></colgroup></html></tbody></td></tfoot></th></thead></tr><td>
61
+#errors
62
+#document
63
+| <html>
64
+|   <head>
65
+|   <body>
66
+|     <table>
67
+|       <tbody>
68
+|         <tr>
69
+|           <td>
70
+
71
+#data
72
+<table><select><option>3</select></table>
73
+#errors
74
+#document
75
+| <html>
76
+|   <head>
77
+|   <body>
78
+|     <select>
79
+|       <option>
80
+|         "3"
81
+|     <table>
82
+
83
+#data
84
+<table><select><table></table></select></table>
85
+#errors
86
+#document
87
+| <html>
88
+|   <head>
89
+|   <body>
90
+|     <select>
91
+|     <table>
92
+|     <table>
93
+
94
+#data
95
+<table><select></table>
96
+#errors
97
+#document
98
+| <html>
99
+|   <head>
100
+|   <body>
101
+|     <select>
102
+|     <table>
103
+
104
+#data
105
+<table><select><option>A<tr><td>B</td></tr></table>
106
+#errors
107
+#document
108
+| <html>
109
+|   <head>
110
+|   <body>
111
+|     <select>
112
+|       <option>
113
+|         "A"
114
+|     <table>
115
+|       <tbody>
116
+|         <tr>
117
+|           <td>
118
+|             "B"
119
+
120
+#data
121
+<table><td></body></caption></col></colgroup></html>foo
122
+#errors
123
+#document
124
+| <html>
125
+|   <head>
126
+|   <body>
127
+|     <table>
128
+|       <tbody>
129
+|         <tr>
130
+|           <td>
131
+|             "foo"
132
+
133
+#data
134
+<table><td>A</table>B
135
+#errors
136
+#document
137
+| <html>
138
+|   <head>
139
+|   <body>
140
+|     <table>
141
+|       <tbody>
142
+|         <tr>
143
+|           <td>
144
+|             "A"
145
+|     "B"
146
+
147
+#data
148
+<table><tr><caption>
149
+#errors
150
+#document
151
+| <html>
152
+|   <head>
153
+|   <body>
154
+|     <table>
155
+|       <tbody>
156
+|         <tr>
157
+|       <caption>
158
+
159
+#data
160
+<table><tr></body></caption></col></colgroup></html></td></th><td>foo
161
+#errors
162
+#document
163
+| <html>
164
+|   <head>
165
+|   <body>
166
+|     <table>
167
+|       <tbody>
168
+|         <tr>
169
+|           <td>
170
+|             "foo"
171
+
172
+#data
173
+<table><td><tr>
174
+#errors
175
+#document
176
+| <html>
177
+|   <head>
178
+|   <body>
179
+|     <table>
180
+|       <tbody>
181
+|         <tr>
182
+|           <td>
183
+|         <tr>
184
+
185
+#data
186
+<table><td><button><td>
187
+#errors
188
+#document
189
+| <html>
190
+|   <head>
191
+|   <body>
192
+|     <table>
193
+|       <tbody>
194
+|         <tr>
195
+|           <td>
196
+|             <button>
197
+|           <td>
198
+
199
+#data
200
+<table><tr><td><svg><desc><td>
201
+#errors
202
+#document
203
+| <html>
204
+|   <head>
205
+|   <body>
206
+|     <table>
207
+|       <tbody>
208
+|         <tr>
209
+|           <td>
210
+|             <svg svg>
211
+|               <svg desc>
212
+|           <td>

+ 1952
- 0
vendor/golang.org/x/net/html/testdata/webkit/tests1.dat
File diff suppressed because it is too large
View File


+ 799
- 0
vendor/golang.org/x/net/html/testdata/webkit/tests10.dat View File

@@ -0,0 +1,799 @@
1
+#data
2
+<!DOCTYPE html><svg></svg>
3
+#errors
4
+#document
5
+| <!DOCTYPE html>
6
+| <html>
7
+|   <head>
8
+|   <body>
9
+|     <svg svg>
10
+
11
+#data
12
+<!DOCTYPE html><svg></svg><![CDATA[a]]>
13
+#errors
14
+29: Bogus comment
15
+#document
16
+| <!DOCTYPE html>
17
+| <html>
18
+|   <head>
19
+|   <body>
20
+|     <svg svg>
21
+|     <!-- [CDATA[a]] -->
22
+
23
+#data
24
+<!DOCTYPE html><body><svg></svg>
25
+#errors
26
+#document
27
+| <!DOCTYPE html>
28
+| <html>
29
+|   <head>
30
+|   <body>
31
+|     <svg svg>
32
+
33
+#data
34
+<!DOCTYPE html><body><select><svg></svg></select>
35
+#errors
36
+35: Stray “svg” start tag.
37
+42: Stray end tag “svg”
38
+#document
39
+| <!DOCTYPE html>
40
+| <html>
41
+|   <head>
42
+|   <body>
43
+|     <select>
44
+
45
+#data
46
+<!DOCTYPE html><body><select><option><svg></svg></option></select>
47
+#errors
48
+43: Stray “svg” start tag.
49
+50: Stray end tag “svg”
50
+#document
51
+| <!DOCTYPE html>
52
+| <html>
53
+|   <head>
54
+|   <body>
55
+|     <select>
56
+|       <option>
57
+
58
+#data
59
+<!DOCTYPE html><body><table><svg></svg></table>
60
+#errors
61
+34: Start tag “svg” seen in “table”.
62
+41: Stray end tag “svg”.
63
+#document
64
+| <!DOCTYPE html>
65
+| <html>
66
+|   <head>
67
+|   <body>
68
+|     <svg svg>
69
+|     <table>
70
+
71
+#data
72
+<!DOCTYPE html><body><table><svg><g>foo</g></svg></table>
73
+#errors
74
+34: Start tag “svg” seen in “table”.
75
+46: Stray end tag “g”.
76
+53: Stray end tag “svg”.
77
+#document
78
+| <!DOCTYPE html>
79
+| <html>
80
+|   <head>
81
+|   <body>
82
+|     <svg svg>
83
+|       <svg g>
84
+|         "foo"
85
+|     <table>
86
+
87
+#data
88
+<!DOCTYPE html><body><table><svg><g>foo</g><g>bar</g></svg></table>
89
+#errors
90
+34: Start tag “svg” seen in “table”.
91
+46: Stray end tag “g”.
92
+58: Stray end tag “g”.
93
+65: Stray end tag “svg”.
94
+#document
95
+| <!DOCTYPE html>
96
+| <html>
97
+|   <head>
98
+|   <body>
99
+|     <svg svg>
100
+|       <svg g>
101
+|         "foo"
102
+|       <svg g>
103
+|         "bar"
104
+|     <table>
105
+
106
+#data
107
+<!DOCTYPE html><body><table><tbody><svg><g>foo</g><g>bar</g></svg></tbody></table>
108
+#errors
109
+41: Start tag “svg” seen in “table”.
110
+53: Stray end tag “g”.
111
+65: Stray end tag “g”.
112
+72: Stray end tag “svg”.
113
+#document
114
+| <!DOCTYPE html>
115
+| <html>
116
+|   <head>
117
+|   <body>
118
+|     <svg svg>
119
+|       <svg g>
120
+|         "foo"
121
+|       <svg g>
122
+|         "bar"
123
+|     <table>
124
+|       <tbody>
125
+
126
+#data
127
+<!DOCTYPE html><body><table><tbody><tr><svg><g>foo</g><g>bar</g></svg></tr></tbody></table>
128
+#errors
129
+45: Start tag “svg” seen in “table”.
130
+57: Stray end tag “g”.
131
+69: Stray end tag “g”.
132
+76: Stray end tag “svg”.
133
+#document
134
+| <!DOCTYPE html>
135
+| <html>
136
+|   <head>
137
+|   <body>
138
+|     <svg svg>
139
+|       <svg g>
140
+|         "foo"
141
+|       <svg g>
142
+|         "bar"
143
+|     <table>
144
+|       <tbody>
145
+|         <tr>
146
+
147
+#data
148
+<!DOCTYPE html><body><table><tbody><tr><td><svg><g>foo</g><g>bar</g></svg></td></tr></tbody></table>
149
+#errors
150
+#document
151
+| <!DOCTYPE html>
152
+| <html>
153
+|   <head>
154
+|   <body>
155
+|     <table>
156
+|       <tbody>
157
+|         <tr>
158
+|           <td>
159
+|             <svg svg>
160
+|               <svg g>
161
+|                 "foo"
162
+|               <svg g>
163
+|                 "bar"
164
+
165
+#data
166
+<!DOCTYPE html><body><table><tbody><tr><td><svg><g>foo</g><g>bar</g></svg><p>baz</td></tr></tbody></table>
167
+#errors
168
+#document
169
+| <!DOCTYPE html>
170
+| <html>
171
+|   <head>
172
+|   <body>
173
+|     <table>
174
+|       <tbody>
175
+|         <tr>
176
+|           <td>
177
+|             <svg svg>
178
+|               <svg g>
179
+|                 "foo"
180
+|               <svg g>
181
+|                 "bar"
182
+|             <p>
183
+|               "baz"
184
+
185
+#data
186
+<!DOCTYPE html><body><table><caption><svg><g>foo</g><g>bar</g></svg><p>baz</caption></table>
187
+#errors
188
+#document
189
+| <!DOCTYPE html>
190
+| <html>
191
+|   <head>
192
+|   <body>
193
+|     <table>
194
+|       <caption>
195
+|         <svg svg>
196
+|           <svg g>
197
+|             "foo"
198
+|           <svg g>
199
+|             "bar"
200
+|         <p>
201
+|           "baz"
202
+
203
+#data
204
+<!DOCTYPE html><body><table><caption><svg><g>foo</g><g>bar</g><p>baz</table><p>quux
205
+#errors
206
+70: HTML start tag “p” in a foreign namespace context.
207
+81: “table” closed but “caption” was still open.
208
+#document
209
+| <!DOCTYPE html>
210
+| <html>
211
+|   <head>
212
+|   <body>
213
+|     <table>
214
+|       <caption>
215
+|         <svg svg>
216
+|           <svg g>
217
+|             "foo"
218
+|           <svg g>
219
+|             "bar"
220
+|         <p>
221
+|           "baz"
222
+|     <p>
223
+|       "quux"
224
+
225
+#data
226
+<!DOCTYPE html><body><table><caption><svg><g>foo</g><g>bar</g>baz</table><p>quux
227
+#errors
228
+78: “table” closed but “caption” was still open.
229
+78: Unclosed elements on stack.
230
+#document
231
+| <!DOCTYPE html>
232
+| <html>
233
+|   <head>
234
+|   <body>
235
+|     <table>
236
+|       <caption>
237
+|         <svg svg>
238
+|           <svg g>
239
+|             "foo"
240
+|           <svg g>
241
+|             "bar"
242
+|           "baz"
243
+|     <p>
244
+|       "quux"
245
+
246
+#data
247
+<!DOCTYPE html><body><table><colgroup><svg><g>foo</g><g>bar</g><p>baz</table><p>quux
248
+#errors
249
+44: Start tag “svg” seen in “table”.
250
+56: Stray end tag “g”.
251
+68: Stray end tag “g”.
252
+71: HTML start tag “p” in a foreign namespace context.
253
+71: Start tag “p” seen in “table”.
254
+#document
255
+| <!DOCTYPE html>
256
+| <html>
257
+|   <head>
258
+|   <body>
259
+|     <svg svg>
260
+|       <svg g>
261
+|         "foo"
262
+|       <svg g>
263
+|         "bar"
264
+|     <p>
265
+|       "baz"
266
+|     <table>
267
+|       <colgroup>
268
+|     <p>
269
+|       "quux"
270
+
271
+#data
272
+<!DOCTYPE html><body><table><tr><td><select><svg><g>foo</g><g>bar</g><p>baz</table><p>quux
273
+#errors
274
+50: Stray “svg” start tag.
275
+54: Stray “g” start tag.
276
+62: Stray end tag “g”
277
+66: Stray “g” start tag.
278
+74: Stray end tag “g”
279
+77: Stray “p” start tag.
280
+88: “table” end tag with “select” open.
281
+#document
282
+| <!DOCTYPE html>
283
+| <html>
284
+|   <head>
285
+|   <body>
286
+|     <table>
287
+|       <tbody>
288
+|         <tr>
289
+|           <td>
290
+|             <select>
291
+|               "foobarbaz"
292
+|     <p>
293
+|       "quux"
294
+
295
+#data
296
+<!DOCTYPE html><body><table><select><svg><g>foo</g><g>bar</g><p>baz</table><p>quux
297
+#errors
298
+36: Start tag “select” seen in “table”.
299
+42: Stray “svg” start tag.
300
+46: Stray “g” start tag.
301
+54: Stray end tag “g”
302
+58: Stray “g” start tag.
303
+66: Stray end tag “g”
304
+69: Stray “p” start tag.
305
+80: “table” end tag with “select” open.
306
+#document
307
+| <!DOCTYPE html>
308
+| <html>
309
+|   <head>
310
+|   <body>
311
+|     <select>
312
+|       "foobarbaz"
313
+|     <table>
314
+|     <p>
315
+|       "quux"
316
+
317
+#data
318
+<!DOCTYPE html><body></body></html><svg><g>foo</g><g>bar</g><p>baz
319
+#errors
320
+41: Stray “svg” start tag.
321
+68: HTML start tag “p” in a foreign namespace context.
322
+#document
323
+| <!DOCTYPE html>
324
+| <html>
325
+|   <head>
326
+|   <body>
327
+|     <svg svg>
328
+|       <svg g>
329
+|         "foo"
330
+|       <svg g>
331
+|         "bar"
332
+|     <p>
333
+|       "baz"
334
+
335
+#data
336
+<!DOCTYPE html><body></body><svg><g>foo</g><g>bar</g><p>baz
337
+#errors
338
+34: Stray “svg” start tag.
339
+61: HTML start tag “p” in a foreign namespace context.
340
+#document
341
+| <!DOCTYPE html>
342
+| <html>
343
+|   <head>
344
+|   <body>
345
+|     <svg svg>
346
+|       <svg g>
347
+|         "foo"
348
+|       <svg g>
349
+|         "bar"
350
+|     <p>
351
+|       "baz"
352
+
353
+#data
354
+<!DOCTYPE html><frameset><svg><g></g><g></g><p><span>
355
+#errors
356
+31: Stray “svg” start tag.
357
+35: Stray “g” start tag.
358
+40: Stray end tag “g”
359
+44: Stray “g” start tag.
360
+49: Stray end tag “g”
361
+52: Stray “p” start tag.
362
+58: Stray “span” start tag.
363
+58: End of file seen and there were open elements.
364
+#document
365
+| <!DOCTYPE html>
366
+| <html>
367
+|   <head>
368
+|   <frameset>
369
+
370
+#data
371
+<!DOCTYPE html><frameset></frameset><svg><g></g><g></g><p><span>
372
+#errors
373
+42: Stray “svg” start tag.
374
+46: Stray “g” start tag.
375
+51: Stray end tag “g”
376
+55: Stray “g” start tag.
377
+60: Stray end tag “g”
378
+63: Stray “p” start tag.
379
+69: Stray “span” start tag.
380
+#document
381
+| <!DOCTYPE html>
382
+| <html>
383
+|   <head>
384
+|   <frameset>
385
+
386
+#data
387
+<!DOCTYPE html><body xlink:href=foo><svg xlink:href=foo></svg>
388
+#errors
389
+#document
390
+| <!DOCTYPE html>
391
+| <html>
392
+|   <head>
393
+|   <body>
394
+|     xlink:href="foo"
395
+|     <svg svg>
396
+|       xlink href="foo"
397
+
398
+#data
399
+<!DOCTYPE html><body xlink:href=foo xml:lang=en><svg><g xml:lang=en xlink:href=foo></g></svg>
400
+#errors
401
+#document
402
+| <!DOCTYPE html>
403
+| <html>
404
+|   <head>
405
+|   <body>
406
+|     xlink:href="foo"
407
+|     xml:lang="en"
408
+|     <svg svg>
409
+|       <svg g>
410
+|         xlink href="foo"
411
+|         xml lang="en"
412
+
413
+#data
414
+<!DOCTYPE html><body xlink:href=foo xml:lang=en><svg><g xml:lang=en xlink:href=foo /></svg>
415
+#errors
416
+#document
417
+| <!DOCTYPE html>
418
+| <html>
419
+|   <head>
420
+|   <body>
421
+|     xlink:href="foo"
422
+|     xml:lang="en"
423
+|     <svg svg>
424
+|       <svg g>
425
+|         xlink href="foo"
426
+|         xml lang="en"
427
+
428
+#data
429
+<!DOCTYPE html><body xlink:href=foo xml:lang=en><svg><g xml:lang=en xlink:href=foo />bar</svg>
430
+#errors
431
+#document
432
+| <!DOCTYPE html>
433
+| <html>
434
+|   <head>
435
+|   <body>
436
+|     xlink:href="foo"
437
+|     xml:lang="en"
438
+|     <svg svg>
439
+|       <svg g>
440
+|         xlink href="foo"
441
+|         xml lang="en"
442
+|       "bar"
443
+
444
+#data
445
+<svg></path>
446
+#errors
447
+#document
448
+| <html>
449
+|   <head>
450
+|   <body>
451
+|     <svg svg>
452
+
453
+#data
454
+<div><svg></div>a
455
+#errors
456
+#document
457
+| <html>
458
+|   <head>
459
+|   <body>
460
+|     <div>
461
+|       <svg svg>
462
+|     "a"
463
+
464
+#data
465
+<div><svg><path></div>a
466
+#errors
467
+#document
468
+| <html>
469
+|   <head>
470
+|   <body>
471
+|     <div>
472
+|       <svg svg>
473
+|         <svg path>
474
+|     "a"
475
+
476
+#data
477
+<div><svg><path></svg><path>
478
+#errors
479
+#document
480
+| <html>
481
+|   <head>
482
+|   <body>
483
+|     <div>
484
+|       <svg svg>
485
+|         <svg path>
486
+|       <path>
487
+
488
+#data
489
+<div><svg><path><foreignObject><math></div>a
490
+#errors
491
+#document
492
+| <html>
493
+|   <head>
494
+|   <body>
495
+|     <div>
496
+|       <svg svg>
497
+|         <svg path>
498
+|           <svg foreignObject>
499
+|             <math math>
500
+|               "a"
501
+
502
+#data
503
+<div><svg><path><foreignObject><p></div>a
504
+#errors
505
+#document
506
+| <html>
507
+|   <head>
508
+|   <body>
509
+|     <div>
510
+|       <svg svg>
511
+|         <svg path>
512
+|           <svg foreignObject>
513
+|             <p>
514
+|               "a"
515
+
516
+#data
517
+<!DOCTYPE html><svg><desc><div><svg><ul>a
518
+#errors
519
+40: HTML start tag “ul” in a foreign namespace context.
520
+41: End of file in a foreign namespace context.
521
+#document
522
+| <!DOCTYPE html>
523
+| <html>
524
+|   <head>
525
+|   <body>
526
+|     <svg svg>
527
+|       <svg desc>
528
+|         <div>
529
+|           <svg svg>
530
+|           <ul>
531
+|             "a"
532
+
533
+#data
534
+<!DOCTYPE html><svg><desc><svg><ul>a
535
+#errors
536
+35: HTML start tag “ul” in a foreign namespace context.
537
+36: End of file in a foreign namespace context.
538
+#document
539
+| <!DOCTYPE html>
540
+| <html>
541
+|   <head>
542
+|   <body>
543
+|     <svg svg>
544
+|       <svg desc>
545
+|         <svg svg>
546
+|         <ul>
547
+|           "a"
548
+
549
+#data
550
+<!DOCTYPE html><p><svg><desc><p>
551
+#errors
552
+#document
553
+| <!DOCTYPE html>
554
+| <html>
555
+|   <head>
556
+|   <body>
557
+|     <p>
558
+|       <svg svg>
559
+|         <svg desc>
560
+|           <p>
561
+
562
+#data
563
+<!DOCTYPE html><p><svg><title><p>
564
+#errors
565
+#document
566
+| <!DOCTYPE html>
567
+| <html>
568
+|   <head>
569
+|   <body>
570
+|     <p>
571
+|       <svg svg>
572
+|         <svg title>
573
+|           <p>
574
+
575
+#data
576
+<div><svg><path><foreignObject><p></foreignObject><p>
577
+#errors
578
+#document
579
+| <html>
580
+|   <head>
581
+|   <body>
582
+|     <div>
583
+|       <svg svg>
584
+|         <svg path>
585
+|           <svg foreignObject>
586
+|             <p>
587
+|             <p>
588
+
589
+#data
590
+<math><mi><div><object><div><span></span></div></object></div></mi><mi>
591
+#errors
592
+#document
593
+| <html>
594
+|   <head>
595
+|   <body>
596
+|     <math math>
597
+|       <math mi>
598
+|         <div>
599
+|           <object>
600
+|             <div>
601
+|               <span>
602
+|       <math mi>
603
+
604
+#data
605
+<math><mi><svg><foreignObject><div><div></div></div></foreignObject></svg></mi><mi>
606
+#errors
607
+#document
608
+| <html>
609
+|   <head>
610
+|   <body>
611
+|     <math math>
612
+|       <math mi>
613
+|         <svg svg>
614
+|           <svg foreignObject>
615
+|             <div>
616
+|               <div>
617
+|       <math mi>
618
+
619
+#data
620
+<svg><script></script><path>
621
+#errors
622
+#document
623
+| <html>
624
+|   <head>
625
+|   <body>
626
+|     <svg svg>
627
+|       <svg script>
628
+|       <svg path>
629
+
630
+#data
631
+<table><svg></svg><tr>
632
+#errors
633
+#document
634
+| <html>
635
+|   <head>
636
+|   <body>
637
+|     <svg svg>
638
+|     <table>
639
+|       <tbody>
640
+|         <tr>
641
+
642
+#data
643
+<math><mi><mglyph>
644
+#errors
645
+#document
646
+| <html>
647
+|   <head>
648
+|   <body>
649
+|     <math math>
650
+|       <math mi>
651
+|         <math mglyph>
652
+
653
+#data
654
+<math><mi><malignmark>
655
+#errors
656
+#document
657
+| <html>
658
+|   <head>
659
+|   <body>
660
+|     <math math>
661
+|       <math mi>
662
+|         <math malignmark>
663
+
664
+#data
665
+<math><mo><mglyph>
666
+#errors
667
+#document
668
+| <html>
669
+|   <head>
670
+|   <body>
671
+|     <math math>
672
+|       <math mo>
673
+|         <math mglyph>
674
+
675
+#data
676
+<math><mo><malignmark>
677
+#errors
678
+#document
679
+| <html>
680
+|   <head>
681
+|   <body>
682
+|     <math math>
683
+|       <math mo>
684
+|         <math malignmark>
685
+
686
+#data
687
+<math><mn><mglyph>
688
+#errors
689
+#document
690
+| <html>
691
+|   <head>
692
+|   <body>
693
+|     <math math>
694
+|       <math mn>
695
+|         <math mglyph>
696
+
697
+#data
698
+<math><mn><malignmark>
699
+#errors
700
+#document
701
+| <html>
702
+|   <head>
703
+|   <body>
704
+|     <math math>
705
+|       <math mn>
706
+|         <math malignmark>
707
+
708
+#data
709
+<math><ms><mglyph>
710
+#errors
711
+#document
712
+| <html>
713
+|   <head>
714
+|   <body>
715
+|     <math math>
716
+|       <math ms>
717
+|         <math mglyph>
718
+
719
+#data
720
+<math><ms><malignmark>
721
+#errors
722
+#document
723
+| <html>
724
+|   <head>
725
+|   <body>
726
+|     <math math>
727
+|       <math ms>
728
+|         <math malignmark>
729
+
730
+#data
731
+<math><mtext><mglyph>
732
+#errors
733
+#document
734
+| <html>
735
+|   <head>
736
+|   <body>
737
+|     <math math>
738
+|       <math mtext>
739
+|         <math mglyph>
740
+
741
+#data
742
+<math><mtext><malignmark>
743
+#errors
744
+#document
745
+| <html>
746
+|   <head>
747
+|   <body>
748
+|     <math math>
749
+|       <math mtext>
750
+|         <math malignmark>
751
+
752
+#data
753
+<math><annotation-xml><svg></svg></annotation-xml><mi>
754
+#errors
755
+#document
756
+| <html>
757
+|   <head>
758
+|   <body>
759
+|     <math math>
760
+|       <math annotation-xml>
761
+|         <svg svg>
762
+|       <math mi>
763
+
764
+#data
765
+<math><annotation-xml><svg><foreignObject><div><math><mi></mi></math><span></span></div></foreignObject><path></path></svg></annotation-xml><mi>
766
+#errors
767
+#document
768
+| <html>
769
+|   <head>
770
+|   <body>
771
+|     <math math>
772
+|       <math annotation-xml>
773
+|         <svg svg>
774
+|           <svg foreignObject>
775
+|             <div>
776
+|               <math math>
777
+|                 <math mi>
778
+|               <span>
779
+|           <svg path>
780
+|       <math mi>
781
+
782
+#data
783
+<math><annotation-xml><svg><foreignObject><math><mi><svg></svg></mi><mo></mo></math><span></span></foreignObject><path></path></svg></annotation-xml><mi>
784
+#errors
785
+#document
786
+| <html>
787
+|   <head>
788
+|   <body>
789
+|     <math math>
790
+|       <math annotation-xml>
791
+|         <svg svg>
792
+|           <svg foreignObject>
793
+|             <math math>
794
+|               <math mi>
795
+|                 <svg svg>
796
+|               <math mo>
797
+|             <span>
798
+|           <svg path>
799
+|       <math mi>

+ 482
- 0
vendor/golang.org/x/net/html/testdata/webkit/tests11.dat View File

@@ -0,0 +1,482 @@
1
+#data
2
+<!DOCTYPE html><body><svg attributeName='' attributeType='' baseFrequency='' baseProfile='' calcMode='' clipPathUnits='' contentScriptType='' contentStyleType='' diffuseConstant='' edgeMode='' externalResourcesRequired='' filterRes='' filterUnits='' glyphRef='' gradientTransform='' gradientUnits='' kernelMatrix='' kernelUnitLength='' keyPoints='' keySplines='' keyTimes='' lengthAdjust='' limitingConeAngle='' markerHeight='' markerUnits='' markerWidth='' maskContentUnits='' maskUnits='' numOctaves='' pathLength='' patternContentUnits='' patternTransform='' patternUnits='' pointsAtX='' pointsAtY='' pointsAtZ='' preserveAlpha='' preserveAspectRatio='' primitiveUnits='' refX='' refY='' repeatCount='' repeatDur='' requiredExtensions='' requiredFeatures='' specularConstant='' specularExponent='' spreadMethod='' startOffset='' stdDeviation='' stitchTiles='' surfaceScale='' systemLanguage='' tableValues='' targetX='' targetY='' textLength='' viewBox='' viewTarget='' xChannelSelector='' yChannelSelector='' zoomAndPan=''></svg>
3
+#errors
4
+#document
5
+| <!DOCTYPE html>
6
+| <html>
7
+|   <head>
8
+|   <body>
9
+|     <svg svg>
10
+|       attributeName=""
11
+|       attributeType=""
12
+|       baseFrequency=""
13
+|       baseProfile=""
14
+|       calcMode=""
15
+|       clipPathUnits=""
16
+|       contentScriptType=""
17
+|       contentStyleType=""
18
+|       diffuseConstant=""
19
+|       edgeMode=""
20
+|       externalResourcesRequired=""
21
+|       filterRes=""
22
+|       filterUnits=""
23
+|       glyphRef=""
24
+|       gradientTransform=""
25
+|       gradientUnits=""
26
+|       kernelMatrix=""
27
+|       kernelUnitLength=""
28
+|       keyPoints=""
29
+|       keySplines=""
30
+|       keyTimes=""
31
+|       lengthAdjust=""
32
+|       limitingConeAngle=""
33
+|       markerHeight=""
34
+|       markerUnits=""
35
+|       markerWidth=""
36
+|       maskContentUnits=""
37
+|       maskUnits=""
38
+|       numOctaves=""
39
+|       pathLength=""
40
+|       patternContentUnits=""
41
+|       patternTransform=""
42
+|       patternUnits=""
43
+|       pointsAtX=""
44
+|       pointsAtY=""
45
+|       pointsAtZ=""
46
+|       preserveAlpha=""
47
+|       preserveAspectRatio=""
48
+|       primitiveUnits=""
49
+|       refX=""
50
+|       refY=""
51
+|       repeatCount=""
52
+|       repeatDur=""
53
+|       requiredExtensions=""
54
+|       requiredFeatures=""
55
+|       specularConstant=""
56
+|       specularExponent=""
57
+|       spreadMethod=""
58
+|       startOffset=""
59
+|       stdDeviation=""
60
+|       stitchTiles=""
61
+|       surfaceScale=""
62
+|       systemLanguage=""
63
+|       tableValues=""
64
+|       targetX=""
65
+|       targetY=""
66
+|       textLength=""
67
+|       viewBox=""
68
+|       viewTarget=""
69
+|       xChannelSelector=""
70
+|       yChannelSelector=""
71
+|       zoomAndPan=""
72
+
73
+#data
74
+<!DOCTYPE html><BODY><SVG ATTRIBUTENAME='' ATTRIBUTETYPE='' BASEFREQUENCY='' BASEPROFILE='' CALCMODE='' CLIPPATHUNITS='' CONTENTSCRIPTTYPE='' CONTENTSTYLETYPE='' DIFFUSECONSTANT='' EDGEMODE='' EXTERNALRESOURCESREQUIRED='' FILTERRES='' FILTERUNITS='' GLYPHREF='' GRADIENTTRANSFORM='' GRADIENTUNITS='' KERNELMATRIX='' KERNELUNITLENGTH='' KEYPOINTS='' KEYSPLINES='' KEYTIMES='' LENGTHADJUST='' LIMITINGCONEANGLE='' MARKERHEIGHT='' MARKERUNITS='' MARKERWIDTH='' MASKCONTENTUNITS='' MASKUNITS='' NUMOCTAVES='' PATHLENGTH='' PATTERNCONTENTUNITS='' PATTERNTRANSFORM='' PATTERNUNITS='' POINTSATX='' POINTSATY='' POINTSATZ='' PRESERVEALPHA='' PRESERVEASPECTRATIO='' PRIMITIVEUNITS='' REFX='' REFY='' REPEATCOUNT='' REPEATDUR='' REQUIREDEXTENSIONS='' REQUIREDFEATURES='' SPECULARCONSTANT='' SPECULAREXPONENT='' SPREADMETHOD='' STARTOFFSET='' STDDEVIATION='' STITCHTILES='' SURFACESCALE='' SYSTEMLANGUAGE='' TABLEVALUES='' TARGETX='' TARGETY='' TEXTLENGTH='' VIEWBOX='' VIEWTARGET='' XCHANNELSELECTOR='' YCHANNELSELECTOR='' ZOOMANDPAN=''></SVG>
75
+#errors
76
+#document
77
+| <!DOCTYPE html>
78
+| <html>
79
+|   <head>
80
+|   <body>
81
+|     <svg svg>
82
+|       attributeName=""
83
+|       attributeType=""
84
+|       baseFrequency=""
85
+|       baseProfile=""
86
+|       calcMode=""
87
+|       clipPathUnits=""
88
+|       contentScriptType=""
89
+|       contentStyleType=""
90
+|       diffuseConstant=""
91
+|       edgeMode=""
92
+|       externalResourcesRequired=""
93
+|       filterRes=""
94
+|       filterUnits=""
95
+|       glyphRef=""
96
+|       gradientTransform=""
97
+|       gradientUnits=""
98
+|       kernelMatrix=""
99
+|       kernelUnitLength=""
100
+|       keyPoints=""
101
+|       keySplines=""
102
+|       keyTimes=""
103
+|       lengthAdjust=""
104
+|       limitingConeAngle=""
105
+|       markerHeight=""
106
+|       markerUnits=""
107
+|       markerWidth=""
108
+|       maskContentUnits=""
109
+|       maskUnits=""
110
+|       numOctaves=""
111
+|       pathLength=""
112
+|       patternContentUnits=""
113
+|       patternTransform=""
114
+|       patternUnits=""
115
+|       pointsAtX=""
116
+|       pointsAtY=""
117
+|       pointsAtZ=""
118
+|       preserveAlpha=""
119
+|       preserveAspectRatio=""
120
+|       primitiveUnits=""
121
+|       refX=""
122
+|       refY=""
123
+|       repeatCount=""
124
+|       repeatDur=""
125
+|       requiredExtensions=""
126
+|       requiredFeatures=""
127
+|       specularConstant=""
128
+|       specularExponent=""
129
+|       spreadMethod=""
130
+|       startOffset=""
131
+|       stdDeviation=""
132
+|       stitchTiles=""
133
+|       surfaceScale=""
134
+|       systemLanguage=""
135
+|       tableValues=""
136
+|       targetX=""
137
+|       targetY=""
138
+|       textLength=""
139
+|       viewBox=""
140
+|       viewTarget=""
141
+|       xChannelSelector=""
142
+|       yChannelSelector=""
143
+|       zoomAndPan=""
144
+
145
+#data
146
+<!DOCTYPE html><body><svg attributename='' attributetype='' basefrequency='' baseprofile='' calcmode='' clippathunits='' contentscripttype='' contentstyletype='' diffuseconstant='' edgemode='' externalresourcesrequired='' filterres='' filterunits='' glyphref='' gradienttransform='' gradientunits='' kernelmatrix='' kernelunitlength='' keypoints='' keysplines='' keytimes='' lengthadjust='' limitingconeangle='' markerheight='' markerunits='' markerwidth='' maskcontentunits='' maskunits='' numoctaves='' pathlength='' patterncontentunits='' patterntransform='' patternunits='' pointsatx='' pointsaty='' pointsatz='' preservealpha='' preserveaspectratio='' primitiveunits='' refx='' refy='' repeatcount='' repeatdur='' requiredextensions='' requiredfeatures='' specularconstant='' specularexponent='' spreadmethod='' startoffset='' stddeviation='' stitchtiles='' surfacescale='' systemlanguage='' tablevalues='' targetx='' targety='' textlength='' viewbox='' viewtarget='' xchannelselector='' ychannelselector='' zoomandpan=''></svg>
147
+#errors
148
+#document
149
+| <!DOCTYPE html>
150
+| <html>
151
+|   <head>
152
+|   <body>
153
+|     <svg svg>
154
+|       attributeName=""
155
+|       attributeType=""
156
+|       baseFrequency=""
157
+|       baseProfile=""
158
+|       calcMode=""
159
+|       clipPathUnits=""
160
+|       contentScriptType=""
161
+|       contentStyleType=""
162
+|       diffuseConstant=""
163
+|       edgeMode=""
164
+|       externalResourcesRequired=""
165
+|       filterRes=""
166
+|       filterUnits=""
167
+|       glyphRef=""
168
+|       gradientTransform=""
169
+|       gradientUnits=""
170
+|       kernelMatrix=""
171
+|       kernelUnitLength=""
172
+|       keyPoints=""
173
+|       keySplines=""
174
+|       keyTimes=""
175
+|       lengthAdjust=""
176
+|       limitingConeAngle=""
177
+|       markerHeight=""
178
+|       markerUnits=""
179
+|       markerWidth=""
180
+|       maskContentUnits=""
181
+|       maskUnits=""
182
+|       numOctaves=""
183
+|       pathLength=""
184
+|       patternContentUnits=""
185
+|       patternTransform=""
186
+|       patternUnits=""
187
+|       pointsAtX=""
188
+|       pointsAtY=""
189
+|       pointsAtZ=""
190
+|       preserveAlpha=""
191
+|       preserveAspectRatio=""
192
+|       primitiveUnits=""
193
+|       refX=""
194
+|       refY=""
195
+|       repeatCount=""
196
+|       repeatDur=""
197
+|       requiredExtensions=""
198
+|       requiredFeatures=""
199
+|       specularConstant=""
200
+|       specularExponent=""
201
+|       spreadMethod=""
202
+|       startOffset=""
203
+|       stdDeviation=""
204
+|       stitchTiles=""
205
+|       surfaceScale=""
206
+|       systemLanguage=""
207
+|       tableValues=""
208
+|       targetX=""
209
+|       targetY=""
210
+|       textLength=""
211
+|       viewBox=""
212
+|       viewTarget=""
213
+|       xChannelSelector=""
214
+|       yChannelSelector=""
215
+|       zoomAndPan=""
216
+
217
+#data
218
+<!DOCTYPE html><body><math attributeName='' attributeType='' baseFrequency='' baseProfile='' calcMode='' clipPathUnits='' contentScriptType='' contentStyleType='' diffuseConstant='' edgeMode='' externalResourcesRequired='' filterRes='' filterUnits='' glyphRef='' gradientTransform='' gradientUnits='' kernelMatrix='' kernelUnitLength='' keyPoints='' keySplines='' keyTimes='' lengthAdjust='' limitingConeAngle='' markerHeight='' markerUnits='' markerWidth='' maskContentUnits='' maskUnits='' numOctaves='' pathLength='' patternContentUnits='' patternTransform='' patternUnits='' pointsAtX='' pointsAtY='' pointsAtZ='' preserveAlpha='' preserveAspectRatio='' primitiveUnits='' refX='' refY='' repeatCount='' repeatDur='' requiredExtensions='' requiredFeatures='' specularConstant='' specularExponent='' spreadMethod='' startOffset='' stdDeviation='' stitchTiles='' surfaceScale='' systemLanguage='' tableValues='' targetX='' targetY='' textLength='' viewBox='' viewTarget='' xChannelSelector='' yChannelSelector='' zoomAndPan=''></math>
219
+#errors
220
+#document
221
+| <!DOCTYPE html>
222
+| <html>
223
+|   <head>
224
+|   <body>
225
+|     <math math>
226
+|       attributename=""
227
+|       attributetype=""
228
+|       basefrequency=""
229
+|       baseprofile=""
230
+|       calcmode=""
231
+|       clippathunits=""
232
+|       contentscripttype=""
233
+|       contentstyletype=""
234
+|       diffuseconstant=""
235
+|       edgemode=""
236
+|       externalresourcesrequired=""
237
+|       filterres=""
238
+|       filterunits=""
239
+|       glyphref=""
240
+|       gradienttransform=""
241
+|       gradientunits=""
242
+|       kernelmatrix=""
243
+|       kernelunitlength=""
244
+|       keypoints=""
245
+|       keysplines=""
246
+|       keytimes=""
247
+|       lengthadjust=""
248
+|       limitingconeangle=""
249
+|       markerheight=""
250
+|       markerunits=""
251
+|       markerwidth=""
252
+|       maskcontentunits=""
253
+|       maskunits=""
254
+|       numoctaves=""
255
+|       pathlength=""
256
+|       patterncontentunits=""
257
+|       patterntransform=""
258
+|       patternunits=""
259
+|       pointsatx=""
260
+|       pointsaty=""
261
+|       pointsatz=""
262
+|       preservealpha=""
263
+|       preserveaspectratio=""
264
+|       primitiveunits=""
265
+|       refx=""
266
+|       refy=""
267
+|       repeatcount=""
268
+|       repeatdur=""
269
+|       requiredextensions=""
270
+|       requiredfeatures=""
271
+|       specularconstant=""
272
+|       specularexponent=""
273
+|       spreadmethod=""
274
+|       startoffset=""
275
+|       stddeviation=""
276
+|       stitchtiles=""
277
+|       surfacescale=""
278
+|       systemlanguage=""
279
+|       tablevalues=""
280
+|       targetx=""
281
+|       targety=""
282
+|       textlength=""
283
+|       viewbox=""
284
+|       viewtarget=""
285
+|       xchannelselector=""
286
+|       ychannelselector=""
287
+|       zoomandpan=""
288
+
289
+#data
290
+<!DOCTYPE html><body><svg><altGlyph /><altGlyphDef /><altGlyphItem /><animateColor /><animateMotion /><animateTransform /><clipPath /><feBlend /><feColorMatrix /><feComponentTransfer /><feComposite /><feConvolveMatrix /><feDiffuseLighting /><feDisplacementMap /><feDistantLight /><feFlood /><feFuncA /><feFuncB /><feFuncG /><feFuncR /><feGaussianBlur /><feImage /><feMerge /><feMergeNode /><feMorphology /><feOffset /><fePointLight /><feSpecularLighting /><feSpotLight /><feTile /><feTurbulence /><foreignObject /><glyphRef /><linearGradient /><radialGradient /><textPath /></svg>
291
+#errors
292
+#document
293
+| <!DOCTYPE html>
294
+| <html>
295
+|   <head>
296
+|   <body>
297
+|     <svg svg>
298
+|       <svg altGlyph>
299
+|       <svg altGlyphDef>
300
+|       <svg altGlyphItem>
301
+|       <svg animateColor>
302
+|       <svg animateMotion>
303
+|       <svg animateTransform>
304
+|       <svg clipPath>
305
+|       <svg feBlend>
306
+|       <svg feColorMatrix>
307
+|       <svg feComponentTransfer>
308
+|       <svg feComposite>
309
+|       <svg feConvolveMatrix>
310
+|       <svg feDiffuseLighting>
311
+|       <svg feDisplacementMap>
312
+|       <svg feDistantLight>
313
+|       <svg feFlood>
314
+|       <svg feFuncA>
315
+|       <svg feFuncB>
316
+|       <svg feFuncG>
317
+|       <svg feFuncR>
318
+|       <svg feGaussianBlur>
319
+|       <svg feImage>
320
+|       <svg feMerge>
321
+|       <svg feMergeNode>
322
+|       <svg feMorphology>
323
+|       <svg feOffset>
324
+|       <svg fePointLight>
325
+|       <svg feSpecularLighting>
326
+|       <svg feSpotLight>
327
+|       <svg feTile>
328
+|       <svg feTurbulence>
329
+|       <svg foreignObject>
330
+|       <svg glyphRef>
331
+|       <svg linearGradient>
332
+|       <svg radialGradient>
333
+|       <svg textPath>
334
+
335
+#data
336
+<!DOCTYPE html><body><svg><altglyph /><altglyphdef /><altglyphitem /><animatecolor /><animatemotion /><animatetransform /><clippath /><feblend /><fecolormatrix /><fecomponenttransfer /><fecomposite /><feconvolvematrix /><fediffuselighting /><fedisplacementmap /><fedistantlight /><feflood /><fefunca /><fefuncb /><fefuncg /><fefuncr /><fegaussianblur /><feimage /><femerge /><femergenode /><femorphology /><feoffset /><fepointlight /><fespecularlighting /><fespotlight /><fetile /><feturbulence /><foreignobject /><glyphref /><lineargradient /><radialgradient /><textpath /></svg>
337
+#errors
338
+#document
339
+| <!DOCTYPE html>
340
+| <html>
341
+|   <head>
342
+|   <body>
343
+|     <svg svg>
344
+|       <svg altGlyph>
345
+|       <svg altGlyphDef>
346
+|       <svg altGlyphItem>
347
+|       <svg animateColor>
348
+|       <svg animateMotion>
349
+|       <svg animateTransform>
350
+|       <svg clipPath>
351
+|       <svg feBlend>
352
+|       <svg feColorMatrix>
353
+|       <svg feComponentTransfer>
354
+|       <svg feComposite>
355
+|       <svg feConvolveMatrix>
356
+|       <svg feDiffuseLighting>
357
+|       <svg feDisplacementMap>
358
+|       <svg feDistantLight>
359
+|       <svg feFlood>
360
+|       <svg feFuncA>
361
+|       <svg feFuncB>
362
+|       <svg feFuncG>
363
+|       <svg feFuncR>
364
+|       <svg feGaussianBlur>
365
+|       <svg feImage>
366
+|       <svg feMerge>
367
+|       <svg feMergeNode>
368
+|       <svg feMorphology>
369
+|       <svg feOffset>
370
+|       <svg fePointLight>
371
+|       <svg feSpecularLighting>
372
+|       <svg feSpotLight>
373
+|       <svg feTile>
374
+|       <svg feTurbulence>
375
+|       <svg foreignObject>
376
+|       <svg glyphRef>
377
+|       <svg linearGradient>
378
+|       <svg radialGradient>
379
+|       <svg textPath>
380
+
381
+#data
382
+<!DOCTYPE html><BODY><SVG><ALTGLYPH /><ALTGLYPHDEF /><ALTGLYPHITEM /><ANIMATECOLOR /><ANIMATEMOTION /><ANIMATETRANSFORM /><CLIPPATH /><FEBLEND /><FECOLORMATRIX /><FECOMPONENTTRANSFER /><FECOMPOSITE /><FECONVOLVEMATRIX /><FEDIFFUSELIGHTING /><FEDISPLACEMENTMAP /><FEDISTANTLIGHT /><FEFLOOD /><FEFUNCA /><FEFUNCB /><FEFUNCG /><FEFUNCR /><FEGAUSSIANBLUR /><FEIMAGE /><FEMERGE /><FEMERGENODE /><FEMORPHOLOGY /><FEOFFSET /><FEPOINTLIGHT /><FESPECULARLIGHTING /><FESPOTLIGHT /><FETILE /><FETURBULENCE /><FOREIGNOBJECT /><GLYPHREF /><LINEARGRADIENT /><RADIALGRADIENT /><TEXTPATH /></SVG>
383
+#errors
384
+#document
385
+| <!DOCTYPE html>
386
+| <html>
387
+|   <head>
388
+|   <body>
389
+|     <svg svg>
390
+|       <svg altGlyph>
391
+|       <svg altGlyphDef>
392
+|       <svg altGlyphItem>
393
+|       <svg animateColor>
394
+|       <svg animateMotion>
395
+|       <svg animateTransform>
396
+|       <svg clipPath>
397
+|       <svg feBlend>
398
+|       <svg feColorMatrix>
399
+|       <svg feComponentTransfer>
400
+|       <svg feComposite>
401
+|       <svg feConvolveMatrix>
402
+|       <svg feDiffuseLighting>
403
+|       <svg feDisplacementMap>
404
+|       <svg feDistantLight>
405
+|       <svg feFlood>
406
+|       <svg feFuncA>
407
+|       <svg feFuncB>
408
+|       <svg feFuncG>
409
+|       <svg feFuncR>
410
+|       <svg feGaussianBlur>
411
+|       <svg feImage>
412
+|       <svg feMerge>
413
+|       <svg feMergeNode>
414
+|       <svg feMorphology>
415
+|       <svg feOffset>
416
+|       <svg fePointLight>
417
+|       <svg feSpecularLighting>
418
+|       <svg feSpotLight>
419
+|       <svg feTile>
420
+|       <svg feTurbulence>
421
+|       <svg foreignObject>
422
+|       <svg glyphRef>
423
+|       <svg linearGradient>
424
+|       <svg radialGradient>
425
+|       <svg textPath>
426
+
427
+#data
428
+<!DOCTYPE html><body><math><altGlyph /><altGlyphDef /><altGlyphItem /><animateColor /><animateMotion /><animateTransform /><clipPath /><feBlend /><feColorMatrix /><feComponentTransfer /><feComposite /><feConvolveMatrix /><feDiffuseLighting /><feDisplacementMap /><feDistantLight /><feFlood /><feFuncA /><feFuncB /><feFuncG /><feFuncR /><feGaussianBlur /><feImage /><feMerge /><feMergeNode /><feMorphology /><feOffset /><fePointLight /><feSpecularLighting /><feSpotLight /><feTile /><feTurbulence /><foreignObject /><glyphRef /><linearGradient /><radialGradient /><textPath /></math>
429
+#errors
430
+#document
431
+| <!DOCTYPE html>
432
+| <html>
433
+|   <head>
434
+|   <body>
435
+|     <math math>
436
+|       <math altglyph>
437
+|       <math altglyphdef>
438
+|       <math altglyphitem>
439
+|       <math animatecolor>
440
+|       <math animatemotion>
441
+|       <math animatetransform>
442
+|       <math clippath>
443
+|       <math feblend>
444
+|       <math fecolormatrix>
445
+|       <math fecomponenttransfer>
446
+|       <math fecomposite>
447
+|       <math feconvolvematrix>
448
+|       <math fediffuselighting>
449
+|       <math fedisplacementmap>
450
+|       <math fedistantlight>
451
+|       <math feflood>
452
+|       <math fefunca>
453
+|       <math fefuncb>
454
+|       <math fefuncg>
455
+|       <math fefuncr>
456
+|       <math fegaussianblur>
457
+|       <math feimage>
458
+|       <math femerge>
459
+|       <math femergenode>
460
+|       <math femorphology>
461
+|       <math feoffset>
462
+|       <math fepointlight>
463
+|       <math fespecularlighting>
464
+|       <math fespotlight>
465
+|       <math fetile>
466
+|       <math feturbulence>
467
+|       <math foreignobject>
468
+|       <math glyphref>
469
+|       <math lineargradient>
470
+|       <math radialgradient>
471
+|       <math textpath>
472
+
473
+#data
474
+<!DOCTYPE html><body><svg><solidColor /></svg>
475
+#errors
476
+#document
477
+| <!DOCTYPE html>
478
+| <html>
479
+|   <head>
480
+|   <body>
481
+|     <svg svg>
482
+|       <svg solidcolor>

+ 0
- 0
vendor/golang.org/x/net/html/testdata/webkit/tests12.dat View File


Some files were not shown because too many files changed in this diff