|
1 | 1 | /* |
2 | | - What would jim do? |
| 2 | + * What would jim do? |
| 3 | + * more tests for border-edge cases |
| 4 | + * Christian Harms. |
| 5 | + * |
| 6 | + * Note: I have no clue who or what jim is supposed to be. It might be something like the German DAU (dumbest possible user) |
| 7 | + */ |
3 | 8 |
|
4 | | - more tests for border-edge cases |
5 | | -
|
6 | | - Christian Harms. |
7 | | -
|
8 | | -*/ |
9 | | - |
10 | | -// try to set one part - modify the next part |
11 | 9 | module("injection"); |
12 | 10 | test("protocol", function() { |
13 | 11 | var u = new URI("http://example.com/dir1/dir2/?query1=value1&query2=value2#hash"); |
14 | | - u.protocol("ftp://example.org"); |
| 12 | + raises(function() { |
| 13 | + u.protocol("ftp://example.org"); |
| 14 | + }, TypeError, "Failing invalid characters"); |
| 15 | + |
| 16 | + u.protocol("ftp:"); |
15 | 17 | equal(u.protocol(), "ftp", "protocol() has set invalid protocoll!"); |
16 | 18 | equal(u.hostname(), "example.com", "protocol() has changed the hostname"); |
17 | | - }); |
18 | | - |
| 19 | +}); |
19 | 20 | test("port", function() { |
20 | 21 | var u = new URI("http://example.com/dir1/dir2/?query1=value1&query2=value2#hash"); |
21 | | - u.port("99:example.org"); |
| 22 | + raises(function() { |
| 23 | + u.port("99:example.org"); |
| 24 | + }, TypeError, "Failing invalid characters"); |
| 25 | + |
| 26 | + u.port(":99"); |
22 | 27 | equal(u.hostname(), "example.com", "port() has modified hostname"); |
23 | 28 | equal(u.port(), 99, "port() has set an invalid port"); |
24 | | - }); |
25 | | -test("domain", function() { |
26 | | - var u = new URI("http://example.com/dir1/dir2/?query1=value1&query2=value2#hash"); |
27 | | - u.domain("example.org/dir0/"); |
28 | | - equal(u.hostname(), "example.com", "domain() has set invalid domain"); |
29 | | - equal(u.path(), "/dir1/dir2/", "domain() has inflicted path with part of domainname"); |
30 | 29 |
|
31 | | - }); |
| 30 | + u.port(false); |
| 31 | + equal(u.port(), "", "port() has set an invalid port"); |
| 32 | + |
| 33 | + // RFC 3986 says nothing about "16-bit unsigned" http://tools.ietf.org/html/rfc3986#section-3.2.3 |
| 34 | + // u.href(new URI("http://example.com/")) |
| 35 | + // u.port(65536); |
| 36 | + // notEqual(u.port(), "65536", "port() has set to an non-valid value (A port number is a 16-bit unsigned integer)"); |
32 | 37 |
|
| 38 | + raises(function() { |
| 39 | + u.port("-99"); |
| 40 | + }, TypeError, "Failing invalid characters"); |
| 41 | +}); |
| 42 | +test("domain", function() { |
| 43 | + var u = new URI("http://example.com/dir1/dir2/?query1=value1&query2=value2#hash"); |
| 44 | + |
| 45 | + raises(function() { |
| 46 | + u.domain("example.org/dir0/"); |
| 47 | + }, TypeError, "Failing invalid characters"); |
| 48 | + |
| 49 | + raises(function() { |
| 50 | + u.domain("example.org:80"); |
| 51 | + }, TypeError, "Failing invalid characters"); |
| 52 | + |
| 53 | + raises(function() { |
| 54 | + u.domain("foo@example.org"); |
| 55 | + }, TypeError, "Failing invalid characters"); |
| 56 | +}); |
| 57 | +test("subdomain", function() { |
| 58 | + var u = new URI("http://example.com/dir1/dir2/?query1=value1&query2=value2#hash"); |
| 59 | + |
| 60 | + raises(function() { |
| 61 | + u.subdomain("example.org/dir0/"); |
| 62 | + }, TypeError, "Failing invalid characters"); |
| 63 | + |
| 64 | + raises(function() { |
| 65 | + u.subdomain("example.org:80"); |
| 66 | + }, TypeError, "Failing invalid characters"); |
| 67 | + |
| 68 | + raises(function() { |
| 69 | + u.subdomain("foo@example.org"); |
| 70 | + }, TypeError, "Failing invalid characters"); |
| 71 | +}); |
| 72 | +test("tld", function() { |
| 73 | + var u = new URI("http://example.com/dir1/dir2/?query1=value1&query2=value2#hash"); |
| 74 | + |
| 75 | + raises(function() { |
| 76 | + u.tld("foo/bar.html"); |
| 77 | + }, TypeError, "Failing invalid characters"); |
| 78 | +}); |
33 | 79 | test("path", function() { |
34 | 80 | var u = new URI("http://example.com/dir1/dir2/?query1=value1&query2=value2#hash"); |
35 | | - u.path("/dir3/?query3=value3"); |
| 81 | + u.path("/dir3/?query3=value3#fragment"); |
36 | 82 | equal(u.hostname(), "example.com", "path() has modified hostname"); |
37 | | - equal(u.path(), "/dir3/%3Fquery3=value3", "path() has set invalid path"); |
| 83 | + equal(u.path(), "/dir3/%3Fquery3=value3%23fragment", "path() has set invalid path"); |
38 | 84 | equal(u.query(), "query1=value1&query2=value2", "path() has modified query"); |
39 | | - }); |
40 | | - |
| 85 | + equal(u.fragment(), "hash", "path() has modified fragment"); |
| 86 | +}); |
41 | 87 | test("filename", function() { |
42 | 88 | var u = new URI("http://example.com/dir1/dir2/?query1=value1&query2=value2#hash"); |
43 | | - u.filename("../name.html?query"); |
44 | | - equal(u.hostname(), "example.com", "filename() has modified hostname"); |
45 | | - equal(u.path(), "/dir1/dir2/", "filename() has modified path"); |
46 | | - equal(u.filename(), "name.html%3Fquery", "filename() has set invalid filename") |
| 89 | + |
| 90 | + u.filename("name.html?query"); |
| 91 | + equal(u.filename(), "name.html%3Fquery", "filename() has set invalid filename"); |
47 | 92 | equal(u.query(), "query1=value1&query2=value2", "filename() has modified query"); |
48 | | - }); |
49 | | - |
| 93 | + |
| 94 | + // allowed! |
| 95 | + u.filename("../name.html?query"); |
| 96 | + equal(u.filename(), "name.html%3Fquery", "filename() has set invalid filename"); |
| 97 | + equal(u.directory(), "/dir1", "filename() has not altered directory properly"); |
| 98 | +}); |
50 | 99 | test("addQuery", function() { |
51 | 100 | var u = new URI("http://example.com/dir1/dir2/?query1=value1&query2=value2#hash"); |
52 | 101 | u.addQuery("query3", "value3#got"); |
53 | 102 | equal(u.query(), "query1=value1&query2=value2&query3=value3%23got", "addQuery() has set invalid query"); |
54 | 103 | equal(u.fragment(), "hash", "addQuery() has modified fragment"); |
55 | | - }); |
| 104 | +}); |
56 | 105 |
|
57 | | - |
58 | | -// try to set not-valid values - check the rfc-allowed parts |
| 106 | + |
| 107 | +/* |
| 108 | +// RFC 3986 says "…and should limit these names to no more than 255 characters in length." |
| 109 | +// SHOULD is not MUST therefore not the responsibility of URI.js |
59 | 110 |
|
60 | 111 | module("validation"); |
61 | 112 | test("domain", function() { |
@@ -88,12 +139,5 @@ test("domain", function() { |
88 | 139 | } |
89 | 140 | u.domain(domain); |
90 | 141 | equals(u.hostname() == domain, true, "set domain() with 70-character subdomain not valid domainname"); |
91 | | - }); |
92 | | - |
93 | | -test("port", function() { |
94 | | - var u = new URI("http://example.com/"); |
95 | | - u.port(65536); |
96 | | - equal(u.port() === 65536, false, "port() has set to an non-valid value (A port number is a 16-bit unsigned integer)"); |
97 | | - u.port(-1); |
98 | | - equal(u.port() === -1, false, "port() has set to an non-valid value (A port number is a 16-bit unsigned integer)"); |
99 | | - }); |
| 142 | +}); |
| 143 | +*/ |
0 commit comments