@@ -185,6 +185,52 @@ func TestRawToken(t *testing.T) {
185
185
}
186
186
}
187
187
188
+ // Ensure that directives (specifically !DOCTYPE) include the complete
189
+ // text of any nested directives, noting that < and > do not change
190
+ // nesting depth if they are in single or double quotes.
191
+
192
+ var nestedDirectivesInput = `
193
+ <!DOCTYPE [<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#">]>
194
+ <!DOCTYPE [<!ENTITY xlt ">">]>
195
+ <!DOCTYPE [<!ENTITY xlt "<">]>
196
+ <!DOCTYPE [<!ENTITY xlt '>'>]>
197
+ <!DOCTYPE [<!ENTITY xlt '<'>]>
198
+ <!DOCTYPE [<!ENTITY xlt '">'>]>
199
+ <!DOCTYPE [<!ENTITY xlt "'<">]>
200
+ `
201
+
202
+ var nestedDirectivesTokens = []Token {
203
+ CharData ([]byte ("\n " )),
204
+ Directive ([]byte (`DOCTYPE [<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#">]` )),
205
+ CharData ([]byte ("\n " )),
206
+ Directive ([]byte (`DOCTYPE [<!ENTITY xlt ">">]` )),
207
+ CharData ([]byte ("\n " )),
208
+ Directive ([]byte (`DOCTYPE [<!ENTITY xlt "<">]` )),
209
+ CharData ([]byte ("\n " )),
210
+ Directive ([]byte (`DOCTYPE [<!ENTITY xlt '>'>]` )),
211
+ CharData ([]byte ("\n " )),
212
+ Directive ([]byte (`DOCTYPE [<!ENTITY xlt '<'>]` )),
213
+ CharData ([]byte ("\n " )),
214
+ Directive ([]byte (`DOCTYPE [<!ENTITY xlt '">'>]` )),
215
+ CharData ([]byte ("\n " )),
216
+ Directive ([]byte (`DOCTYPE [<!ENTITY xlt "'<">]` )),
217
+ CharData ([]byte ("\n " )),
218
+ }
219
+
220
+ func TestNestedDirectives (t * testing.T ) {
221
+ p := NewParser (StringReader (nestedDirectivesInput ))
222
+
223
+ for i , want := range nestedDirectivesTokens {
224
+ have , err := p .Token ()
225
+ if err != nil {
226
+ t .Fatalf ("token %d: unexpected error: %s" , i , err )
227
+ }
228
+ if ! reflect .DeepEqual (have , want ) {
229
+ t .Errorf ("token %d = %#v want %#v" , i , have , want )
230
+ }
231
+ }
232
+ }
233
+
188
234
func TestToken (t * testing.T ) {
189
235
p := NewParser (StringReader (testInput ))
190
236
0 commit comments