|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| package nu.xom.tests; |
|
23 |
| |
|
24 |
| import java.io.File; |
|
25 |
| import java.io.IOException; |
|
26 |
| import java.io.UnsupportedEncodingException; |
|
27 |
| import java.net.URL; |
|
28 |
| import java.util.Locale; |
|
29 |
| |
|
30 |
| import nu.xom.Attribute; |
|
31 |
| import nu.xom.Builder; |
|
32 |
| import nu.xom.Comment; |
|
33 |
| import nu.xom.Document; |
|
34 |
| import nu.xom.Element; |
|
35 |
| import nu.xom.MalformedURIException; |
|
36 |
| import nu.xom.Namespace; |
|
37 |
| import nu.xom.Node; |
|
38 |
| import nu.xom.ParsingException; |
|
39 |
| import nu.xom.Text; |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| public class BaseURITest extends XOMTestCase { |
|
58 |
| |
|
59 |
| |
|
60 |
76
| public BaseURITest(String name) {
|
|
61 |
76
| super(name);
|
|
62 |
| } |
|
63 |
| |
|
64 |
| |
|
65 |
| private Document doc; |
|
66 |
| private String base1 = "http://www.base1.com/"; |
|
67 |
| private String base2 = "http://www.base2.com/"; |
|
68 |
| private String base3 = "base3.html"; |
|
69 |
| private Builder builder = new Builder(); |
|
70 |
| |
|
71 |
| |
|
72 |
76
| protected void setUp() {
|
|
73 |
| |
|
74 |
76
| Element root = new Element("root");
|
|
75 |
76
| doc = new Document(root);
|
|
76 |
76
| doc.setBaseURI(base1);
|
|
77 |
76
| Element child = new Element("child");
|
|
78 |
76
| root.appendChild(child);
|
|
79 |
76
| child.setBaseURI(base2);
|
|
80 |
76
| child.appendChild(new Comment("here I am"));
|
|
81 |
| |
|
82 |
76
| Element child2 = new Element("child2");
|
|
83 |
76
| root.appendChild(child2);
|
|
84 |
| |
|
85 |
76
| Element child3 = new Element("child3");
|
|
86 |
76
| root.appendChild(child3);
|
|
87 |
76
| child3.addAttribute(new Attribute("xml:base",
|
|
88 |
| Namespace.XML_NAMESPACE, base2)); |
|
89 |
| |
|
90 |
76
| Element child4 = new Element("child4");
|
|
91 |
76
| root.appendChild(child4);
|
|
92 |
76
| child4.addAttribute(new Attribute("xml:base",
|
|
93 |
| Namespace.XML_NAMESPACE, base3)); |
|
94 |
| |
|
95 |
| } |
|
96 |
| |
|
97 |
| |
|
98 |
1
| public void testDocBase() {
|
|
99 |
1
| assertEquals(base1, doc.getBaseURI());
|
|
100 |
| } |
|
101 |
| |
|
102 |
| |
|
103 |
1
| public void testUnsetBase() {
|
|
104 |
1
| Element root = new Element("test");
|
|
105 |
1
| root.setBaseURI(base1);
|
|
106 |
1
| root.setBaseURI(null);
|
|
107 |
1
| assertEquals("", root.getBaseURI());
|
|
108 |
| } |
|
109 |
| |
|
110 |
| |
|
111 |
1
| public void testInheritBaseFromDocument() {
|
|
112 |
1
| Element root = doc.getRootElement();
|
|
113 |
1
| root.setBaseURI("");
|
|
114 |
1
| assertEquals(doc.getBaseURI(), root.getBaseURI());
|
|
115 |
| } |
|
116 |
| |
|
117 |
| |
|
118 |
1
| public void testAllowEmptyBase() {
|
|
119 |
1
| Element root = new Element("test");
|
|
120 |
1
| root.setBaseURI(base1);
|
|
121 |
1
| root.setBaseURI("");
|
|
122 |
1
| assertEquals("", root.getBaseURI());
|
|
123 |
| } |
|
124 |
| |
|
125 |
| |
|
126 |
1
| public void testIPv6Base() {
|
|
127 |
1
| String ipv6
|
|
128 |
| = "http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/test.xml"; |
|
129 |
1
| Element root = new Element("test");
|
|
130 |
1
| root.setBaseURI(ipv6);
|
|
131 |
1
| assertEquals(ipv6, root.getBaseURI());
|
|
132 |
| } |
|
133 |
| |
|
134 |
| |
|
135 |
1
| public void testBaseWithNonASCIICharacter() {
|
|
136 |
| |
|
137 |
1
| String uri = "http://www.w3.org/\u00A9testing";
|
|
138 |
1
| Element root = new Element("test");
|
|
139 |
1
| try {
|
|
140 |
1
| root.setBaseURI(uri);
|
|
141 |
0
| fail("Allowed base URI containing non-ASCII character");
|
|
142 |
| } |
|
143 |
| catch (MalformedURIException success) { |
|
144 |
1
| assertNotNull(success.getMessage());
|
|
145 |
| } |
|
146 |
| |
|
147 |
1
| root.setBaseURI("http://www.example.org/D%C3%BCrst");
|
|
148 |
1
| assertEquals("http://www.example.org/D%C3%BCrst", root.getBaseURI());
|
|
149 |
| |
|
150 |
| } |
|
151 |
| |
|
152 |
| |
|
153 |
1
| public void testDocumentBaseWithNonASCIICharacter() {
|
|
154 |
| |
|
155 |
1
| String uri = "http://www.w3.org/\u00A9testing";
|
|
156 |
1
| Element root = new Element("test");
|
|
157 |
1
| Document doc = new Document(root);
|
|
158 |
1
| try {
|
|
159 |
1
| doc.setBaseURI(uri);
|
|
160 |
0
| fail("Allowed base URI containing non-ASCII character");
|
|
161 |
| } |
|
162 |
| catch (MalformedURIException success) { |
|
163 |
1
| assertNotNull(success.getMessage());
|
|
164 |
| } |
|
165 |
| |
|
166 |
1
| doc.setBaseURI("http://www.example.org/D%C3%BCrst");
|
|
167 |
1
| assertEquals("http://www.example.org/D%C3%BCrst", doc.getBaseURI());
|
|
168 |
| |
|
169 |
| } |
|
170 |
| |
|
171 |
| |
|
172 |
1
| public void testUppercaseBase() {
|
|
173 |
1
| String base = "HTTP://WWW.EXAMPLE.COM/TEST.XML";
|
|
174 |
1
| Element root = new Element("test");
|
|
175 |
1
| root.setBaseURI(base);
|
|
176 |
1
| assertEquals(base, root.getBaseURI());
|
|
177 |
| } |
|
178 |
| |
|
179 |
| |
|
180 |
1
| public void testASCIILettersWithXMLBaseAttribute() {
|
|
181 |
| |
|
182 |
1
| String alphabet = "abcdefghijklmnopqrstuvwxyz";
|
|
183 |
| |
|
184 |
1
| String base = "HTTP://WWW.EXAMPLE.COM/" + alphabet;
|
|
185 |
1
| Element root = new Element("test");
|
|
186 |
1
| root.addAttribute(new Attribute("xml:base",
|
|
187 |
| Namespace.XML_NAMESPACE, base)); |
|
188 |
1
| assertEquals(base, root.getBaseURI());
|
|
189 |
| |
|
190 |
1
| base = "HTTP://WWW.EXAMPLE.COM/" + alphabet.toUpperCase(Locale.ENGLISH);
|
|
191 |
1
| root.addAttribute(new Attribute("xml:base",
|
|
192 |
| Namespace.XML_NAMESPACE, base)); |
|
193 |
1
| assertEquals(base, root.getBaseURI());
|
|
194 |
| |
|
195 |
| } |
|
196 |
| |
|
197 |
| |
|
198 |
1
| public void testXMLBaseWithParameters() {
|
|
199 |
1
| String base = "scheme://authority/data/name;v=1.1/test.db";
|
|
200 |
1
| Element root = new Element("test");
|
|
201 |
1
| root.addAttribute(new Attribute("xml:base",
|
|
202 |
| Namespace.XML_NAMESPACE, base)); |
|
203 |
1
| assertEquals(base, root.getBaseURI());
|
|
204 |
| } |
|
205 |
| |
|
206 |
| |
|
207 |
1
| public void testXMLBaseWithCommaParameter() {
|
|
208 |
| |
|
209 |
1
| String base = "scheme://authority/data/name,1.1/test.db";
|
|
210 |
1
| Element root = new Element("test");
|
|
211 |
1
| root.addAttribute(new Attribute("xml:base",
|
|
212 |
| Namespace.XML_NAMESPACE, base)); |
|
213 |
1
| assertEquals(base, root.getBaseURI());
|
|
214 |
| |
|
215 |
| } |
|
216 |
| |
|
217 |
| |
|
218 |
| |
|
219 |
1
| public void testXMLBaseWithDollarSign() {
|
|
220 |
| |
|
221 |
1
| String base = "scheme://authority/data$important";
|
|
222 |
1
| Element root = new Element("test");
|
|
223 |
1
| root.addAttribute(new Attribute("xml:base",
|
|
224 |
| Namespace.XML_NAMESPACE, base)); |
|
225 |
1
| assertEquals(base, root.getBaseURI());
|
|
226 |
| |
|
227 |
| } |
|
228 |
| |
|
229 |
| |
|
230 |
1
| public void testFragmentIDWithXMLBaseAttribute() {
|
|
231 |
| |
|
232 |
1
| String base = "HTTP://WWW.EXAMPLE.COM/#test";
|
|
233 |
1
| Element root = new Element("test");
|
|
234 |
1
| root.addAttribute(new Attribute("xml:base",
|
|
235 |
| Namespace.XML_NAMESPACE, base)); |
|
236 |
1
| assertEquals(base, root.getBaseURI());
|
|
237 |
| |
|
238 |
| } |
|
239 |
| |
|
240 |
| |
|
241 |
1
| public void testQueryString() {
|
|
242 |
| |
|
243 |
1
| String base = "http://www.example.com/test?name=value&data=important";
|
|
244 |
1
| Element root = new Element("test");
|
|
245 |
1
| root.addAttribute(new Attribute("xml:base",
|
|
246 |
| Namespace.XML_NAMESPACE, base)); |
|
247 |
1
| assertEquals(base, root.getBaseURI());
|
|
248 |
| |
|
249 |
| } |
|
250 |
| |
|
251 |
| |
|
252 |
1
| public void testUnreserved() {
|
|
253 |
| |
|
254 |
1
| String unreserved = "-.!~*'()";
|
|
255 |
1
| String base = "http://www.example.com/" + unreserved;
|
|
256 |
1
| Element root = new Element("test");
|
|
257 |
1
| root.addAttribute(new Attribute("xml:base",
|
|
258 |
| Namespace.XML_NAMESPACE, base)); |
|
259 |
1
| assertEquals(base, root.getBaseURI());
|
|
260 |
| |
|
261 |
| } |
|
262 |
| |
|
263 |
| |
|
264 |
1
| public void testDelims() {
|
|
265 |
| |
|
266 |
1
| String[] delims = {"<", ">", "\""};
|
|
267 |
1
| for (int i = 0; i < delims.length; i++) {
|
|
268 |
3
| String base = "http://www.example.com/" + delims[i] + "/";
|
|
269 |
3
| Element root = new Element("test");
|
|
270 |
3
| root.addAttribute(new Attribute("xml:base",
|
|
271 |
| Namespace.XML_NAMESPACE, base)); |
|
272 |
3
| assertEquals("http://www.example.com/%"
|
|
273 |
| + Integer.toHexString(delims[i].charAt(0)).toUpperCase() |
|
274 |
| + "/", root.getBaseURI()); |
|
275 |
| } |
|
276 |
| |
|
277 |
| } |
|
278 |
| |
|
279 |
| |
|
280 |
1
| public void testUnwise() {
|
|
281 |
| |
|
282 |
1
| char[] unwise = {'{', '}', '|', '\\', '^', '`'};
|
|
283 |
1
| for (int i = 0; i < unwise.length; i++) {
|
|
284 |
6
| String base = "http://www.example.com/" + unwise[i] + "/";
|
|
285 |
6
| Element root = new Element("test");
|
|
286 |
6
| root.addAttribute(new Attribute("xml:base",
|
|
287 |
| Namespace.XML_NAMESPACE, base)); |
|
288 |
6
| assertEquals("http://www.example.com/%"
|
|
289 |
| + Integer.toHexString(unwise[i]).toUpperCase() |
|
290 |
| + "/", root.getBaseURI()); |
|
291 |
| } |
|
292 |
| |
|
293 |
| } |
|
294 |
| |
|
295 |
| |
|
296 |
1
| public void testBaseWithUnusualParts() {
|
|
297 |
1
| String base = "HTTP://user@WWW.EXAMPLE.COM:65130/TEST-2+final.XML?name=value&name2=value2";
|
|
298 |
1
| Element root = new Element("test");
|
|
299 |
1
| root.setBaseURI(base);
|
|
300 |
1
| assertEquals(base, root.getBaseURI());
|
|
301 |
| } |
|
302 |
| |
|
303 |
| |
|
304 |
1
| public void testBaseWithEscapedParts() {
|
|
305 |
1
| String base = "http://www.example.com/test%20test";
|
|
306 |
1
| Element root = new Element("test");
|
|
307 |
1
| root.setBaseURI(base);
|
|
308 |
1
| assertEquals(base, root.getBaseURI());
|
|
309 |
| } |
|
310 |
| |
|
311 |
| |
|
312 |
1
| public void testXMLBaseWithPlus() {
|
|
313 |
1
| String base = "http://www.example.com/test+test";
|
|
314 |
1
| Element root = new Element("test");
|
|
315 |
1
| root.addAttribute(new Attribute("xml:base",
|
|
316 |
| Namespace.XML_NAMESPACE, base)); |
|
317 |
1
| assertEquals(base, root.getBaseURI());
|
|
318 |
| } |
|
319 |
| |
|
320 |
| |
|
321 |
1
| public void testXMLBaseWithUserInfoWithXMLBaseAttribute() {
|
|
322 |
1
| String base = "http://invited:test@www.example.com/";
|
|
323 |
1
| Element root = new Element("test");
|
|
324 |
1
| root.addAttribute(new Attribute("xml:base",
|
|
325 |
| Namespace.XML_NAMESPACE, base)); |
|
326 |
1
| assertEquals(base, root.getBaseURI());
|
|
327 |
| } |
|
328 |
| |
|
329 |
| |
|
330 |
1
| public void testElementWithEmptyXMLBaseAttributeHasSameBaseURIAsDocument() {
|
|
331 |
| |
|
332 |
1
| String base = "http://www.example.com/";
|
|
333 |
1
| Element root = new Element("test");
|
|
334 |
1
| root.addAttribute(new Attribute("xml:base",
|
|
335 |
| Namespace.XML_NAMESPACE, base)); |
|
336 |
| |
|
337 |
1
| Element child = new Element("child");
|
|
338 |
1
| root.appendChild(child);
|
|
339 |
1
| child.addAttribute(new Attribute("xml:base",
|
|
340 |
| Namespace.XML_NAMESPACE, "")); |
|
341 |
1
| Document doc = new Document(root);
|
|
342 |
1
| doc.setBaseURI("http://www.cafeaulait.org/");
|
|
343 |
1
| assertEquals("http://www.cafeaulait.org/", child.getBaseURI());
|
|
344 |
| |
|
345 |
| } |
|
346 |
| |
|
347 |
| |
|
348 |
1
| public void testBaseURIOfElementWithEmptyXMLBaseAttributeIsEmptyStringIfTheresNoActualBaseURI() {
|
|
349 |
| |
|
350 |
1
| String base = "http://www.example.com/";
|
|
351 |
1
| Element root = new Element("test");
|
|
352 |
1
| root.addAttribute(new Attribute("xml:base",
|
|
353 |
| Namespace.XML_NAMESPACE, base)); |
|
354 |
| |
|
355 |
1
| Element child = new Element("child");
|
|
356 |
1
| child.addAttribute(new Attribute("xml:base",
|
|
357 |
| Namespace.XML_NAMESPACE, "")); |
|
358 |
1
| root.appendChild(child);
|
|
359 |
1
| new Document(root);
|
|
360 |
1
| assertEquals("", child.getBaseURI());
|
|
361 |
| |
|
362 |
| } |
|
363 |
| |
|
364 |
| |
|
365 |
1
| public void testXMLBaseWithUnreservedCharacters() {
|
|
366 |
1
| String base = "http://www.example.com/()-_.!~*'";
|
|
367 |
1
| Element root = new Element("test");
|
|
368 |
1
| root.addAttribute(new Attribute("xml:base",
|
|
369 |
| Namespace.XML_NAMESPACE, base)); |
|
370 |
1
| assertEquals(base, root.getBaseURI());
|
|
371 |
| } |
|
372 |
| |
|
373 |
| |
|
374 |
1
| public void testXMLBaseWithNonASCIICharacters()
|
|
375 |
| throws UnsupportedEncodingException { |
|
376 |
| |
|
377 |
1
| String omega = "\u03A9";
|
|
378 |
| |
|
379 |
1
| String base = "http://www.example.com/" + omega;
|
|
380 |
1
| Element root = new Element("test");
|
|
381 |
1
| root.addAttribute(new Attribute("xml:base",
|
|
382 |
| Namespace.XML_NAMESPACE, base)); |
|
383 |
1
| assertEquals("http://www.example.com/%CE%A9", root.getBaseURI());
|
|
384 |
| |
|
385 |
| } |
|
386 |
| |
|
387 |
| |
|
388 |
1
| public void testBaseWithNonASCIICharacters()
|
|
389 |
| throws UnsupportedEncodingException { |
|
390 |
| |
|
391 |
1
| String base = "http://www.example.com/%ce%a9";
|
|
392 |
1
| Element root = new Element("test");
|
|
393 |
1
| root.setBaseURI(base);
|
|
394 |
1
| assertEquals(base, root.getBaseURI());
|
|
395 |
| |
|
396 |
| } |
|
397 |
| |
|
398 |
| |
|
399 |
1
| public void testBadIPv6Base() {
|
|
400 |
| |
|
401 |
1
| Element root = new Element("test");
|
|
402 |
1
| try {
|
|
403 |
1
| root.setBaseURI(
|
|
404 |
| "http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]/test.xml#xpointer(/*[1])" |
|
405 |
| ); |
|
406 |
0
| fail("allowed multiple brackets");
|
|
407 |
| } |
|
408 |
| catch (MalformedURIException success) { |
|
409 |
1
| assertNotNull(success.getMessage());
|
|
410 |
| } |
|
411 |
| |
|
412 |
1
| try {
|
|
413 |
1
| root.setBaseURI(
|
|
414 |
| "http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210/" |
|
415 |
| ); |
|
416 |
0
| fail("allowed mismatched brackets");
|
|
417 |
| } |
|
418 |
| catch (MalformedURIException success) { |
|
419 |
1
| assertNotNull(success.getMessage());
|
|
420 |
| } |
|
421 |
| |
|
422 |
1
| try {
|
|
423 |
1
| root.setBaseURI(
|
|
424 |
| "http://]FEDC:BA98:7654:3210:FEDC:BA98:7654:3210[/" |
|
425 |
| ); |
|
426 |
0
| fail("allowed right bracket before left bracket");
|
|
427 |
| } |
|
428 |
| catch (MalformedURIException success) { |
|
429 |
1
| assertNotNull(success.getMessage());
|
|
430 |
| } |
|
431 |
| |
|
432 |
| } |
|
433 |
| |
|
434 |
| |
|
435 |
1
| public void testAllowEmptyXMLBase() {
|
|
436 |
1
| Element root = doc.getRootElement();
|
|
437 |
1
| root.setBaseURI(base1);
|
|
438 |
1
| root.addAttribute(new Attribute("xml:base",
|
|
439 |
| Namespace.XML_NAMESPACE, "")); |
|
440 |
1
| assertEquals(base1, root.getBaseURI());
|
|
441 |
| } |
|
442 |
| |
|
443 |
| |
|
444 |
1
| public void testFailures() {
|
|
445 |
| |
|
446 |
1
| Element root = doc.getRootElement();
|
|
447 |
| |
|
448 |
1
| try {
|
|
449 |
1
| root.setBaseURI("http://www.w3.org/ testing");
|
|
450 |
0
| fail("Allowed URI containing space");
|
|
451 |
| } |
|
452 |
| catch (MalformedURIException success) { |
|
453 |
1
| assertNotNull(success.getMessage());
|
|
454 |
| } |
|
455 |
| |
|
456 |
1
| try {
|
|
457 |
1
| root.setBaseURI("http://www.w3.org/tes%ting");
|
|
458 |
0
| fail("Allowed URI containing %");
|
|
459 |
| } |
|
460 |
| catch (MalformedURIException success) { |
|
461 |
1
| assertNotNull(success.getMessage());
|
|
462 |
| } |
|
463 |
| |
|
464 |
1
| try {
|
|
465 |
1
| root.setBaseURI("http://www.w3.org/%Atesting");
|
|
466 |
0
| fail("Allowed URI containing half percent");
|
|
467 |
| } |
|
468 |
| catch (MalformedURIException success) { |
|
469 |
1
| assertNotNull(success.getMessage());
|
|
470 |
| } |
|
471 |
| |
|
472 |
1
| try {
|
|
473 |
1
| root.setBaseURI("http://www.w3.org/%A");
|
|
474 |
0
| fail("Allowed URI containing half percent at end of path");
|
|
475 |
| } |
|
476 |
| catch (MalformedURIException success) { |
|
477 |
1
| assertNotNull(success.getMessage());
|
|
478 |
| } |
|
479 |
| |
|
480 |
| |
|
481 |
1
| try {
|
|
482 |
1
| root.setBaseURI("http://www.w3.org/^testing");
|
|
483 |
0
| fail("Allowed URI containing unwise character");
|
|
484 |
| } |
|
485 |
| catch (MalformedURIException success) { |
|
486 |
1
| assertNotNull(success.getMessage());
|
|
487 |
| } |
|
488 |
| |
|
489 |
1
| try {
|
|
490 |
1
| root.setBaseURI("http://www.w3.org/<testing");
|
|
491 |
0
| fail("Allowed URI containing unwise < character");
|
|
492 |
| } |
|
493 |
| catch (MalformedURIException success) { |
|
494 |
1
| assertNotNull(success.getMessage());
|
|
495 |
| } |
|
496 |
| |
|
497 |
1
| try {
|
|
498 |
1
| root.setBaseURI("http://www.w3.org/\u0000testing");
|
|
499 |
0
| fail("Allowed URI containing unwise null C0 control character");
|
|
500 |
| } |
|
501 |
| catch (MalformedURIException success) { |
|
502 |
1
| assertNotNull(success.getMessage());
|
|
503 |
| } |
|
504 |
| |
|
505 |
1
| try {
|
|
506 |
1
| root.setBaseURI("http://www.w3.org/\u0007testing");
|
|
507 |
0
| fail("Allowed URI containing unwise BEL C0 control character");
|
|
508 |
| } |
|
509 |
| catch (MalformedURIException success) { |
|
510 |
1
| assertNotNull(success.getMessage());
|
|
511 |
| } |
|
512 |
| |
|
513 |
| |
|
514 |
| } |
|
515 |
| |
|
516 |
| |
|
517 |
| |
|
518 |
| |
|
519 |
| |
|
520 |
1
| public void testXMLBaseFailures() {
|
|
521 |
| |
|
522 |
1
| Attribute base = new Attribute("xml:base",
|
|
523 |
| Namespace.XML_NAMESPACE, "base.html"); |
|
524 |
1
| Element test = new Element("test");
|
|
525 |
1
| test.addAttribute(base);
|
|
526 |
| |
|
527 |
1
| base.setValue("http://www.w3.org/tes%ting");
|
|
528 |
1
| assertEquals("", test.getBaseURI());
|
|
529 |
| |
|
530 |
1
| base.setValue("http://www.w3.org/%Atesting");
|
|
531 |
1
| assertEquals("", test.getBaseURI());
|
|
532 |
| |
|
533 |
1
| base.setValue("http://www.w3.org/%A");
|
|
534 |
1
| assertEquals("", test.getBaseURI());
|
|
535 |
| |
|
536 |
1
| base.setValue("http://www.w3.org/%0testing");
|
|
537 |
1
| assertEquals("", test.getBaseURI());
|
|
538 |
| |
|
539 |
1
| base.setValue("http://www.w3.org/%7testing");
|
|
540 |
1
| assertEquals("", test.getBaseURI());
|
|
541 |
| |
|
542 |
| } |
|
543 |
| |
|
544 |
| |
|
545 |
1
| public void testSyntacticallyIllegalXMLBaseValuesAreIgnored() {
|
|
546 |
| |
|
547 |
1
| Attribute base = new Attribute("xml:base",
|
|
548 |
| Namespace.XML_NAMESPACE, "base.html"); |
|
549 |
1
| Element test = new Element("test");
|
|
550 |
1
| test.setBaseURI("http://www.example.com/");
|
|
551 |
1
| test.addAttribute(base);
|
|
552 |
| |
|
553 |
1
| base.setValue("http://www.w3.org/tes%ting");
|
|
554 |
1
| assertEquals("http://www.example.com/", test.getBaseURI());
|
|
555 |
| |
|
556 |
| } |
|
557 |
| |
|
558 |
| |
|
559 |
| |
|
560 |
| |
|
561 |
| |
|
562 |
1
| public void testValuesLegalInXMLBaseButNotInAURI() {
|
|
563 |
| |
|
564 |
1
| Element element = new Element("test");
|
|
565 |
1
| Attribute base = new Attribute("xml:base",
|
|
566 |
| Namespace.XML_NAMESPACE, "base.html"); |
|
567 |
1
| element.addAttribute(base);
|
|
568 |
| |
|
569 |
1
| base.setValue("http://www.w3.org/ testing");
|
|
570 |
1
| assertEquals("http://www.w3.org/%20testing", element.getBaseURI());
|
|
571 |
| |
|
572 |
1
| base.setValue("http://www.w3.org/^testing");
|
|
573 |
1
| assertEquals("http://www.w3.org/%5Etesting", element.getBaseURI());
|
|
574 |
| |
|
575 |
1
| base.setValue("http://www.w3.org/<testing");
|
|
576 |
1
| assertEquals("http://www.w3.org/%3Ctesting", element.getBaseURI());
|
|
577 |
| |
|
578 |
| } |
|
579 |
| |
|
580 |
| |
|
581 |
1
| public void testXMLBaseValuesCanContainPercentEscapes() {
|
|
582 |
| |
|
583 |
1
| Attribute base = new Attribute("xml:base",
|
|
584 |
| Namespace.XML_NAMESPACE, "base.html"); |
|
585 |
1
| Element e = new Element("test");
|
|
586 |
1
| e.addAttribute(base);
|
|
587 |
1
| base.setValue("http://www.w3.org/%20testing");
|
|
588 |
1
| String baseURI = e.getBaseURI();
|
|
589 |
1
| assertEquals("http://www.w3.org/%20testing", baseURI);
|
|
590 |
| |
|
591 |
| } |
|
592 |
| |
|
593 |
| |
|
594 |
1
| public void testInheritBaseFromDoc() {
|
|
595 |
1
| assertEquals(base1, doc.getRootElement().getBaseURI());
|
|
596 |
| } |
|
597 |
| |
|
598 |
| |
|
599 |
1
| public void testLoadElementFromDifferentEntity() {
|
|
600 |
1
| assertEquals(base2,
|
|
601 |
| doc.getRootElement().getChild(0).getBaseURI()); |
|
602 |
| } |
|
603 |
| |
|
604 |
| |
|
605 |
1
| public void testLeafNode() {
|
|
606 |
1
| assertEquals(
|
|
607 |
| doc.getRootElement().getChild(0).getBaseURI(), |
|
608 |
| doc.getRootElement().getChild(0).getChild(0).getBaseURI() |
|
609 |
| ); |
|
610 |
| } |
|
611 |
| |
|
612 |
| |
|
613 |
1
| public void testLoadElementFromSameEntity() {
|
|
614 |
1
| assertEquals(
|
|
615 |
| base1, |
|
616 |
| doc.getRootElement().getFirstChildElement("child2").getBaseURI() |
|
617 |
| ); |
|
618 |
| } |
|
619 |
| |
|
620 |
| |
|
621 |
1
| public void testXMLBaseAbsolute() {
|
|
622 |
1
| assertEquals(
|
|
623 |
| base2, |
|
624 |
| doc.getRootElement().getFirstChildElement("child3").getBaseURI() |
|
625 |
| ); |
|
626 |
| } |
|
627 |
| |
|
628 |
| |
|
629 |
1
| public void testXMLBaseRelative() {
|
|
630 |
1
| Element e = doc.getRootElement().getFirstChildElement("child4");
|
|
631 |
1
| String u = e.getBaseURI();
|
|
632 |
1
| assertEquals("http://www.base1.com/base3.html", u);
|
|
633 |
| } |
|
634 |
| |
|
635 |
| |
|
636 |
1
| public void testXMLBaseRelativeWithNoRoot() {
|
|
637 |
| |
|
638 |
1
| Element element = new Element("test");
|
|
639 |
1
| element.addAttribute(new Attribute("xml:base",
|
|
640 |
| Namespace.XML_NAMESPACE, "base.html")); |
|
641 |
1
| assertEquals("", element.getBaseURI());
|
|
642 |
| |
|
643 |
| } |
|
644 |
| |
|
645 |
| |
|
646 |
1
| public void testRelativeBaseURIsNotAllowed() {
|
|
647 |
| |
|
648 |
1
| Element element = new Element("test");
|
|
649 |
1
| try {
|
|
650 |
1
| element.setBaseURI("base.html");
|
|
651 |
0
| fail("Allowed relative base URI");
|
|
652 |
| } |
|
653 |
| catch (MalformedURIException success) { |
|
654 |
1
| assertTrue(success.getMessage().toLowerCase().indexOf("absolute") >= 0);
|
|
655 |
| } |
|
656 |
| |
|
657 |
| } |
|
658 |
| |
|
659 |
| |
|
660 |
1
| public void testRelativeURIResolutionAgainstARedirectedBase()
|
|
661 |
| throws IOException, ParsingException { |
|
662 |
| |
|
663 |
1
| Builder builder = new Builder();
|
|
664 |
1
| Document doc = builder.build(
|
|
665 |
| "http://www.ibiblio.org/xml/redirecttest.xml"); |
|
666 |
1
| assertEquals(
|
|
667 |
| "http://www.ibiblio.org/xml/redirected/target.xml", |
|
668 |
| doc.getBaseURI() |
|
669 |
| ); |
|
670 |
| |
|
671 |
| } |
|
672 |
| |
|
673 |
| |
|
674 |
1
| public void testParentlessNodesHaveEmptyBaseURIs() {
|
|
675 |
1
| Text t = new Text("data");
|
|
676 |
1
| assertEquals("", t.getBaseURI());
|
|
677 |
| |
|
678 |
1
| Element e = new Element("a");
|
|
679 |
1
| assertEquals("", e.getBaseURI());
|
|
680 |
| } |
|
681 |
| |
|
682 |
| |
|
683 |
| |
|
684 |
| |
|
685 |
1
| public void testElementsFromDifferentActualBases() {
|
|
686 |
1
| Element parent = new Element("parent");
|
|
687 |
1
| parent.setBaseURI("http://www.cafeconleche.org/");
|
|
688 |
1
| Element child = new Element("child");
|
|
689 |
1
| child.setBaseURI("http://www.example.com/");
|
|
690 |
1
| parent.appendChild(child);
|
|
691 |
1
| child.addAttribute(new Attribute("xml:base",
|
|
692 |
| Namespace.XML_NAMESPACE, "/test/data/")); |
|
693 |
1
| String base = child.getBaseURI();
|
|
694 |
1
| assertEquals("http://www.example.com/test/data/", base);
|
|
695 |
| } |
|
696 |
| |
|
697 |
| |
|
698 |
1
| public void testBadURIInElementsFromDifferentActualBases() {
|
|
699 |
| |
|
700 |
1
| Element parent = new Element("parent");
|
|
701 |
1
| parent.setBaseURI("http://www.cafeconleche.org/");
|
|
702 |
1
| Element child = new Element("child");
|
|
703 |
1
| parent.appendChild(child);
|
|
704 |
1
| child.addAttribute(new Attribute("xml:base",
|
|
705 |
| Namespace.XML_NAMESPACE, |
|
706 |
| "%GF.html")); |
|
707 |
1
| String base = child.getBaseURI();
|
|
708 |
1
| assertEquals("http://www.cafeconleche.org/", base);
|
|
709 |
| |
|
710 |
| } |
|
711 |
| |
|
712 |
| |
|
713 |
1
| public void testBadURIInElementsFromSameActualBases() {
|
|
714 |
| |
|
715 |
1
| Element parent = new Element("parent");
|
|
716 |
1
| parent.setBaseURI("http://www.cafeconleche.org/");
|
|
717 |
1
| Element child = new Element("child");
|
|
718 |
1
| child.setBaseURI("http://www.cafeconleche.org/");
|
|
719 |
1
| parent.appendChild(child);
|
|
720 |
1
| child.addAttribute(new Attribute("xml:base",
|
|
721 |
| Namespace.XML_NAMESPACE, |
|
722 |
| "http://www.example.com/%5.html")); |
|
723 |
1
| assertEquals("http://www.cafeconleche.org/", child.getBaseURI());
|
|
724 |
| |
|
725 |
| } |
|
726 |
| |
|
727 |
| |
|
728 |
1
| public void testBadURIInBaseAttributeWithParent() {
|
|
729 |
| |
|
730 |
1
| Element parent = new Element("parent");
|
|
731 |
1
| parent.setBaseURI("http://www.cafeconleche.org/");
|
|
732 |
1
| Element child = new Element("child");
|
|
733 |
1
| child.setBaseURI("http://www.cafeconleche.org/");
|
|
734 |
1
| parent.appendChild(child);
|
|
735 |
1
| child.addAttribute(new Attribute("xml:base",
|
|
736 |
| Namespace.XML_NAMESPACE, |
|
737 |
| "%TR.html")); |
|
738 |
1
| assertEquals("http://www.cafeconleche.org/", child.getBaseURI());
|
|
739 |
| |
|
740 |
| } |
|
741 |
| |
|
742 |
| |
|
743 |
1
| public void testHierarchicalURIsWithoutProtocolHandlers() {
|
|
744 |
| |
|
745 |
1
| String[] urls = {
|
|
746 |
| "gopher://gopher.uminn.edu/", "GOPHER://gopher.uminn.edu/", |
|
747 |
| "gopher://gopher.uminn.edu", "GOPHER://gopher.uminn.edu", |
|
748 |
| "wais://wais.example.com:78/database", "WAIS://wais.example.com:78/database", |
|
749 |
| "file://vms.host.edu/disk$user/my/notes/note12345.txt", |
|
750 |
| "FILE://vms.host.edu/disk$user/my/notes/note12345.txt", |
|
751 |
| "z39.50s://melvyl.ucop.edu/cat", "Z39.50S://melvyl.ucop.edu/cat", |
|
752 |
| "z39.50r://melvyl.ucop.edu/mags?elecworld.v30.n19", |
|
753 |
| "Z39.50R://melvyl.ucop.edu/mags?elecworld.v30.n19", |
|
754 |
| "z39.50r://cnidr.org:2100/tmf?bkirch_rules__a1;esn=f;rs=marc", |
|
755 |
| "Z39.50R://cnidr.org:2100/tmf?bkirch_rules__a1;esn=f;rs=marc", |
|
756 |
| "vemmi://zeus.mctel.fr/demo", "VEMMI://zeus.mctel.fr/demo", |
|
757 |
| "vemmi://mctel.fr/demo;$USERDATA=smith;account=1234", |
|
758 |
| "xmlrpc.beeps://stateserver.example.com/NumberToName", |
|
759 |
| "XMLRPC.BEEPS://stateserver.example.com/NumberToName", |
|
760 |
| "tn3270://login.example.com/" |
|
761 |
| }; |
|
762 |
1
| for (int i = 0; i < urls.length; i++) {
|
|
763 |
20
| Element e = new Element("test");
|
|
764 |
20
| e.addAttribute(new Attribute("xml:base",
|
|
765 |
| Namespace.XML_NAMESPACE, |
|
766 |
| urls[i])); |
|
767 |
20
| Element child = new Element("child");
|
|
768 |
20
| child.addAttribute(new Attribute("xml:base",
|
|
769 |
| Namespace.XML_NAMESPACE, |
|
770 |
| "TR.html")); |
|
771 |
20
| e.appendChild(child);
|
|
772 |
20
| String base = child.getBaseURI();
|
|
773 |
20
| assertTrue(urls[i] + " " + base, base.endsWith("/TR.html"));
|
|
774 |
20
| assertTrue(base.indexOf("://") >= 4 );
|
|
775 |
| } |
|
776 |
| |
|
777 |
| } |
|
778 |
| |
|
779 |
| |
|
780 |
1
| public void testOpaqueURIs() {
|
|
781 |
| |
|
782 |
1
| String[] urls = {
|
|
783 |
| "MAILTO:elharo@metalab.unc.edu?Subject=XOM%20Namespace", |
|
784 |
| "mailto:elharo@metalab.unc.edu?Subject=XOM%20Namespace", |
|
785 |
| "telnet:namespaces.ibiblio.org", "TELNET:namespaces.ibiblio.org", |
|
786 |
| "uri:urn:nwalsh:namespaces", "URI:urn:nwalsh:namespaces", |
|
787 |
| "news:comp.lang.xml", "NEWS:comp.lang.xml", |
|
788 |
| "mid:960830.1639@XIson.com/partA.960830.1639@XIson.com", |
|
789 |
| "MID:960830.1639@XIson.com/partA.960830.1639@XIson.com", |
|
790 |
| "cid:foo4*foo1@bar.net", "CID:foo4*foo1@bar.net", |
|
791 |
| "opaquelocktoken:f81d4fae-7dec-11d0-a765-00a0c91e6bf6", |
|
792 |
| "OPAQUELOCKTOKEN:f81d4fae-7dec-11d0-a765-00a0c91e6bf6", |
|
793 |
| "fax:+358.555.1234567", "FAX:+358.555.1234567", |
|
794 |
| "modem:+3585551234567;type=v32b?7e1;type=v110", |
|
795 |
| "tel:0w003585551234567;phone-context=+3585551234", |
|
796 |
| "tel:+1234567890;phone-context=+1234;vnd.company.option=foo", |
|
797 |
| "h323:user@h323.example.com", "H323:user@h323.example.com", |
|
798 |
| }; |
|
799 |
1
| for (int i = 0; i < urls.length; i++) {
|
|
800 |
21
| Element e = new Element("test");
|
|
801 |
21
| e.addAttribute(new Attribute("xml:base",
|
|
802 |
| Namespace.XML_NAMESPACE, |
|
803 |
| urls[i])); |
|
804 |
21
| Element child = new Element("child");
|
|
805 |
21
| child.addAttribute(new Attribute("xml:base",
|
|
806 |
| Namespace.XML_NAMESPACE, |
|
807 |
| "TR.html")); |
|
808 |
21
| e.appendChild(child);
|
|
809 |
21
| String base = child.getBaseURI();
|
|
810 |
21
| assertEquals("", base);
|
|
811 |
| } |
|
812 |
| |
|
813 |
| } |
|
814 |
| |
|
815 |
| |
|
816 |
1
| public void testURIStartsWithColon() {
|
|
817 |
| |
|
818 |
1
| String url = ":elharo@metalab.unc.edu?Subject=XOM%20Namespace";
|
|
819 |
1
| Element e = new Element("test");
|
|
820 |
1
| e.addAttribute(new Attribute("xml:base",
|
|
821 |
| Namespace.XML_NAMESPACE, url)); |
|
822 |
1
| Element child = new Element("child");
|
|
823 |
1
| child.addAttribute(new Attribute("xml:base",
|
|
824 |
| Namespace.XML_NAMESPACE, |
|
825 |
| "TR.html")); |
|
826 |
1
| e.appendChild(child);
|
|
827 |
1
| String base = child.getBaseURI();
|
|
828 |
1
| assertEquals("", base);
|
|
829 |
| |
|
830 |
| } |
|
831 |
| |
|
832 |
| |
|
833 |
1
| public void testURIStartsWithNumber() {
|
|
834 |
| |
|
835 |
1
| String url = "7aelharo@metalab.unc.edu?Subject=XOM%20Namespace";
|
|
836 |
1
| Element e = new Element("test");
|
|
837 |
1
| e.addAttribute(new Attribute("xml:base",
|
|
838 |
| Namespace.XML_NAMESPACE, url)); |
|
839 |
1
| Element child = new Element("child");
|
|
840 |
1
| child.addAttribute(new Attribute("xml:base",
|
|
841 |
| Namespace.XML_NAMESPACE, |
|
842 |
| "TR.html")); |
|
843 |
1
| e.appendChild(child);
|
|
844 |
1
| String base = child.getBaseURI();
|
|
845 |
1
| assertEquals("", base);
|
|
846 |
| |
|
847 |
| } |
|
848 |
| |
|
849 |
| |
|
850 |
1
| public void testURISchemeContainsComma() {
|
|
851 |
| |
|
852 |
1
| String url = "foo,foo:elharo@metalab.unc.edu?Subject=XOM%20Namespace";
|
|
853 |
1
| Element e = new Element("test");
|
|
854 |
1
| e.addAttribute(new Attribute("xml:base",
|
|
855 |
| Namespace.XML_NAMESPACE, url)); |
|
856 |
1
| Element child = new Element("child");
|
|
857 |
1
| child.addAttribute(new Attribute("xml:base",
|
|
858 |
| Namespace.XML_NAMESPACE, |
|
859 |
| "TR.html")); |
|
860 |
1
| e.appendChild(child);
|
|
861 |
1
| String base = child.getBaseURI();
|
|
862 |
1
| assertEquals("", base);
|
|
863 |
| |
|
864 |
| } |
|
865 |
| |
|
866 |
| |
|
867 |
1
| public void testXMLBaseUsedToResolveHref()
|
|
868 |
| throws ParsingException, IOException { |
|
869 |
| |
|
870 |
1
| File input = new File("data");
|
|
871 |
1
| input = new File(input, "xmlbasetest.xml");
|
|
872 |
1
| Document doc = builder.build(input);
|
|
873 |
1
| Element root = doc.getRootElement();
|
|
874 |
1
| String base = root.getBaseURI();
|
|
875 |
| |
|
876 |
| |
|
877 |
| |
|
878 |
| |
|
879 |
1
| new URL(base);
|
|
880 |
1
| assertTrue(base.startsWith("file:/"));
|
|
881 |
| |
|
882 |
| } |
|
883 |
| |
|
884 |
| |
|
885 |
1
| public void testBuildElementFromSeveralEntities()
|
|
886 |
| throws ParsingException, IOException { |
|
887 |
| |
|
888 |
1
| File input = new File("data");
|
|
889 |
1
| input = new File(input, "BaseURIWithEntitiesTest.xml");
|
|
890 |
1
| Document doc = builder.build(input);
|
|
891 |
1
| Element root = doc.getRootElement();
|
|
892 |
1
| String rootBase = root.getBaseURI();
|
|
893 |
1
| String childBase = root.getChild(0).getBaseURI();
|
|
894 |
1
| assertFalse(rootBase.equals(childBase));
|
|
895 |
1
| assertTrue(childBase.indexOf("entities") > 0);
|
|
896 |
| |
|
897 |
| } |
|
898 |
| |
|
899 |
| |
|
900 |
1
| public void testReplacedRootRetainsBaseURI() {
|
|
901 |
| |
|
902 |
1
| Element root = new Element("root");
|
|
903 |
1
| Document doc = new Document(root);
|
|
904 |
1
| doc.setBaseURI("http://www.example.com");
|
|
905 |
1
| doc.setRootElement(new Element("data"));
|
|
906 |
1
| assertEquals("http://www.example.com", root.getBaseURI());
|
|
907 |
| |
|
908 |
| } |
|
909 |
| |
|
910 |
| |
|
911 |
1
| public void testDetachedElementRetainsBaseURI() {
|
|
912 |
| |
|
913 |
1
| Element root = new Element("root");
|
|
914 |
1
| Document doc = new Document(root);
|
|
915 |
1
| doc.setBaseURI("http://www.example.com");
|
|
916 |
1
| Element child = new Element("child");
|
|
917 |
1
| root.appendChild(child);
|
|
918 |
1
| child.detach();
|
|
919 |
1
| assertEquals("http://www.example.com", child.getBaseURI());
|
|
920 |
| |
|
921 |
| } |
|
922 |
| |
|
923 |
| |
|
924 |
1
| public void testCopiedElementRetainsBaseURI() {
|
|
925 |
| |
|
926 |
1
| Element root = new Element("root");
|
|
927 |
1
| Document doc = new Document(root);
|
|
928 |
1
| doc.setBaseURI("http://www.example.com");
|
|
929 |
1
| Element child = new Element("child");
|
|
930 |
1
| root.appendChild(child);
|
|
931 |
1
| Node copy = child.copy();
|
|
932 |
1
| assertEquals("http://www.example.com", copy.getBaseURI());
|
|
933 |
| |
|
934 |
| } |
|
935 |
| |
|
936 |
| |
|
937 |
1
| public void testElementRemovedByIndexRetainsBaseURI() {
|
|
938 |
| |
|
939 |
1
| Element root = new Element("root");
|
|
940 |
1
| Document doc = new Document(root);
|
|
941 |
1
| doc.setBaseURI("http://www.example.com");
|
|
942 |
1
| Element child = new Element("child");
|
|
943 |
1
| root.appendChild(child);
|
|
944 |
1
| root.removeChild(0);
|
|
945 |
1
| assertEquals("http://www.example.com", child.getBaseURI());
|
|
946 |
| |
|
947 |
| } |
|
948 |
| |
|
949 |
| |
|
950 |
1
| public void testElementRemovedByReferenceRetainsBaseURI() {
|
|
951 |
| |
|
952 |
1
| Element root = new Element("root");
|
|
953 |
1
| Document doc = new Document(root);
|
|
954 |
1
| doc.setBaseURI("http://www.example.com");
|
|
955 |
1
| Element child = new Element("child");
|
|
956 |
1
| root.appendChild(child);
|
|
957 |
1
| root.removeChild(child);
|
|
958 |
1
| assertEquals("http://www.example.com", child.getBaseURI());
|
|
959 |
| |
|
960 |
| } |
|
961 |
| |
|
962 |
| |
|
963 |
1
| public void testRemovedChildrenRetainBaseURI() {
|
|
964 |
| |
|
965 |
1
| Element root = new Element("root");
|
|
966 |
1
| Document doc = new Document(root);
|
|
967 |
1
| doc.setBaseURI("http://www.example.com");
|
|
968 |
1
| Element child = new Element("child");
|
|
969 |
1
| root.appendChild(child);
|
|
970 |
1
| root.removeChildren();
|
|
971 |
1
| assertEquals("http://www.example.com", child.getBaseURI());
|
|
972 |
| |
|
973 |
| } |
|
974 |
| |
|
975 |
| |
|
976 |
1
| public void testXMLBaseAttributesAreOnlyUsedIfTheyreInTheSameEntity() {
|
|
977 |
| |
|
978 |
1
| Element top = new Element("top");
|
|
979 |
1
| top.addAttribute(new Attribute("xml:base",
|
|
980 |
| Namespace.XML_NAMESPACE, |
|
981 |
| "http://www.example.com/")); |
|
982 |
1
| top.setBaseURI("http://www.w3.org");
|
|
983 |
1
| Element bottom = new Element("bottom");
|
|
984 |
1
| bottom.setBaseURI("http://www.example.net");
|
|
985 |
1
| top.appendChild(bottom);
|
|
986 |
1
| assertEquals("http://www.example.net", bottom.getBaseURI());
|
|
987 |
| |
|
988 |
1
| top.setBaseURI(null);
|
|
989 |
1
| assertEquals("http://www.example.net", bottom.getBaseURI());
|
|
990 |
| |
|
991 |
| } |
|
992 |
| |
|
993 |
| |
|
994 |
1
| public void testXMLBaseAttributesInTheSameEntityOverrideActualBaseURI() {
|
|
995 |
| |
|
996 |
1
| Element top = new Element("top");
|
|
997 |
1
| top.addAttribute(new Attribute("xml:base",
|
|
998 |
| Namespace.XML_NAMESPACE, |
|
999 |
| "http://www.example.com/")); |
|
1000 |
1
| top.setBaseURI("http://www.w3.org");
|
|
1001 |
1
| Element bottom = new Element("bottom");
|
|
1002 |
1
| bottom.setBaseURI("http://www.w3.org");
|
|
1003 |
1
| top.appendChild(bottom);
|
|
1004 |
1
| assertEquals("http://www.example.com/", bottom.getBaseURI());
|
|
1005 |
| |
|
1006 |
| } |
|
1007 |
| |
|
1008 |
| |
|
1009 |
1
| public void testRelativeBaseURIResolution() {
|
|
1010 |
| |
|
1011 |
1
| Element root = new Element("root");
|
|
1012 |
1
| Attribute baseAttribute = new Attribute("xml:base",
|
|
1013 |
| Namespace.XML_NAMESPACE, "http://www.example.com/data/limit/test.xml"); |
|
1014 |
1
| root.addAttribute(baseAttribute);
|
|
1015 |
1
| Element child = new Element ("child");
|
|
1016 |
1
| child.addAttribute(new Attribute("xml:base",
|
|
1017 |
| Namespace.XML_NAMESPACE, "child.xml")); |
|
1018 |
1
| root.appendChild(child);
|
|
1019 |
1
| assertEquals("http://www.example.com/data/limit/child.xml", child.getBaseURI());
|
|
1020 |
| |
|
1021 |
| } |
|
1022 |
| |
|
1023 |
| |
|
1024 |
1
| public void testRelativeBaseURIResolutionWithNumbers() {
|
|
1025 |
| |
|
1026 |
1
| Element root = new Element("root");
|
|
1027 |
1
| Attribute baseAttribute = new Attribute("xml:base",
|
|
1028 |
| Namespace.XML_NAMESPACE, "http://www.example.com/data/limit/test.xml"); |
|
1029 |
1
| root.addAttribute(baseAttribute);
|
|
1030 |
1
| Element child = new Element ("child");
|
|
1031 |
1
| child.addAttribute(new Attribute("xml:base",
|
|
1032 |
| Namespace.XML_NAMESPACE, "01test.xml")); |
|
1033 |
1
| root.appendChild(child);
|
|
1034 |
1
| assertEquals("http://www.example.com/data/limit/01test.xml", child.getBaseURI());
|
|
1035 |
| |
|
1036 |
| } |
|
1037 |
| |
|
1038 |
| |
|
1039 |
1
| public void testRelativeBaseURIStartsWithDotSlash() {
|
|
1040 |
| |
|
1041 |
1
| Element root = new Element("root");
|
|
1042 |
1
| Attribute baseAttribute = new Attribute("xml:base",
|
|
1043 |
| Namespace.XML_NAMESPACE, "http://www.example.com/data/limit/test.xml"); |
|
1044 |
1
| root.addAttribute(baseAttribute);
|
|
1045 |
1
| Element child = new Element ("child");
|
|
1046 |
1
| child.addAttribute(new Attribute("xml:base",
|
|
1047 |
| Namespace.XML_NAMESPACE, "./test.xml")); |
|
1048 |
1
| root.appendChild(child);
|
|
1049 |
1
| assertEquals("http://www.example.com/data/limit/test.xml", child.getBaseURI());
|
|
1050 |
| |
|
1051 |
| } |
|
1052 |
| |
|
1053 |
| |
|
1054 |
1
| public void testRelativeBaseURIIsDot() {
|
|
1055 |
| |
|
1056 |
1
| Element root = new Element("root");
|
|
1057 |
1
| Attribute baseAttribute = new Attribute("xml:base",
|
|
1058 |
| Namespace.XML_NAMESPACE, "http://www.example.com/data/limit/test.xml"); |
|
1059 |
1
| root.addAttribute(baseAttribute);
|
|
1060 |
1
| Element child = new Element ("child");
|
|
1061 |
1
| child.addAttribute(new Attribute("xml:base",
|
|
1062 |
| Namespace.XML_NAMESPACE, ".")); |
|
1063 |
1
| root.appendChild(child);
|
|
1064 |
1
| assertEquals("http://www.example.com/data/limit/", child.getBaseURI());
|
|
1065 |
| |
|
1066 |
| } |
|
1067 |
| |
|
1068 |
| |
|
1069 |
1
| public void testRelativeBaseURIIsDotDot() {
|
|
1070 |
| |
|
1071 |
1
| Element root = new Element("root");
|
|
1072 |
1
| Attribute baseAttribute = new Attribute("xml:base",
|
|
1073 |
| Namespace.XML_NAMESPACE, "http://www.example.com/data/limit/test.xml"); |
|
1074 |
1
| root.addAttribute(baseAttribute);
|
|
1075 |
1
| Element child = new Element ("child");
|
|
1076 |
1
| child.addAttribute(new Attribute("xml:base",
|
|
1077 |
| Namespace.XML_NAMESPACE, "..")); |
|
1078 |
1
| root.appendChild(child);
|
|
1079 |
1
| assertEquals("http://www.example.com/data/", child.getBaseURI());
|
|
1080 |
| |
|
1081 |
| } |
|
1082 |
| |
|
1083 |
| |
|
1084 |
1
| public void testRelativeBaseURIStartsWithDotDotSlash() {
|
|
1085 |
| |
|
1086 |
1
| Element root = new Element("root");
|
|
1087 |
1
| Attribute baseAttribute = new Attribute("xml:base",
|
|
1088 |
| Namespace.XML_NAMESPACE, "http://www.example.com/data/limit/test.xml"); |
|
1089 |
1
| root.addAttribute(baseAttribute);
|
|
1090 |
1
| Element child = new Element ("child");
|
|
1091 |
1
| child.addAttribute(new Attribute("xml:base",
|
|
1092 |
| Namespace.XML_NAMESPACE, "../test.xml")); |
|
1093 |
1
| root.appendChild(child);
|
|
1094 |
1
| assertEquals("http://www.example.com/data/test.xml", child.getBaseURI());
|
|
1095 |
| |
|
1096 |
| } |
|
1097 |
| |
|
1098 |
| |
|
1099 |
1
| public void testAbsoluteBaseURIEndsWithDotDotSlash() {
|
|
1100 |
| |
|
1101 |
1
| Element root = new Element("root");
|
|
1102 |
1
| Attribute baseAttribute = new Attribute("xml:base",
|
|
1103 |
| Namespace.XML_NAMESPACE, "http://www.example.com/data/limit/../"); |
|
1104 |
1
| root.addAttribute(baseAttribute);
|
|
1105 |
1
| Element child = new Element ("child");
|
|
1106 |
1
| child.addAttribute(new Attribute("xml:base",
|
|
1107 |
| Namespace.XML_NAMESPACE, "test.xml")); |
|
1108 |
1
| root.appendChild(child);
|
|
1109 |
1
| assertEquals("http://www.example.com/data/test.xml", child.getBaseURI());
|
|
1110 |
| |
|
1111 |
| } |
|
1112 |
| |
|
1113 |
| |
|
1114 |
1
| public void testAbsoluteBaseURIEndsWithDotDotSlashDotDot() {
|
|
1115 |
| |
|
1116 |
1
| Element root = new Element("root");
|
|
1117 |
1
| Attribute baseAttribute = new Attribute("xml:base",
|
|
1118 |
| Namespace.XML_NAMESPACE, "http://www.example.com/../.."); |
|
1119 |
1
| root.addAttribute(baseAttribute);
|
|
1120 |
1
| Element child = new Element ("child");
|
|
1121 |
1
| child.addAttribute(new Attribute("xml:base",
|
|
1122 |
| Namespace.XML_NAMESPACE, "test.xml")); |
|
1123 |
1
| root.appendChild(child);
|
|
1124 |
1
| assertEquals("http://www.example.com/test.xml", child.getBaseURI());
|
|
1125 |
| |
|
1126 |
| } |
|
1127 |
| |
|
1128 |
| |
|
1129 |
| |
|
1130 |
1
| public void testAbsoluteBaseURIEndsWithDotDot() {
|
|
1131 |
| |
|
1132 |
1
| Element root = new Element("root");
|
|
1133 |
1
| Attribute baseAttribute = new Attribute("xml:base",
|
|
1134 |
| Namespace.XML_NAMESPACE, "http://www.example.com/data/limit/.."); |
|
1135 |
1
| root.addAttribute(baseAttribute);
|
|
1136 |
1
| Element child = new Element ("child");
|
|
1137 |
1
| child.addAttribute(new Attribute("xml:base",
|
|
1138 |
| Namespace.XML_NAMESPACE, "test.xml")); |
|
1139 |
1
| root.appendChild(child);
|
|
1140 |
1
| assertEquals("http://www.example.com/data/test.xml", child.getBaseURI());
|
|
1141 |
| |
|
1142 |
| } |
|
1143 |
| |
|
1144 |
| |
|
1145 |
| |
|
1146 |
1
| public void testRFC2396NormalExamples() {
|
|
1147 |
| |
|
1148 |
1
| String[] RFC2396bisCases = {
|
|
1149 |
| "g:h", "g:h", |
|
1150 |
| "g", "http://a/b/c/g", |
|
1151 |
| "./g", "http://a/b/c/g", |
|
1152 |
| "g/", "http://a/b/c/g/", |
|
1153 |
| "/g", "http://a/g", |
|
1154 |
| "//g", "http://g", |
|
1155 |
| "?y", "http://a/b/c/d;p?y", |
|
1156 |
| "g?y", "http://a/b/c/g?y", |
|
1157 |
| "#s", "http://a/b/c/d;p?q#s", |
|
1158 |
| "g#s", "http://a/b/c/g#s", |
|
1159 |
| "g?y#s", "http://a/b/c/g?y#s", |
|
1160 |
| ";x", "http://a/b/c/;x", |
|
1161 |
| "g;x", "http://a/b/c/g;x", |
|
1162 |
| "g;x?y#s", "http://a/b/c/g;x?y#s", |
|
1163 |
| "", "http://a/b/c/d;p?q", |
|
1164 |
| ".", "http://a/b/c/", |
|
1165 |
| "./", "http://a/b/c/", |
|
1166 |
| "..", "http://a/b/", |
|
1167 |
| "../", "http://a/b/", |
|
1168 |
| "../g", "http://a/b/g", |
|
1169 |
| "../..", "http://a/", |
|
1170 |
| "../../", "http://a/", |
|
1171 |
| "../../g", "http://a/g" |
|
1172 |
| }; |
|
1173 |
| |
|
1174 |
1
| Element root = new Element("root");
|
|
1175 |
1
| Document doc = new Document(root);
|
|
1176 |
1
| doc.setBaseURI("http://a/b/c/d;p?q");
|
|
1177 |
1
| Attribute base = new Attribute("xml:base", Namespace.XML_NAMESPACE, "g");
|
|
1178 |
1
| root.addAttribute(base);
|
|
1179 |
1
| for (int i = 0; i < RFC2396bisCases.length; i += 2) {
|
|
1180 |
23
| base.setValue(RFC2396bisCases[i]);
|
|
1181 |
23
| assertEquals(RFC2396bisCases[i], RFC2396bisCases[i+1], root.getBaseURI());
|
|
1182 |
| } |
|
1183 |
| |
|
1184 |
| } |
|
1185 |
| |
|
1186 |
| |
|
1187 |
1
| public void testRFC2396AbnormalExamples() {
|
|
1188 |
| |
|
1189 |
1
| String[] RFC2396bisCases = {
|
|
1190 |
| "../../../g", "http://a/g", |
|
1191 |
| "../../../../g", "http://a/g", |
|
1192 |
| "/./g", "http://a/g", |
|
1193 |
| "/../g", "http://a/g", |
|
1194 |
| "g.", "http://a/b/c/g.", |
|
1195 |
| ".g", "http://a/b/c/.g", |
|
1196 |
| "g..", "http://a/b/c/g..", |
|
1197 |
| "..g", "http://a/b/c/..g", |
|
1198 |
| "./../g", "http://a/b/g", |
|
1199 |
| "./g/.", "http://a/b/c/g/", |
|
1200 |
| "g/./h", "http://a/b/c/g/h", |
|
1201 |
| "g/../h", "http://a/b/c/h", |
|
1202 |
| "g;x=1/./y", "http://a/b/c/g;x=1/y", |
|
1203 |
| "g;x=1/../y", "http://a/b/c/y", |
|
1204 |
| "g?y/./x", "http://a/b/c/g?y/./x", |
|
1205 |
| "g?y/../x", "http://a/b/c/g?y/../x", |
|
1206 |
| "g#s/./x", "http://a/b/c/g#s/./x", |
|
1207 |
| "g#s/../x", "http://a/b/c/g#s/../x", |
|
1208 |
| "http:g", "http:g" |
|
1209 |
| }; |
|
1210 |
| |
|
1211 |
1
| Element root = new Element("root");
|
|
1212 |
1
| Document doc = new Document(root);
|
|
1213 |
1
| doc.setBaseURI("http://a/b/c/d;p?q");
|
|
1214 |
1
| Attribute base = new Attribute("xml:base", Namespace.XML_NAMESPACE, "g");
|
|
1215 |
1
| root.addAttribute(base);
|
|
1216 |
1
| for (int i = 0; i < RFC2396bisCases.length; i += 2) {
|
|
1217 |
19
| base.setValue(RFC2396bisCases[i]);
|
|
1218 |
19
| assertEquals(RFC2396bisCases[i], RFC2396bisCases[i+1], root.getBaseURI());
|
|
1219 |
| } |
|
1220 |
| |
|
1221 |
| } |
|
1222 |
| |
|
1223 |
1
| public void testSlashDotDot() {
|
|
1224 |
| |
|
1225 |
1
| Element root = new Element("root");
|
|
1226 |
1
| Document doc = new Document(root);
|
|
1227 |
1
| doc.setBaseURI("http://www.example.com/");
|
|
1228 |
1
| Attribute base = new Attribute("xml:base", Namespace.XML_NAMESPACE, "g");
|
|
1229 |
1
| root.addAttribute(base);
|
|
1230 |
1
| base.setValue("..");
|
|
1231 |
1
| assertEquals("http://www.example.com/", root.getBaseURI());
|
|
1232 |
| |
|
1233 |
| } |
|
1234 |
| |
|
1235 |
1
| public void testSlashDotDotSlashDotDot() {
|
|
1236 |
| |
|
1237 |
1
| Element root = new Element("root");
|
|
1238 |
1
| Document doc = new Document(root);
|
|
1239 |
1
| doc.setBaseURI("http://www.example.com/");
|
|
1240 |
1
| Attribute base = new Attribute("xml:base", Namespace.XML_NAMESPACE, "g");
|
|
1241 |
1
| root.addAttribute(base);
|
|
1242 |
1
| base.setValue("../..");
|
|
1243 |
1
| assertEquals("http://www.example.com/", root.getBaseURI());
|
|
1244 |
| |
|
1245 |
| } |
|
1246 |
| |
|
1247 |
1
| public void testSlashDot() {
|
|
1248 |
| |
|
1249 |
1
| Element root = new Element("root");
|
|
1250 |
1
| Document doc = new Document(root);
|
|
1251 |
1
| doc.setBaseURI("http://www.example.com/");
|
|
1252 |
1
| Attribute base = new Attribute("xml:base", Namespace.XML_NAMESPACE, "g");
|
|
1253 |
1
| root.addAttribute(base);
|
|
1254 |
1
| base.setValue(".");
|
|
1255 |
1
| assertEquals("http://www.example.com/", root.getBaseURI());
|
|
1256 |
| |
|
1257 |
| } |
|
1258 |
| |
|
1259 |
| } |