1
/* Copyright 2002-2005 Elliotte Rusty Harold
3
This library is free software; you can redistribute it and/or modify
4
it under the terms of version 2.1 of the GNU Lesser General Public
5
License as published by the Free Software Foundation.
7
This library is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU Lesser General Public License for more details.
12
You should have received a copy of the GNU Lesser General Public
13
License along with this library; if not, write to the
14
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
15
Boston, MA 02111-1307 USA
17
You can contact Elliotte Rusty Harold by sending e-mail to
18
elharo@metalab.unc.edu. Please include the word "XOM" in the
19
subject line. The XOM home page is located at http://www.xom.nu/
24
import nu.xom.Attribute;
25
import nu.xom.DocType;
26
import nu.xom.Element;
27
import nu.xom.IllegalDataException;
28
import nu.xom.IllegalNameException;
29
import nu.xom.MalformedURIException;
32
import org.apache.xerces.util.XMLChar;
36
* Tests to make sure name and character rules are enforced.
37
* The rules are tested by comparison with the rules in
38
* the org.apache.xerces.util.XMLChar class.
39
* This is an undocumented class so this is potentially dangerous
40
* in the long run. it also means the tests depend on Xerces 2
41
* specifically. However, this dependence does not extend into the
45
* @author Elliotte Rusty Harold
49
public class VerifierTest extends XOMTestCase {
51
private final static char[] subdelims = {'!', '$', '&', '\'', '(', ')' , '*', '+', ',', ';', '='};
52
private final static char[] unreserved = {'-', '.', '_', '~'};
53
private final static char[] unwise = {'{', '}', '|', '\\', '^', '[', ']', '`'};
54
private final static char[] delims = {'<', '>', '#', '%', '^', '"'};
56
public VerifierTest(String name) {
61
public void testElementNames() {
63
for (char c = 0; c < 65535; c++) {
65
// XXX remove dependence on this class by providing
66
// your own table of name characters as a config file for
68
if (XMLChar.isNCNameStart(c)) {
69
String name = String.valueOf(c);
70
Element e = new Element(name);
71
assertEquals(name, e.getLocalName());
75
new Element(String.valueOf(c));
76
fail("Allowed illegal name start character "
77
+ Integer.toHexString(c) + " in element name");
79
catch (IllegalNameException success) {
80
assertNotNull(success.getMessage());
84
if (XMLChar.isNCName(c)) {
85
String name = "a" + c;
86
Element e = new Element(name);
87
assertEquals(name, e.getLocalName());
91
new Element(String.valueOf(c));
92
fail("Allowed illegal character "
93
+ Integer.toHexString(c) + " in element name");
95
catch (IllegalNameException success) {
96
assertNotNull(success.getMessage());
97
assertEquals(String.valueOf(c), success.getData());
107
/* ucschar = %xA0-D7FF / %xF900-FDCF / %xFDF0-FFEF /
108
/ %x10000-1FFFD / %x20000-2FFFD / %x30000-3FFFD
109
/ %x40000-4FFFD / %x50000-5FFFD / %x60000-6FFFD
110
/ %x70000-7FFFD / %x80000-8FFFD / %x90000-9FFFD
111
/ %xA0000-AFFFD / %xB0000-BFFFD / %xC0000-CFFFD
112
/ %xD0000-DFFFD / %xE1000-EFFFD */
114
// From RFC 2396 reallowed into IRIs
115
// "{" | "}" | "|" | "\" | "^" | "[" | "]" | "`"
116
public void testLegalIRIs() {
119
'{', '}', '<', '>', '"', '|', '\\', '^', '`', '\u007F',
120
0xA0, 0xD7FF, 0xF900, 0xFDCF, 0xFDF0,
121
0xFFEF, 0x10000, 0x1FFFD, 0x20000, 0x2FFFD, 0x30000,
122
0x3FFFD, 0x40000, 0x4FFFD, 0x50000, 0x5FFFD, 0x60000,
123
0x6FFFD, 0x70000, 0x7FFFD, 0x80000, 0x8FFFD, 0x90000,
124
0x9FFFD, 0xA0000, 0xAFFFD, 0xB0000, 0xBFFFD, 0xC0000,
125
0xCFFFD, 0xD0000, 0xDFFFD, 0xE1000, 0xEFFFD, 0xCFFFD};
127
Element element = new Element("test");
128
for (int i = 0; i < legalChars.length; i++) {
129
String utf16 = convertToUTF16(legalChars[i]);
130
String url = "http://www.example.com/" + utf16 + ".xml";
131
element.addAttribute(new Attribute("xml:base",
132
"http://www.w3.org/XML/1998/namespace", url));
133
assertEquals(url, element.getAttributeValue("base",
134
"http://www.w3.org/XML/1998/namespace"));
140
public void testAllASCIILettersAllowedToBeginSchemeNames() {
142
Element e = new Element("e");
144
for (char c = 'A'; c <= 'Z'; c++) {
145
String uri = c + "scheme:schemeSpecificData";
146
e.setNamespaceURI(uri);
147
assertEquals(uri, e.getNamespaceURI());
150
for (char c = 'a'; c <= 'z'; c++) {
151
String uri = c + "scheme:schemeSpecificData";
152
e.setNamespaceURI(uri);
153
assertEquals(uri, e.getNamespaceURI());
159
public void testAllASCIILettersAllowedInSchemeNames() {
161
Element e = new Element("e");
163
for (char c = 'A'; c <= 'Z'; c++) {
164
String uri = "scheme" + c + ":schemeSpecificData";
165
e.setNamespaceURI(uri);
166
assertEquals(uri, e.getNamespaceURI());
169
for (char c = 'a'; c <= 'z'; c++) {
170
String uri = "scheme" + c + ":schemeSpecificData";
171
e.setNamespaceURI(uri);
172
assertEquals(uri, e.getNamespaceURI());
178
public void testAllASCIILettersAllowedInQueryStrings() {
180
Element e = new Element("e");
182
for (char c = 'A'; c <= 'Z'; c++) {
183
String uri = "http://www.example.com/?name=" + c;
184
e.setNamespaceURI(uri);
185
assertEquals(uri, e.getNamespaceURI());
188
for (char c = 'a'; c <= 'z'; c++) {
189
String uri = "http://www.example.com/?name=" + c;
190
e.setNamespaceURI(uri);
191
assertEquals(uri, e.getNamespaceURI());
197
public void testAllASCIIDigitsAllowedInQueryStrings() {
199
Element e = new Element("e");
201
for (char c = '0'; c <= '9'; c++) {
202
String uri = "http://www.example.com/?value=" + c;
203
e.setNamespaceURI(uri);
204
assertEquals(uri, e.getNamespaceURI());
210
public void testSlashAllowedInQueryString() {
212
Element e = new Element("e");
214
String uri = "http://www.example.com/?path=/home/elharo/docs/";
215
e.setNamespaceURI(uri);
216
assertEquals(uri, e.getNamespaceURI());
221
public void testQuestionMarkAllowedInQueryString() {
223
Element e = new Element("e");
225
String uri = "http://www.example.com/?path=?home?elharo?docs?";
226
e.setNamespaceURI(uri);
227
assertEquals(uri, e.getNamespaceURI());
232
public void testColonAllowedInQueryString() {
234
Element e = new Element("e");
236
String uri = "http://www.example.com/?path=:home:elharo:docs:";
237
e.setNamespaceURI(uri);
238
assertEquals(uri, e.getNamespaceURI());
243
public void testAtSignAllowedInQueryString() {
245
Element e = new Element("e");
247
String uri = "http://www.example.com/?path=@home@elharo@docs@";
248
e.setNamespaceURI(uri);
249
assertEquals(uri, e.getNamespaceURI());
254
public void testNonASCIICharactersNotAllowedInQueryStrings() {
256
Element e = new Element("e");
258
for (char c = 128; c <= 1024; c++) {
259
String uri = "http://www.example.com/?value=" + c;
261
e.setNamespaceURI(uri);
262
fail("Allowed unescaped non-ASCII character " + c + " in query string");
264
catch (MalformedURIException success) {
265
assertEquals(uri, success.getData());
272
public void testDelimsNotAllowedInQueryStrings() {
274
Element e = new Element("e");
276
for (int i = 0; i < delims.length; i++) {
277
String uri = "http://www.example.com/?value=" + delims[i] + "#Must_Use_Fragment_ID";
279
e.setNamespaceURI(uri);
280
fail("Allowed delimiter character " + delims[i] + " in query string");
282
catch (MalformedURIException success) {
283
assertEquals(uri, success.getData());
290
public void testUnwiseCharactersNotAllowedInQueryStrings() {
292
Element e = new Element("e");
294
for (int i = 0; i < unwise.length; i++) {
295
String uri = "http://www.example.com/?value=" + unwise[i];
297
e.setNamespaceURI(uri);
298
fail("Allowed unwise character " + unwise[i] + " in query string");
300
catch (MalformedURIException success) {
301
assertEquals(uri, success.getData());
308
public void testUnwiseCharactersNotAllowedInUserInfo() {
310
Element e = new Element("e");
312
for (int i = 0; i < unwise.length; i++) {
313
String uri = "http://user" + unwise[i] + "name@www.example.com/?value=" + unwise[i];
315
e.setNamespaceURI(uri);
316
fail("Allowed unwise character " + unwise[i] + " in user info");
318
catch (MalformedURIException success) {
319
assertEquals(uri, success.getData());
326
public void testUnwiseCharactersNotAllowedInHost() {
328
Element e = new Element("e");
330
for (int i = 0; i < unwise.length; i++) {
331
String uri = "http://u" + unwise[i] + "www.example.com/";
333
e.setNamespaceURI(uri);
334
fail("Allowed unwise character " + unwise[i] + " in host");
336
catch (MalformedURIException success) {
337
assertEquals(uri, success.getData());
344
public void testDelimsNotAllowedInHost() {
346
Element e = new Element("e");
348
for (int i = 0; i < delims.length; i++) {
349
String uri = "http://u" + delims[i] + "www.example.com/#value";
351
e.setNamespaceURI(uri);
352
fail("Allowed unwise character " + delims[i] + " in host");
354
catch (MalformedURIException success) {
355
assertEquals(uri, success.getData());
362
public void testUnwiseCharactersNotAllowedInPath() {
364
Element e = new Element("e");
366
for (int i = 0; i < unwise.length; i++) {
367
String uri = "http://www.example.com/path" + unwise[i] + "/path";
369
e.setNamespaceURI(uri);
370
fail("Allowed unwise character " + unwise[i] + " in path");
372
catch (MalformedURIException success) {
373
assertEquals(uri, success.getData());
380
public void testAllASCIILettersAllowedInHostNames() {
382
Element e = new Element("e");
384
for (char c = 'A'; c <= 'Z'; c++) {
385
String uri = "http://" + c + ".com/";
386
e.setNamespaceURI(uri);
387
assertEquals(uri, e.getNamespaceURI());
390
for (char c = 'a'; c <= 'z'; c++) {
391
String uri = "http://" + c + ".com/";
392
e.setNamespaceURI(uri);
393
assertEquals(uri, e.getNamespaceURI());
399
public void testAllASCIIDigitsAllowedInHostNames() {
401
Element e = new Element("e");
403
for (char c = '0'; c <= '9'; c++) {
404
String uri = "http://c" + c + ".com/";
405
e.setNamespaceURI(uri);
406
assertEquals(uri, e.getNamespaceURI());
412
public void testNonASCIICharactersNotAllowedInHostNames() {
414
Element e = new Element("e");
416
for (char c = 128; c <= 1024; c++) {
417
String uri = "http://c" + c + ".com/";
419
e.setNamespaceURI(uri);
420
fail("Allowed unescaped non-ASCII character " + c + " in host name");
422
catch (MalformedURIException success) {
423
assertEquals(uri, success.getData());
430
public void testAllASCIILettersAllowedInUserInfo() {
432
Element e = new Element("e");
434
for (char c = 'A'; c <= 'Z'; c++) {
435
String uri = "http://" + c + "@c.com/";
436
e.setNamespaceURI(uri);
437
assertEquals(uri, e.getNamespaceURI());
440
for (char c = 'a'; c <= 'z'; c++) {
441
String uri = "http://" + c + "@c.com/";
442
e.setNamespaceURI(uri);
443
assertEquals(uri, e.getNamespaceURI());
449
public void testAllSubDelimsAllowedInUserInfo() {
451
Element e = new Element("e");
453
for (int i = 0; i < subdelims.length; i++) {
454
String uri = "http://c" + subdelims[i] + "x@c.com/";
455
e.setNamespaceURI(uri);
456
assertEquals(uri, e.getNamespaceURI());
462
public void testAllSubDelimsAllowedInPath() {
464
Element e = new Element("e");
466
for (int i = 0; i < subdelims.length; i++) {
467
String uri = "http://cc.com/path" + subdelims[i] +".html";
468
e.setNamespaceURI(uri);
469
assertEquals(uri, e.getNamespaceURI());
475
public void testAllUnreservedPunctuationMarksAllowedInUserInfo() {
477
Element e = new Element("e");
479
for (int i = 0; i < unreserved.length; i++) {
480
String uri = "http://c" + unreserved[i] + "x@c.com/";
481
e.setNamespaceURI(uri);
482
assertEquals(uri, e.getNamespaceURI());
488
public void testAllUnreservedPunctuationMarksAllowedInHost() {
490
Element e = new Element("e");
492
for (int i = 0; i < unreserved.length; i++) {
493
String uri = "http://c" + unreserved[i] + "xc.com/";
494
e.setNamespaceURI(uri);
495
assertEquals(uri, e.getNamespaceURI());
501
public void testAllSubDelimsAllowedInQueryString() {
503
Element e = new Element("e");
505
for (int i = 0; i < subdelims.length; i++) {
506
String uri = "http://cx@c.com/?name=" + subdelims[i];
507
e.setNamespaceURI(uri);
508
assertEquals(uri, e.getNamespaceURI());
514
public void testAllSubDelimsAllowedInHost() {
516
Element e = new Element("e");
518
for (int i = 0; i < subdelims.length; i++) {
519
String uri = "http://cx" + subdelims[i] + "c.com/";
520
e.setNamespaceURI(uri);
521
assertEquals(uri, e.getNamespaceURI());
527
public void testAllUnreservedPunctuationMarksAllowedInQueryString() {
529
Element e = new Element("e");
531
for (int i = 0; i < unreserved.length; i++) {
532
String uri = "http://cx@c.com/?name=" + unreserved[i];
533
e.setNamespaceURI(uri);
534
assertEquals(uri, e.getNamespaceURI());
540
public void testAllASCIIDigitsAllowedInUserInfo() {
542
Element e = new Element("e");
544
for (char c = '0'; c <= '9'; c++) {
545
String uri = "http://" + c + "@c.com/";
546
e.setNamespaceURI(uri);
547
assertEquals(uri, e.getNamespaceURI());
553
public void testNonASCIICharactersNotAllowedInUserInfo() {
555
Element e = new Element("e");
557
for (char c = 128; c <= 1024; c++) {
558
String uri = "http://" + c + "@c.com/";
560
e.setNamespaceURI(uri);
561
fail("Allowed unescaped non-ASCII character " + c + " in user info");
563
catch (MalformedURIException success) {
564
assertEquals(uri, success.getData());
571
public void testDelimCharactersNotAllowedInUserInfo() {
573
Element e = new Element("e");
575
for (int i = 0; i < delims.length; i++) {
576
String uri = "http://c" + delims[i] + "c@c.com/?name=value#fragID";
578
e.setNamespaceURI(uri);
579
fail("Allowed delim character " + delims[i] + " in user info");
581
catch (MalformedURIException success) {
582
assertEquals(uri, success.getData());
589
public void testMalformedURI() {
591
Element e = new Element("e");
593
String uri = "http://c#c@c.com/?name=value#fragID";
595
e.setNamespaceURI(uri);
596
fail("Allowed http://c#c@c.com/?name=value#fragID as URI");
598
catch (MalformedURIException success) {
599
assertEquals(uri, success.getData());
605
public void testFragmentIDContainsQuestionMark() {
607
Element e = new Element("e");
609
String uri = "http://cc@c.com/?name=value#fragID?home/?elharo?";
610
e.setNamespaceURI(uri);
611
assertEquals(uri, e.getNamespaceURI());
613
uri = "http://cc@c.com/#fragID?name=value";
614
e.setNamespaceURI(uri);
615
assertEquals(uri, e.getNamespaceURI());
620
public void testFragmentIDContainsFirstColon() {
622
Element e = new Element("e");
624
String uri = "http://c.com/#fragID:home";
625
e.setNamespaceURI(uri);
626
assertEquals(uri, e.getNamespaceURI());
628
uri = "http://c.com/#fragID:home@eharo.com/somewhere";
629
e.setNamespaceURI(uri);
630
assertEquals(uri, e.getNamespaceURI());
635
public void testEmptyHostAllowed() {
637
Element e = new Element("e");
639
String uri = "scheme://elharo@:80/data";
640
e.setNamespaceURI(uri);
641
assertEquals(uri, e.getNamespaceURI());
646
public void testC0ControlsNotAllowedInUserInfo() {
648
Element e = new Element("e");
650
for (char c = 0; c <= ' '; c++) {
651
String uri = "http://" + c + "@c.com/";
653
e.setNamespaceURI(uri);
654
fail("Allowed C0 control 0x" + Integer.toHexString(c) + " in user info");
656
catch (MalformedURIException success) {
657
assertEquals(uri, success.getData());
664
public void testC0ControlsNotAllowedInPath() {
666
Element e = new Element("e");
668
for (char c = 0; c <= ' '; c++) {
669
String uri = "http://www.example.com/test/" + c + "data/";
671
e.setNamespaceURI(uri);
672
fail("Allowed C0 control 0x" + Integer.toHexString(c) + " in path");
674
catch (MalformedURIException success) {
675
assertEquals(uri, success.getData());
682
public void testC0ControlsNotAllowedInQueryString() {
684
Element e = new Element("e");
686
for (char c = 0; c <= ' '; c++) {
687
String uri = "http://www.c.com/?name=" + c + "&value=7";
689
e.setNamespaceURI(uri);
690
fail("Allowed C0 control 0x" + Integer.toHexString(c) + " in query string");
692
catch (MalformedURIException success) {
693
assertEquals(uri, success.getData());
700
public void testHostNameTooLong() {
702
StringBuffer uri = new StringBuffer("http://");
703
for (int i = 0; i < 255; i++) uri.append('c');
705
Element e = new Element("e");
707
e.setNamespaceURI(uri.toString());
708
fail("Allowed excessively long host name");
710
catch (MalformedURIException success) {
711
assertNotNull(success.getMessage());
717
public void testSymbolsNotAllowedInSchemeNames() {
719
Element e = new Element("e");
721
char[] disallowed = { ';', '@', '&', '=', '$', ',', '"', '?', '#', '/', '\\', '|',
722
'_', '!', '~', '*', '\'', '(', ')', '<', '>', '[', ']', '{', '}', '^', '`'};
724
for (int i = 0; i < disallowed.length; i++) {
725
String uri = "scheme" + disallowed[i] + ":schemeSpecificData";
727
e.setNamespaceURI(uri);
728
fail("allowed " + uri + " as namespace URI");
730
catch (MalformedURIException success) {
731
assertEquals(uri, success.getData());
738
public void testNonASCIILettersNotAllowedToBeginSchemeNames() {
740
Element e = new Element("e");
742
for (char c = 'Z' +1; c < 'a'; c++) {
743
String uri = c + "scheme:schemeSpecificData";
745
e.setNamespaceURI(uri);
746
fail("allowed " + uri + " as namespace URI");
748
catch (MalformedURIException success) {
749
assertEquals(uri, success.getData());
756
public void testBadHexEscapeInQueryString() {
758
Element e = new Element("e");
760
String uri = "scheme:schemeSpecificData?test%5test";
762
e.setNamespaceURI(uri);
763
fail("allowed " + uri + " as namespace URI");
765
catch (MalformedURIException success) {
766
assertEquals(uri, success.getData());
769
uri = "scheme:schemeSpecificData?test%5";
771
e.setNamespaceURI(uri);
772
fail("allowed " + uri + " as namespace URI");
774
catch (MalformedURIException success) {
775
assertEquals(uri, success.getData());
781
public void testHexEscapeInUserInfo() {
783
Element e = new Element("e");
785
String uri = "scheme://user%C3%80TED@www.example.com/";
786
e.setNamespaceURI(uri);
787
assertEquals(uri, e.getNamespaceURI());
792
public void testHexEscapeInHost() {
794
Element e = new Element("e");
796
String uri = "scheme://user%C3%80www.example.com/";
797
e.setNamespaceURI(uri);
798
assertEquals(uri, e.getNamespaceURI());
803
public void testBadHexEscapeInUserInfo() {
805
Element e = new Element("e");
807
String uri = "scheme://user%5TED@www.example.com/";
809
e.setNamespaceURI(uri);
810
fail("allowed " + uri + " as namespace URI");
812
catch (MalformedURIException success) {
813
assertEquals(uri, success.getData());
816
uri = "scheme://user%5@www.example.com/";
818
e.setNamespaceURI(uri);
819
fail("allowed " + uri + " as namespace URI");
821
catch (MalformedURIException success) {
822
assertEquals(uri, success.getData());
828
public void testBadHexEscapeInHost() {
830
Element e = new Element("e");
832
String uri = "scheme://user%5TEDwww.example.com/";
834
e.setNamespaceURI(uri);
835
fail("allowed " + uri + " as namespace URI");
837
catch (MalformedURIException success) {
838
assertEquals(uri, success.getData());
841
uri = "scheme://www.example.co%5/";
843
e.setNamespaceURI(uri);
844
fail("allowed " + uri + " as namespace URI");
846
catch (MalformedURIException success) {
847
assertEquals(uri, success.getData());
853
public void testQuestionmarkIsNotAHexDigit() {
855
Element e = new Element("e");
857
// Have to do this in a fragment ID to keep it from being
858
// interpreted as a query string separator
859
String uri = "scheme://user@www.example.com/#fragment%?Adata";
861
e.setNamespaceURI(uri);
862
fail("allowed " + uri + " as namespace URI");
864
catch (MalformedURIException success) {
865
assertEquals(uri, success.getData());
871
public void testIllegalIRIs() {
873
int[] illegalChars = {0x00, 0xDC00, 0xE7FF, 0xF899, 0xD800,
874
0xFDE0, 0xFFFF, 0x1FFFE, 0x2FFFE, 0x3FFFF, 0x4FFFE,
875
0x4FFFF, 0x5FFFE, 0x6FFFF, 0x7FFFE, 0x8FFFF, 0x9FFFE,
876
0xAFFFE, 0xBFFFF, 0xCFFFE, 0xDFFFE, 0xEFFFF, 0xFDDF};
878
for (int i = 0; i < illegalChars.length; i++) {
879
String utf16 = convertToUTF16(illegalChars[i]);
880
String url = "http://www.example.com/" + utf16 + ".xml";
882
new DocType("root", url);
883
fail("Allowed URL containing 0x" +
884
Integer.toHexString(illegalChars[i]).toUpperCase());
886
catch (MalformedURIException success) {
887
assertNotNull(success.getMessage());
888
assertEquals(url, success.getData());
895
public void testLegalIP6Addresses() {
897
String[] addresses = {
898
"FEDC:BA98:7654:3210:FEDC:BA98:7654:3210",
899
"1080:0:0:0:8:800:200C:4171",
900
"3ffe:2a00:100:7031::1",
901
"1080::8:800:200C:417A",
903
"::FFFF:129.144.52.38",
904
"2010:836B:4179::836B:4179",
905
"1080:0:0:0:8:800:200C:417A",
906
"FF01:0:0:0:0:0:0:101",
909
"1080::8:800:200C:417A",
913
"0:0:0:0:0:0:13.1.68.3",
914
"0:0:0:0:0:FFFF:129.144.52.38",
916
"::FFFF:129.144.52.38"
919
Element element = new Element("test");
920
for (int i = 0; i < addresses.length; i++) {
921
String url = "http://[" + addresses[i] + "]/";
922
element.addAttribute(new Attribute("xml:base",
923
"http://www.w3.org/XML/1998/namespace", url));
924
assertEquals(url, element.getBaseURI());
930
public void testIllegalIP6Addresses() {
932
String[] addresses = {
933
"FEDC:BA98:7654:3210:GEDC:BA98:7654:3 210",
934
"FEDC:BA98:7654:3210:FEDC:BA98:7654:3210:4352",
935
"FEDC:BA98:7654:3210:GEDC:BA98:7654:3210",
936
"FEDC:BA98:7654:3210:GEDC:BA98:7654:G210",
937
"FEDC:BA98:7654:3210:GEDC:BA98:7654: 3210",
938
"FEDC:BA98:7654:3210:GEDC:BA98:7654:+3210",
939
"FEDC:BA98:7654:3210:GEDC:BA98:7654:3210 ",
940
"FEDC:BA98:7654:3210:GEDC:BA98:7654:32 10",
941
"1080:0:::8:800:200C:4171",
944
"::FFFF:129.144.52.38.56",
945
"::FFFF:129.144.52.A3",
946
"::FFFF:129.144.52.-22",
947
"::FFFF:129.144.52.+22",
948
"::FFFF:256.144.52.+22",
949
"::FFFF:www.apple.com",
950
"1080:0:0:0:8:800:-200C:417A",
951
"1080:0:0:0:-8:800:-200C:417A"
954
for (int i = 0; i < addresses.length; i++) {
955
String url = "http://[" + addresses[i] + "]/";
957
new DocType("root", url);
958
fail("Allowed illegal IPv6 address: " + addresses[i] );
960
catch (MalformedURIException success) {
961
assertNotNull(success.getMessage());
962
assertTrue(success.getData().indexOf(addresses[i]) >= 0);
970
// http://www.unicode.org/faq/utf_bom.html#35
971
private static int LEAD_OFFSET = 0xD800 - (0x10000 >> 10);
973
private static String convertToUTF16(int c) {
975
if (c <= 0xFFFF) return String.valueOf((char) c);
976
char high = (char) (LEAD_OFFSET + (c >> 10));
977
char low = (char) (0xDC00 + (c & 0x3FF));
978
StringBuffer sb = new StringBuffer(2);
981
return sb.toString().toLowerCase();
986
public void testC0Controls() {
988
for (char c = 0; c < '\t'; c++) {
990
new Text(String.valueOf(c));
992
catch (IllegalDataException success) {
993
assertNotNull(success.getMessage());
997
for (char c = '\r'+1; c < ' '; c++) {
999
new Text(String.valueOf(c));
1001
catch (IllegalDataException success) {
1002
assertNotNull(success.getMessage());
1003
assertEquals(String.valueOf(c), success.getData());
1010
public void testAttributeNameThatEndsWithAColon() {
1013
new Attribute("name:", "http://www.example.com", "value", Attribute.Type.CDATA);
1014
fail("Allowed attribute name that ends with a colon");
1016
catch (IllegalNameException success) {
1017
assertNotNull(success.getMessage());
1018
assertEquals("name:", success.getData());
1024
public void testAttributeNameThatBeginsWithAColon() {
1027
new Attribute(":name", "http://www.example.com", "value", Attribute.Type.CDATA);
1028
fail("Allowed attribute name that begins with a colon");
1030
catch (IllegalNameException success) {
1031
assertNotNull(success.getMessage());
1032
assertEquals(":name", success.getData());
1038
public void testElementNameThatEndsWithAColon() {
1041
new Element("name:", "http://www.example.com");
1042
fail("Allowed element name that ends with a colon");
1044
catch (IllegalNameException success) {
1045
assertNotNull(success.getMessage());
1046
assertEquals("name:", success.getData());
1052
public void testElementNameThatBeginsWithAColon() {
1055
new Element(":name", "http://www.example.com");
1056
fail("Allowed element name that begins with a colon");
1058
catch (IllegalNameException success) {
1059
assertNotNull(success.getMessage());
1060
assertEquals(":name", success.getData());