kea-rails 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kea-rails/version.rb +1 -1
- data/vendor/assets/components/Keypress/LICENSE +191 -0
- data/vendor/assets/components/Keypress/README.md +78 -0
- data/vendor/assets/components/Keypress/bower.json +28 -0
- data/vendor/assets/components/Keypress/keypress-2.1.0.min.js +33 -0
- data/vendor/assets/components/Keypress/keypress.coffee +921 -0
- data/vendor/assets/components/Keypress/keypress.js +1132 -0
- data/vendor/assets/components/Keypress/package.json +15 -0
- data/vendor/assets/components/attachejs/attache-jquery.js +47 -0
- data/vendor/assets/components/attachejs/attache-knockout.js +56 -0
- data/vendor/assets/components/attachejs/attache.css +10 -0
- data/vendor/assets/components/attachejs/attache.js +589 -0
- data/vendor/assets/components/attachejs/bower.json +36 -0
- data/vendor/assets/components/humane-js/bower.json +8 -0
- data/vendor/assets/components/humane-js/changelog.md +165 -0
- data/vendor/assets/components/humane-js/humane.js +238 -0
- data/vendor/assets/components/humane-js/humane.min.js +11 -0
- data/vendor/assets/components/humane-js/index.html +190 -0
- data/vendor/assets/components/humane-js/package.json +25 -0
- data/vendor/assets/components/humane-js/readme.md +85 -0
- data/vendor/assets/components/humane-js/test/issue23.html +11 -0
- data/vendor/assets/components/humane-js/test/issue36.html +9 -0
- data/vendor/assets/components/humane-js/test/issue38.html +15 -0
- data/vendor/assets/components/humane-js/test/issue49.html +9 -0
- data/vendor/assets/components/humane-js/theme-src/bigbox.styl +65 -0
- data/vendor/assets/components/humane-js/theme-src/boldlight.styl +64 -0
- data/vendor/assets/components/humane-js/theme-src/jackedup.styl +69 -0
- data/vendor/assets/components/humane-js/theme-src/libnotify.styl +61 -0
- data/vendor/assets/components/humane-js/theme-src/original.styl +51 -0
- data/vendor/assets/components/humane-js/themes/bigbox.css +123 -0
- data/vendor/assets/components/humane-js/themes/boldlight.css +122 -0
- data/vendor/assets/components/humane-js/themes/flatty.css +94 -0
- data/vendor/assets/components/humane-js/themes/jackedup.css +123 -0
- data/vendor/assets/components/humane-js/themes/libnotify.css +115 -0
- data/vendor/assets/components/humane-js/themes/original.css +72 -0
- data/vendor/assets/components/knockout-sortable/README.md +129 -0
- data/vendor/assets/components/knockout-sortable/bower.json +15 -0
- data/vendor/assets/components/knockout-sortable/build/knockout-sortable.js +358 -0
- data/vendor/assets/components/knockout-sortable/build/knockout-sortable.min.js +2 -0
- data/vendor/assets/components/uri.js/README.md +437 -0
- data/vendor/assets/components/uri.js/URI.jquery.json +38 -0
- data/vendor/assets/components/uri.js/about-uris.html +156 -0
- data/vendor/assets/components/uri.js/build.html +66 -0
- data/vendor/assets/components/uri.js/build.js +78 -0
- data/vendor/assets/components/uri.js/component.json +15 -0
- data/vendor/assets/components/uri.js/contribute.md +11 -0
- data/vendor/assets/components/uri.js/docs.html +1280 -0
- data/vendor/assets/components/uri.js/index.html +173 -0
- data/vendor/assets/components/uri.js/jquery-1.10.2.min.js +6 -0
- data/vendor/assets/components/uri.js/jquery-1.7.2.min.js +4 -0
- data/vendor/assets/components/uri.js/jquery-1.8.2.min.js +2 -0
- data/vendor/assets/components/uri.js/jquery-1.9.1.min.js +5 -0
- data/vendor/assets/components/uri.js/jquery-uri-plugin.html +203 -0
- data/vendor/assets/components/uri.js/package.json +75 -0
- data/vendor/assets/components/uri.js/prettify/lang-apollo.js +2 -0
- data/vendor/assets/components/uri.js/prettify/lang-clj.js +18 -0
- data/vendor/assets/components/uri.js/prettify/lang-css.js +2 -0
- data/vendor/assets/components/uri.js/prettify/lang-go.js +1 -0
- data/vendor/assets/components/uri.js/prettify/lang-hs.js +2 -0
- data/vendor/assets/components/uri.js/prettify/lang-lisp.js +3 -0
- data/vendor/assets/components/uri.js/prettify/lang-lua.js +2 -0
- data/vendor/assets/components/uri.js/prettify/lang-ml.js +2 -0
- data/vendor/assets/components/uri.js/prettify/lang-n.js +4 -0
- data/vendor/assets/components/uri.js/prettify/lang-proto.js +1 -0
- data/vendor/assets/components/uri.js/prettify/lang-scala.js +2 -0
- data/vendor/assets/components/uri.js/prettify/lang-sql.js +2 -0
- data/vendor/assets/components/uri.js/prettify/lang-tex.js +1 -0
- data/vendor/assets/components/uri.js/prettify/lang-vb.js +2 -0
- data/vendor/assets/components/uri.js/prettify/lang-vhdl.js +3 -0
- data/vendor/assets/components/uri.js/prettify/lang-wiki.js +2 -0
- data/vendor/assets/components/uri.js/prettify/lang-xq.js +3 -0
- data/vendor/assets/components/uri.js/prettify/lang-yaml.js +2 -0
- data/vendor/assets/components/uri.js/prettify/prettify.css +1 -0
- data/vendor/assets/components/uri.js/prettify/prettify.js +28 -0
- data/vendor/assets/components/uri.js/prettify/prettify.sunburst.css +52 -0
- data/vendor/assets/components/uri.js/screen.css +167 -0
- data/vendor/assets/components/uri.js/screen.js +39 -0
- data/vendor/assets/components/uri.js/src/IPv6.js +185 -0
- data/vendor/assets/components/uri.js/src/SecondLevelDomains.js +220 -0
- data/vendor/assets/components/uri.js/src/URI.fragmentQuery.js +103 -0
- data/vendor/assets/components/uri.js/src/URI.fragmentURI.js +96 -0
- data/vendor/assets/components/uri.js/src/URI.js +1938 -0
- data/vendor/assets/components/uri.js/src/URI.min.js +81 -0
- data/vendor/assets/components/uri.js/src/URITemplate.js +494 -0
- data/vendor/assets/components/uri.js/src/jquery.URI.js +232 -0
- data/vendor/assets/components/uri.js/src/jquery.URI.min.js +7 -0
- data/vendor/assets/components/uri.js/src/punycode.js +508 -0
- data/vendor/assets/components/uri.js/test/index.html +26 -0
- data/vendor/assets/components/uri.js/test/pre_libs.js +4 -0
- data/vendor/assets/components/uri.js/test/qunit/qunit-composite.css +13 -0
- data/vendor/assets/components/uri.js/test/qunit/qunit-composite.js +167 -0
- data/vendor/assets/components/uri.js/test/qunit/qunit.css +244 -0
- data/vendor/assets/components/uri.js/test/qunit/qunit.js +2212 -0
- data/vendor/assets/components/uri.js/test/test.URI.html +26 -0
- data/vendor/assets/components/uri.js/test/test.fragmentQuery.html +31 -0
- data/vendor/assets/components/uri.js/test/test.fragmentURI.html +31 -0
- data/vendor/assets/components/uri.js/test/test.jQuery-1.10.html +31 -0
- data/vendor/assets/components/uri.js/test/test.jQuery-1.7.html +31 -0
- data/vendor/assets/components/uri.js/test/test.jQuery-1.8.html +31 -0
- data/vendor/assets/components/uri.js/test/test.jQuery-1.9.html +31 -0
- data/vendor/assets/components/uri.js/test/test.js +1409 -0
- data/vendor/assets/components/uri.js/test/test_fragmentQuery.js +57 -0
- data/vendor/assets/components/uri.js/test/test_fragmentURI.js +59 -0
- data/vendor/assets/components/uri.js/test/test_jim.js +143 -0
- data/vendor/assets/components/uri.js/test/test_jquery.js +138 -0
- data/vendor/assets/components/uri.js/test/test_template.js +385 -0
- data/vendor/assets/components/uri.js/test/urls.js +1236 -0
- data/vendor/assets/components/uri.js/uri-template.html +234 -0
- data/vendor/assets/components/uri.js/utils/SLDs.php +37 -0
- data/vendor/assets/components/uri.js/utils/sld.js +101 -0
- data/vendor/assets/components/veiljs/bower.json +36 -0
- data/vendor/assets/components/veiljs/veil-jquery.js +47 -0
- data/vendor/assets/components/veiljs/veil-knockout.js +55 -0
- data/vendor/assets/components/veiljs/veil.js +465 -0
- data/vendor/assets/javascripts/fuse.js +472 -0
- data/vendor/assets/javascripts/jquery-ui.js +3844 -0
- data/vendor/assets/javascripts/knockout-3.2.0-debug.js +5299 -0
- data/vendor/assets/javascripts/moment.js +1902 -0
- data/vendor/assets/javascripts/pikaday.js +896 -0
- data/vendor/assets/stylesheets/pikaday.css +171 -0
- metadata +120 -1
@@ -0,0 +1,1409 @@
|
|
1
|
+
(function(){
|
2
|
+
test("loaded", function() {
|
3
|
+
ok(window.URI);
|
4
|
+
});
|
5
|
+
|
6
|
+
module("constructing");
|
7
|
+
test("new URI(string)", function() {
|
8
|
+
var u = new URI("http://example.org/");
|
9
|
+
ok(u instanceof URI, "instanceof URI");
|
10
|
+
ok(u._parts.hostname !== undefined, "host undefined");
|
11
|
+
});
|
12
|
+
test("new URI(object)", function() {
|
13
|
+
var u = new URI({protocol: "http", hostname: 'example.org'});
|
14
|
+
ok(u instanceof URI, "instanceof URI");
|
15
|
+
ok(u._parts.hostname !== undefined, "host undefined");
|
16
|
+
});
|
17
|
+
test("new URI(Location)", function () {
|
18
|
+
var u = new URI(location);
|
19
|
+
equal(u.href(), String(location.href), "location object");
|
20
|
+
});
|
21
|
+
(function() {
|
22
|
+
var element;
|
23
|
+
|
24
|
+
for (var nodeName in URI.domAttributes) {
|
25
|
+
if (!Object.prototype.hasOwnProperty.call(URI.domAttributes, nodeName) || nodeName === 'input') {
|
26
|
+
continue;
|
27
|
+
}
|
28
|
+
|
29
|
+
element = document.createElement(nodeName);
|
30
|
+
testDomAttribute(element, URI.domAttributes[nodeName]);
|
31
|
+
}
|
32
|
+
|
33
|
+
element = document.createElement('input');
|
34
|
+
element.type = 'image';
|
35
|
+
testDomAttribute(element, 'src');
|
36
|
+
|
37
|
+
element = document.createElement('input');
|
38
|
+
testUnsupportedDomAttribute(element, 'src');
|
39
|
+
|
40
|
+
element = document.createElement('div');
|
41
|
+
testUnsupportedDomAttribute(element, 'src');
|
42
|
+
|
43
|
+
function testDomAttribute(element, attribute) {
|
44
|
+
test("new URI(Element " + element.nodeName + ")", function() {
|
45
|
+
element[attribute] = "http://example.org/foobar.html";
|
46
|
+
|
47
|
+
var u = new URI(element);
|
48
|
+
equal(u.scheme(), "http", "scheme");
|
49
|
+
equal(u.host(), "example.org", "host");
|
50
|
+
equal(u.path(), "/foobar.html", "path");
|
51
|
+
|
52
|
+
element[attribute] = "file:///C:/foo/bar.html";
|
53
|
+
u = new URI(element);
|
54
|
+
equal(u.href(), element[attribute], "file");
|
55
|
+
});
|
56
|
+
}
|
57
|
+
|
58
|
+
function testUnsupportedDomAttribute(element, attribute) {
|
59
|
+
test("new URI(unsupported Element " + element.nodeName + ")", function() {
|
60
|
+
element[attribute] = "http://example.org/foobar.html";
|
61
|
+
|
62
|
+
var u = new URI(element);
|
63
|
+
equal(u.scheme(), "", "scheme");
|
64
|
+
equal(u.host(), "", "host");
|
65
|
+
equal(u.path(), "", "path");
|
66
|
+
|
67
|
+
element[attribute] = "file:///C:/foo/bar.html";
|
68
|
+
u = new URI(element);
|
69
|
+
equal(u.href(), "", "file");
|
70
|
+
});
|
71
|
+
}
|
72
|
+
})();
|
73
|
+
test("new URI(URI)", function() {
|
74
|
+
var u = new URI(new URI({protocol: "http", hostname: 'example.org'}));
|
75
|
+
ok(u instanceof URI, "instanceof URI");
|
76
|
+
ok(u._parts.hostname !== undefined, "host undefined");
|
77
|
+
});
|
78
|
+
test("new URI(new Date())", function() {
|
79
|
+
raises(function() {
|
80
|
+
new URI(new Date());
|
81
|
+
}, TypeError, "Failing unknown input");
|
82
|
+
});
|
83
|
+
test("new URI()", function() {
|
84
|
+
var u = new URI();
|
85
|
+
ok(u instanceof URI, "instanceof URI");
|
86
|
+
ok(u._parts.hostname === location.hostname || u._parts.hostname === null && location.hostname === '',
|
87
|
+
"hostname == location.hostname");
|
88
|
+
});
|
89
|
+
test("function URI(string)", function() {
|
90
|
+
var u = new URI("http://example.org/");
|
91
|
+
ok(u instanceof URI, "instanceof URI");
|
92
|
+
ok(u._parts.hostname !== undefined, "host undefined");
|
93
|
+
});
|
94
|
+
test("new URI(string, string)", function() {
|
95
|
+
// see http://dvcs.w3.org/hg/url/raw-file/tip/Overview.html#constructor
|
96
|
+
var u = new URI("../foobar.html", "http://example.org/hello/world.html");
|
97
|
+
equal(u+"", "http://example.org/foobar.html", "resolve on construct");
|
98
|
+
});
|
99
|
+
|
100
|
+
module("parsing");
|
101
|
+
// [].forEach() no IE, lacking interest in polyfilling this...
|
102
|
+
for (var i = 0, t; t = urls[i]; i++) {
|
103
|
+
(function(t){
|
104
|
+
test("parse " + t.name, function() {
|
105
|
+
var u = new URI(t.url),
|
106
|
+
key;
|
107
|
+
|
108
|
+
// test URL built from parts
|
109
|
+
equal(u + "", t._url || t.url, "toString");
|
110
|
+
|
111
|
+
// test parsed parts
|
112
|
+
for (key in t.parts) {
|
113
|
+
if (Object.hasOwnProperty.call(t.parts, key)) {
|
114
|
+
equal(u._parts[key], t.parts[key], "part: " + key);
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
118
|
+
// test accessors
|
119
|
+
for (key in t.accessors) {
|
120
|
+
if (Object.hasOwnProperty.call(t.accessors, key)) {
|
121
|
+
equal(u[key](), t.accessors[key], "accessor: " + key);
|
122
|
+
}
|
123
|
+
}
|
124
|
+
|
125
|
+
// test is()
|
126
|
+
for (key in t.is) {
|
127
|
+
if (Object.hasOwnProperty.call(t.is, key)) {
|
128
|
+
equal(u.is(key), t.is[key], "is: " + key);
|
129
|
+
}
|
130
|
+
}
|
131
|
+
});
|
132
|
+
})(t);
|
133
|
+
};
|
134
|
+
|
135
|
+
module("mutating basics");
|
136
|
+
test("protocol", function() {
|
137
|
+
var u = new URI("http://example.org/foo.html");
|
138
|
+
u.protocol('ftp');
|
139
|
+
equal(u.protocol(), "ftp", "ftp protocol");
|
140
|
+
equal(u+"", "ftp://example.org/foo.html", "ftp url");
|
141
|
+
|
142
|
+
u.protocol('');
|
143
|
+
equal(u.protocol(), "", "relative protocol");
|
144
|
+
equal(u+"", "//example.org/foo.html", "relative-scheme url");
|
145
|
+
|
146
|
+
u.protocol(null);
|
147
|
+
equal(u.protocol(), "", "missing protocol");
|
148
|
+
equal(u+"", "//example.org/foo.html", "missing-scheme url");
|
149
|
+
});
|
150
|
+
test("username", function() {
|
151
|
+
var u = new URI("http://example.org/foo.html");
|
152
|
+
u.username("hello");
|
153
|
+
equal(u.username(), "hello", "changed username hello");
|
154
|
+
equal(u.password(), "", "changed passowrd hello");
|
155
|
+
equal(u+"", "http://hello@example.org/foo.html", "changed url hello");
|
156
|
+
|
157
|
+
u.username("");
|
158
|
+
equal(u.username(), "", "changed username ''");
|
159
|
+
equal(u.password(), "", "changed passowrd ''");
|
160
|
+
equal(u+"", "http://example.org/foo.html", "changed url ''");
|
161
|
+
});
|
162
|
+
test("password", function() {
|
163
|
+
var u = new URI("http://hello@example.org/foo.html");
|
164
|
+
u.password("world");
|
165
|
+
equal(u.username(), "hello", "changed username world");
|
166
|
+
equal(u.password(), "world", "changed passowrd world");
|
167
|
+
equal(u+"", "http://hello:world@example.org/foo.html", "changed url world");
|
168
|
+
|
169
|
+
u.password("");
|
170
|
+
equal(u.username(), "hello", "changed username ''");
|
171
|
+
equal(u.password(), "", "changed passowrd ''");
|
172
|
+
equal(u+"", "http://hello@example.org/foo.html", "changed url ''");
|
173
|
+
|
174
|
+
u.username("").password("hahaha");
|
175
|
+
equal(u.username(), "", "changed username - password without username");
|
176
|
+
equal(u.password(), "hahaha", "changed passowrd - password without username");
|
177
|
+
equal(u+"", "http://example.org/foo.html", "changed url - password without username");
|
178
|
+
});
|
179
|
+
test("hostname", function() {
|
180
|
+
var u = new URI("http://example.org/foo.html");
|
181
|
+
u.hostname('abc.foobar.lala');
|
182
|
+
equal(u.hostname(), "abc.foobar.lala", "hostname changed");
|
183
|
+
equal(u+"", "http://abc.foobar.lala/foo.html", "hostname changed url");
|
184
|
+
|
185
|
+
u.hostname('');
|
186
|
+
equal(u.hostname(), "", "hostname removed");
|
187
|
+
equal(u+"", "http:///foo.html", "hostname removed url");
|
188
|
+
});
|
189
|
+
test("port", function() {
|
190
|
+
var u = new URI("http://example.org/foo.html");
|
191
|
+
u.port('80');
|
192
|
+
equal(u.port(), "80", "changing port 80");
|
193
|
+
equal(u+"", "http://example.org:80/foo.html", "changing url 80");
|
194
|
+
|
195
|
+
u.port('');
|
196
|
+
equal(u.port(), "", "changing port ''");
|
197
|
+
equal(u+"", "http://example.org/foo.html", "changing url ''");
|
198
|
+
});
|
199
|
+
test("path", function() {
|
200
|
+
var u = new URI("http://example.org/foobar.html?query=string");
|
201
|
+
u.pathname('/some/path/file.suffix');
|
202
|
+
equal(u.pathname(), '/some/path/file.suffix', "changing pathname '/some/path/file.suffix'");
|
203
|
+
equal(u+"", "http://example.org/some/path/file.suffix?query=string", "changing url '/some/path/file.suffix'");
|
204
|
+
|
205
|
+
u.pathname('');
|
206
|
+
equal(u.pathname(), '/', "changing pathname ''");
|
207
|
+
equal(u+"", "http://example.org/?query=string", "changing url ''");
|
208
|
+
|
209
|
+
u.pathname('/~userhome/@mine;is %2F and/');
|
210
|
+
equal(u.pathname(), '/~userhome/@mine;is%20%2F%20and/', "path encoding");
|
211
|
+
equal(u.pathname(true), '/~userhome/@mine;is %2F and/', "path decoded");
|
212
|
+
|
213
|
+
u = new URI('/a/b/c/').relativeTo('/a/b/c/');
|
214
|
+
equal(u.pathname(), '', "empty relative path");
|
215
|
+
equal(u.toString(), '', "empty relative path to string");
|
216
|
+
|
217
|
+
u.pathname('/');
|
218
|
+
equal(u.pathname(), '/', "empty absolute path");
|
219
|
+
equal(u.toString(), '/', "empty absolute path to string");
|
220
|
+
});
|
221
|
+
test("query", function() {
|
222
|
+
var u = new URI("http://example.org/foo.html");
|
223
|
+
u.query('foo=bar=foo');
|
224
|
+
equal(u.query(), "foo=bar=foo", "query: foo=bar=foo");
|
225
|
+
equal(u.search(), "?foo=bar=foo", "query: foo=bar=foo - search");
|
226
|
+
|
227
|
+
u.query('?bar=foo');
|
228
|
+
equal(u.query(), "bar=foo", "query: ?bar=foo");
|
229
|
+
equal(u.search(), "?bar=foo", "query: ?bar=foo - search");
|
230
|
+
|
231
|
+
u.query('');
|
232
|
+
equal(u.query(), "", "query: ''");
|
233
|
+
equal(u.search(), "", "query: '' - search");
|
234
|
+
equal(u.toString(), "http://example.org/foo.html");
|
235
|
+
|
236
|
+
u.search('foo=bar=foo');
|
237
|
+
equal(u.query(), "foo=bar=foo", "search: foo=bar=foo");
|
238
|
+
equal(u.search(), "?foo=bar=foo", "search: foo=bar=foo - query");
|
239
|
+
|
240
|
+
u.search('?bar=foo');
|
241
|
+
equal(u.query(), "bar=foo", "search: ?bar=foo");
|
242
|
+
equal(u.search(), "?bar=foo", "search: ?bar=foo - query");
|
243
|
+
|
244
|
+
u.search('');
|
245
|
+
equal(u.query(), "", "search: ''");
|
246
|
+
equal(u.search(), "", "search: '' - query");
|
247
|
+
|
248
|
+
u.query('?foo');
|
249
|
+
equal(u.query(), "foo", "search: ''");
|
250
|
+
equal(u.search(), "?foo", "search: '' - query");
|
251
|
+
|
252
|
+
// parsing empty query
|
253
|
+
var t;
|
254
|
+
t = u.query('?').query(true);
|
255
|
+
t = u.query('').query(true);
|
256
|
+
t = u.href("http://example.org").query(true);
|
257
|
+
});
|
258
|
+
test("fragment", function() {
|
259
|
+
var u = new URI("http://example.org/foo.html");
|
260
|
+
u.fragment('foo');
|
261
|
+
equal(u.fragment(), "foo", "fragment: foo");
|
262
|
+
equal(u.hash(), "#foo", "fragment: foo - hash");
|
263
|
+
|
264
|
+
u.fragment('#bar');
|
265
|
+
equal(u.fragment(), "bar", "fragment: #bar");
|
266
|
+
equal(u.hash(), "#bar", "fragment: #bar - hash");
|
267
|
+
|
268
|
+
u.fragment('');
|
269
|
+
equal(u.fragment(), "", "fragment: ''");
|
270
|
+
equal(u.hash(), "", "fragment: '' - hash");
|
271
|
+
equal(u.toString(), "http://example.org/foo.html");
|
272
|
+
|
273
|
+
u.hash('foo');
|
274
|
+
equal(u.fragment(), "foo", "hash: foo");
|
275
|
+
equal(u.hash(), "#foo", "hash: foo - fragment");
|
276
|
+
|
277
|
+
u.hash('#bar');
|
278
|
+
equal(u.fragment(), "bar", "hash: #bar");
|
279
|
+
equal(u.hash(), "#bar", "hash: #bar - fragment");
|
280
|
+
|
281
|
+
u.hash('');
|
282
|
+
equal(u.fragment(), "", "hash: ''");
|
283
|
+
equal(u.hash(), "", "hash: '' - fragment");
|
284
|
+
});
|
285
|
+
|
286
|
+
module("mutating compounds");
|
287
|
+
test("host", function() {
|
288
|
+
var u = new URI("http://foo.bar/foo.html");
|
289
|
+
|
290
|
+
u.host('example.org:80');
|
291
|
+
equal(u.hostname(), "example.org", "host changed hostname");
|
292
|
+
equal(u.port(), "80", "host changed port");
|
293
|
+
equal(u+"", "http://example.org:80/foo.html", "host changed url");
|
294
|
+
|
295
|
+
u.host('some-domain.com');
|
296
|
+
equal(u.hostname(), "some-domain.com", "host modified hostname");
|
297
|
+
equal(u.port(), "", "host removed port");
|
298
|
+
equal(u+"", "http://some-domain.com/foo.html", "host modified url");
|
299
|
+
});
|
300
|
+
test("authority", function() {
|
301
|
+
var u = new URI("http://foo.bar/foo.html");
|
302
|
+
|
303
|
+
u.authority('username:password@example.org:80');
|
304
|
+
equal(u.username(), "username", "authority changed username");
|
305
|
+
equal(u.password(), "password", "authority changed password");
|
306
|
+
equal(u.hostname(), "example.org", "authority changed hostname");
|
307
|
+
equal(u.port(), "80", "authority changed port");
|
308
|
+
equal(u+"", "http://username:password@example.org:80/foo.html", "authority changed url");
|
309
|
+
|
310
|
+
u.authority('some-domain.com');
|
311
|
+
equal(u.username(), "", "authority removed username");
|
312
|
+
equal(u.password(), "", "authority removed password");
|
313
|
+
equal(u.hostname(), "some-domain.com", "authority modified hostname");
|
314
|
+
equal(u.port(), "", "authority removed port");
|
315
|
+
equal(u+"", "http://some-domain.com/foo.html", "authority modified url");
|
316
|
+
});
|
317
|
+
test("userinfo", function() {
|
318
|
+
var u = new URI("http://foo.bar/foo.html");
|
319
|
+
|
320
|
+
u.userinfo('username:password');
|
321
|
+
equal(u.username(), "username", "userinfo changed username-only");
|
322
|
+
equal(u.password(), "password", "userinfo changed password");
|
323
|
+
equal(u+"", "http://username:password@foo.bar/foo.html", "userinfo changed url");
|
324
|
+
|
325
|
+
u.userinfo('walter');
|
326
|
+
equal(u.username(), "walter", "userinfo removed password");
|
327
|
+
equal(u.password(), "", "userinfo removed password");
|
328
|
+
equal(u+"", "http://walter@foo.bar/foo.html", "userinfo changed url");
|
329
|
+
|
330
|
+
u.userinfo('');
|
331
|
+
equal(u.username(), "", "userinfo removed username");
|
332
|
+
equal(u.password(), "", "userinfo removed password");
|
333
|
+
equal(u+"", "http://foo.bar/foo.html", "userinfo changed url");
|
334
|
+
});
|
335
|
+
test("href", function() {
|
336
|
+
var u = new URI("http://foo.bar/foo.html");
|
337
|
+
|
338
|
+
u.href('ftp://u:p@example.org:123/directory/file.suffix?query=string#fragment');
|
339
|
+
equal(u.protocol(), "ftp", "href changed protocol");
|
340
|
+
equal(u.username(), "u", "href changed username");
|
341
|
+
equal(u.password(), "p", "href changed password");
|
342
|
+
equal(u.hostname(), "example.org", "href changed hostname");
|
343
|
+
equal(u.port(), "123", "href changed port");
|
344
|
+
equal(u.pathname(), "/directory/file.suffix", "href changed pathname");
|
345
|
+
equal(u.search(), "?query=string", "href changed search");
|
346
|
+
equal(u.hash(), "#fragment", "href changed hash");
|
347
|
+
equal(u.href(), 'ftp://u:p@example.org:123/directory/file.suffix?query=string#fragment', "href removed url");
|
348
|
+
|
349
|
+
u.href('../path/index.html');
|
350
|
+
equal(u.protocol(), "", "href removed protocol");
|
351
|
+
equal(u.username(), "", "href removed username");
|
352
|
+
equal(u.password(), "", "href removed password");
|
353
|
+
equal(u.hostname(), "", "href removed hostname");
|
354
|
+
equal(u.port(), "", "href removed port");
|
355
|
+
equal(u.pathname(), "../path/index.html", "href removed pathname");
|
356
|
+
equal(u.search(), "", "href removed search");
|
357
|
+
equal(u.hash(), "", "href removed hash");
|
358
|
+
equal(u.href(), '../path/index.html', "href removed url");
|
359
|
+
});
|
360
|
+
test("resource", function() {
|
361
|
+
var u = new URI("http://foo.bar/foo.html?hello#world");
|
362
|
+
|
363
|
+
equal(u.resource(), "/foo.html?hello#world", "get resource");
|
364
|
+
|
365
|
+
u.resource("/foo.html?hello#world");
|
366
|
+
equal(u.href(), "http://foo.bar/foo.html?hello#world", "set resource");
|
367
|
+
|
368
|
+
u.resource("/world.html");
|
369
|
+
equal(u.href(), "http://foo.bar/world.html", "set resource path");
|
370
|
+
equal(u.resource(), "/world.html", "get resource path");
|
371
|
+
|
372
|
+
u.resource("?query");
|
373
|
+
equal(u.href(), "http://foo.bar/?query", "set resource query");
|
374
|
+
equal(u.resource(), "/?query", "get resource query");
|
375
|
+
|
376
|
+
u.resource("#fragment");
|
377
|
+
equal(u.href(), "http://foo.bar/#fragment", "set resource fragment");
|
378
|
+
equal(u.resource(), "/#fragment", "get resource fragment");
|
379
|
+
|
380
|
+
u.resource("?hello#world");
|
381
|
+
equal(u.href(), "http://foo.bar/?hello#world", "set resource query+fragment");
|
382
|
+
equal(u.resource(), "/?hello#world", "get resource query+fragment");
|
383
|
+
|
384
|
+
u.resource("/mars.txt?planet=123");
|
385
|
+
equal(u.href(), "http://foo.bar/mars.txt?planet=123", "set resource path+query");
|
386
|
+
equal(u.resource(), "/mars.txt?planet=123", "get resource path+query");
|
387
|
+
|
388
|
+
u.resource("/neptune.txt#foo");
|
389
|
+
equal(u.href(), "http://foo.bar/neptune.txt#foo", "set resource path+fragment");
|
390
|
+
equal(u.resource(), "/neptune.txt#foo", "get resource path+fragment");
|
391
|
+
});
|
392
|
+
|
393
|
+
module("mutating fractions");
|
394
|
+
test("subdomain", function() {
|
395
|
+
var u = new URI("http://www.example.org/foo.html");
|
396
|
+
u.subdomain("foo.bar");
|
397
|
+
equal(u.hostname(), "foo.bar.example.org", "changed subdomain foo.bar");
|
398
|
+
equal(u+"", "http://foo.bar.example.org/foo.html", "changed url foo.bar");
|
399
|
+
|
400
|
+
u.subdomain("");
|
401
|
+
equal(u.hostname(), "example.org", "changed subdomain ''");
|
402
|
+
equal(u+"", "http://example.org/foo.html", "changed url ''");
|
403
|
+
|
404
|
+
u.subdomain("foo.");
|
405
|
+
equal(u.hostname(), "foo.example.org", "changed subdomain foo.");
|
406
|
+
equal(u+"", "http://foo.example.org/foo.html", "changed url foo.");
|
407
|
+
|
408
|
+
});
|
409
|
+
test("domain", function() {
|
410
|
+
var u = new URI("http://www.example.org/foo.html");
|
411
|
+
u.domain("foo.bar");
|
412
|
+
equal(u.hostname(), "www.foo.bar", "changed hostname foo.bar");
|
413
|
+
equal(u+"", "http://www.foo.bar/foo.html", "changed url foo.bar");
|
414
|
+
|
415
|
+
raises(function() {
|
416
|
+
u.domain("");
|
417
|
+
}, TypeError, "Failing empty input");
|
418
|
+
|
419
|
+
u.hostname("www.example.co.uk");
|
420
|
+
equal(u.domain(), "example.co.uk", "domain after changed hostname www.example.co.uk");
|
421
|
+
equal(u+"", "http://www.example.co.uk/foo.html", "url after changed hostname www.example.co.uk");
|
422
|
+
equal(u.domain(true), "co.uk", "domain after changed hostname www.example.co.uk (TLD of SLD)");
|
423
|
+
|
424
|
+
u.domain('example.org');
|
425
|
+
equal(u.domain(), "example.org", "domain after changed domain example.org");
|
426
|
+
equal(u+"", "http://www.example.org/foo.html", "url after changed domain example.org");
|
427
|
+
|
428
|
+
u.domain('example.co.uk');
|
429
|
+
equal(u.domain(), "example.co.uk", "domain after changed domain example.co.uk");
|
430
|
+
equal(u+"", "http://www.example.co.uk/foo.html", "url after changed domain example.co.uk");
|
431
|
+
|
432
|
+
u.href('http://test/');
|
433
|
+
equal(u.domain(), "test", "domain (dot-less)");
|
434
|
+
equal(u.subdomain(), "", "subdomain (dot-less)");
|
435
|
+
|
436
|
+
u.subdomain('foo');
|
437
|
+
equal(u.href(), "http://foo.test/", "subdomain set on (dot-less)");
|
438
|
+
});
|
439
|
+
test("tld", function() {
|
440
|
+
var u = new URI("http://www.example.org/foo.html");
|
441
|
+
u.tld("mine");
|
442
|
+
equal(u.tld(), "mine", "tld changed");
|
443
|
+
equal(u+"", "http://www.example.mine/foo.html", "changed url mine");
|
444
|
+
|
445
|
+
raises(function() {
|
446
|
+
u.tld("");
|
447
|
+
}, TypeError, "Failing empty input");
|
448
|
+
|
449
|
+
raises(function() {
|
450
|
+
u.tld("foo.bar");
|
451
|
+
}, TypeError, "Failing 'foo.bar'");
|
452
|
+
|
453
|
+
u.tld('co.uk');
|
454
|
+
equal(u.tld(), "co.uk", "tld changed to sld");
|
455
|
+
equal(u+"", "http://www.example.co.uk/foo.html", "changed url to sld");
|
456
|
+
equal(u.tld(true), "uk", "TLD of SLD");
|
457
|
+
|
458
|
+
u.tld('org');
|
459
|
+
equal(u.tld(), "org", "sld changed to tld");
|
460
|
+
equal(u+"", "http://www.example.org/foo.html", "changed url to tld");
|
461
|
+
|
462
|
+
u.hostname('www.examplet.se');
|
463
|
+
equal(u.tld(), "se", "se tld");
|
464
|
+
|
465
|
+
});
|
466
|
+
test("directory", function() {
|
467
|
+
var u = new URI("http://www.example.org/some/directory/foo.html");
|
468
|
+
u.directory("/");
|
469
|
+
equal(u.path(), "/foo.html", "changed path '/'");
|
470
|
+
equal(u+"", "http://www.example.org/foo.html", "changed url '/'");
|
471
|
+
|
472
|
+
u.directory("");
|
473
|
+
equal(u.path(), "/foo.html", "changed path ''");
|
474
|
+
equal(u+"", "http://www.example.org/foo.html", "changed url ''");
|
475
|
+
|
476
|
+
u.directory("/bar");
|
477
|
+
equal(u.path(), "/bar/foo.html", "changed path '/bar'");
|
478
|
+
equal(u+"", "http://www.example.org/bar/foo.html", "changed url '/bar'");
|
479
|
+
|
480
|
+
u.directory("baz");
|
481
|
+
equal(u.path(), "/baz/foo.html", "changed path 'baz'");
|
482
|
+
equal(u+"", "http://www.example.org/baz/foo.html", "changed url 'baz'");
|
483
|
+
|
484
|
+
// relative paths
|
485
|
+
u = new URI("../some/directory/foo.html");
|
486
|
+
u.directory("../other/");
|
487
|
+
equal(u.path(), "../other/foo.html", "changed path '../other/'");
|
488
|
+
equal(u+"", "../other/foo.html", "changed url '../other/'");
|
489
|
+
|
490
|
+
u.directory("mine");
|
491
|
+
equal(u.path(), "mine/foo.html", "changed path 'mine'");
|
492
|
+
equal(u+"", "mine/foo.html", "changed url 'mine'");
|
493
|
+
|
494
|
+
u.directory("/");
|
495
|
+
equal(u.path(), "/foo.html", "changed path '/'");
|
496
|
+
equal(u+"", "/foo.html", "changed url '/'");
|
497
|
+
|
498
|
+
u.directory("");
|
499
|
+
equal(u.path(), "foo.html", "changed path ''");
|
500
|
+
equal(u+"", "foo.html", "changed url ''");
|
501
|
+
|
502
|
+
u.directory("../blubb");
|
503
|
+
equal(u.path(), "../blubb/foo.html", "changed path '../blubb'");
|
504
|
+
equal(u+"", "../blubb/foo.html", "changed url '../blubb'");
|
505
|
+
|
506
|
+
// encoding
|
507
|
+
u.path("/some/directory/foo.html");
|
508
|
+
u.directory('/~userhome/@mine;is %2F and/');
|
509
|
+
equal(u.path(), '/~userhome/@mine;is%20%2F%20and/foo.html', "directory encoding");
|
510
|
+
equal(u.directory(true), '/~userhome/@mine;is %2F and', "directory decoded");
|
511
|
+
});
|
512
|
+
test("filename", function() {
|
513
|
+
var u = new URI("http://www.example.org/some/directory/foo.html");
|
514
|
+
u.filename("hello.world");
|
515
|
+
equal(u.path(), "/some/directory/hello.world", "changed path 'hello.world'");
|
516
|
+
equal(u+"", "http://www.example.org/some/directory/hello.world", "changed url 'hello.world'");
|
517
|
+
|
518
|
+
u.filename("hello");
|
519
|
+
equal(u.path(), "/some/directory/hello", "changed path 'hello'");
|
520
|
+
equal(u+"", "http://www.example.org/some/directory/hello", "changed url 'hello'");
|
521
|
+
|
522
|
+
u.filename("");
|
523
|
+
equal(u.path(), "/some/directory/", "changed path ''");
|
524
|
+
equal(u+"", "http://www.example.org/some/directory/", "changed url ''");
|
525
|
+
|
526
|
+
u.filename("world");
|
527
|
+
equal(u.path(), "/some/directory/world", "changed path 'world'");
|
528
|
+
equal(u+"", "http://www.example.org/some/directory/world", "changed url 'world'");
|
529
|
+
|
530
|
+
// encoding
|
531
|
+
u.path("/some/directory/foo.html");
|
532
|
+
u.filename('hällo wörld.html');
|
533
|
+
equal(u.path(), '/some/directory/h%C3%A4llo%20w%C3%B6rld.html', "filename encoding");
|
534
|
+
equal(u.filename(true), 'hällo wörld.html', "filename decoded");
|
535
|
+
});
|
536
|
+
test("suffix", function() {
|
537
|
+
var u = new URI("http://www.example.org/some/directory/foo.html");
|
538
|
+
u.suffix("xml");
|
539
|
+
equal(u.path(), "/some/directory/foo.xml", "changed path 'xml'");
|
540
|
+
equal(u+"", "http://www.example.org/some/directory/foo.xml", "changed url 'xml'");
|
541
|
+
|
542
|
+
u.suffix("");
|
543
|
+
equal(u.path(), "/some/directory/foo", "changed path ''");
|
544
|
+
equal(u+"", "http://www.example.org/some/directory/foo", "changed url ''");
|
545
|
+
|
546
|
+
u.suffix("html");
|
547
|
+
equal(u.path(), "/some/directory/foo.html", "changed path 'html'");
|
548
|
+
equal(u+"", "http://www.example.org/some/directory/foo.html", "changed url 'html'");
|
549
|
+
|
550
|
+
// encoding
|
551
|
+
u.suffix('cört');
|
552
|
+
equal(u.path(), '/some/directory/foo.c%C3%B6rt', "suffix encoding");
|
553
|
+
equal(u.suffix(), 'c%C3%B6rt', "suffix encoded"); // suffix is expected to be alnum!
|
554
|
+
equal(u.suffix(true), 'cört', "suffix decoded"); // suffix is expected to be alnum!
|
555
|
+
});
|
556
|
+
test("segment", function() {
|
557
|
+
var u = new URI("http://www.example.org/some/directory/foo.html"),
|
558
|
+
s = u.segment();
|
559
|
+
|
560
|
+
equal(s.join('||'), "some||directory||foo.html", "segment get array");
|
561
|
+
|
562
|
+
u.segment(['hello', 'world', 'foo.html']);
|
563
|
+
equal(u.path(), "/hello/world/foo.html", "segment set array");
|
564
|
+
|
565
|
+
equal(u.segment(0), "hello", "segment get 0");
|
566
|
+
equal(u.segment(2), "foo.html", "segment get 2");
|
567
|
+
equal(u.segment(3), undefined, "segment get 3");
|
568
|
+
|
569
|
+
u.segment(0, "goodbye");
|
570
|
+
equal(u.path(), "/goodbye/world/foo.html", "segment set 0");
|
571
|
+
u.segment(2, "bar.html");
|
572
|
+
equal(u.path(), "/goodbye/world/bar.html", "segment set 2");
|
573
|
+
u.segment(3, "zupp");
|
574
|
+
equal(u.path(), "/goodbye/world/bar.html/zupp", "segment set 3");
|
575
|
+
u.segment("zapp");
|
576
|
+
equal(u.path(), "/goodbye/world/bar.html/zupp/zapp", "segment append");
|
577
|
+
|
578
|
+
u.segment(3, "");
|
579
|
+
equal(u.path(), "/goodbye/world/bar.html/zapp", "segment del 3 ''");
|
580
|
+
u.segment(3, null);
|
581
|
+
equal(u.path(), "/goodbye/world/bar.html", "segment del 3 null");
|
582
|
+
|
583
|
+
u = new URI("http://www.example.org/some/directory/foo.html");
|
584
|
+
equal(u.segment(-1), "foo.html", "segment get -1");
|
585
|
+
u.segment(-1, "world.html");
|
586
|
+
equal(u.path(), "/some/directory/world.html", "segment set -1");
|
587
|
+
|
588
|
+
u = new URI("someurn:foo:bar:baz");
|
589
|
+
equal(u.segment().join('||'), "foo||bar||baz", "segment get array URN");
|
590
|
+
u.segment(1, 'mars');
|
591
|
+
equal(u.path(), "foo:mars:baz", "segment set 1 URN");
|
592
|
+
equal(u.toString(), "someurn:foo:mars:baz", "segment set 1 URN");
|
593
|
+
|
594
|
+
u = new URI('/foo/');
|
595
|
+
equal(u.segment().join('||'), "foo||", "segment get array trailing empty");
|
596
|
+
|
597
|
+
u.segment('test');
|
598
|
+
equal(u.path(), "/foo/test", "segment append trailing empty");
|
599
|
+
|
600
|
+
u.segment('');
|
601
|
+
equal(u.path(), "/foo/test/", "segment append empty trailing");
|
602
|
+
u.segment('');
|
603
|
+
equal(u.path(), "/foo/test/", "segment append empty trailing unchanged");
|
604
|
+
|
605
|
+
u.segment(['', '', 'foo', '', '', 'bar', '', '']);
|
606
|
+
equal(u.path(), "/foo/bar/", "segment collapsing empty parts");
|
607
|
+
});
|
608
|
+
test("segmentCoded", function() {
|
609
|
+
var u = new URI("http://www.example.org/some%20thing/directory/foo.html"),
|
610
|
+
s = u.segmentCoded();
|
611
|
+
|
612
|
+
equal(s.join('||'), "some thing||directory||foo.html", "segmentCoded get array");
|
613
|
+
|
614
|
+
u.segmentCoded(['hello world', 'mars', 'foo.html']);
|
615
|
+
equal(u.path(), "/hello%20world/mars/foo.html", "segmentCoded set array");
|
616
|
+
|
617
|
+
equal(u.segmentCoded(0), "hello world", "segmentCoded get 0");
|
618
|
+
equal(u.segmentCoded(2), "foo.html", "segmentCoded get 2");
|
619
|
+
equal(u.segmentCoded(3), undefined, "segmentCoded get 3");
|
620
|
+
|
621
|
+
u.segmentCoded("zapp zerapp");
|
622
|
+
equal(u.path(), "/hello%20world/mars/foo.html/zapp%20zerapp", "segmentCoded append");
|
623
|
+
|
624
|
+
u.segmentCoded(2, "");
|
625
|
+
equal(u.path(), "/hello%20world/mars/zapp%20zerapp", "segmentCoded del 3 ''");
|
626
|
+
u.segmentCoded(2, null);
|
627
|
+
equal(u.path(), "/hello%20world/mars", "segmentCoded del 3 null");
|
628
|
+
|
629
|
+
u.segmentCoded('');
|
630
|
+
equal(u.path(), "/hello%20world/mars/", "segmentCoded append empty trailing");
|
631
|
+
u.segmentCoded('');
|
632
|
+
equal(u.path(), "/hello%20world/mars/", "segmentCoded append empty trailing unchanged");
|
633
|
+
});
|
634
|
+
|
635
|
+
module("mutating query strings");
|
636
|
+
test("mutating object", function() {
|
637
|
+
var u = new URI('?foo=bar&baz=bam&baz=bau'),
|
638
|
+
q = u.query(true);
|
639
|
+
|
640
|
+
q.something = ['new', 'and', 'funky'];
|
641
|
+
u.query(q);
|
642
|
+
equal(u.query(), 'foo=bar&baz=bam&baz=bau&something=new&something=and&something=funky', "adding array");
|
643
|
+
|
644
|
+
q.foo = undefined;
|
645
|
+
u.query(q);
|
646
|
+
equal(u.query(), 'baz=bam&baz=bau&something=new&something=and&something=funky', "removing field");
|
647
|
+
|
648
|
+
q.baz = undefined;
|
649
|
+
u.query(q);
|
650
|
+
equal(u.query(), 'something=new&something=and&something=funky', "removing array");
|
651
|
+
});
|
652
|
+
test("query callback", function() {
|
653
|
+
var u = URI('?foo=bar');
|
654
|
+
u.query(function(data) {
|
655
|
+
data.foo = "bam";
|
656
|
+
});
|
657
|
+
equal(u.query(), 'foo=bam', "augment argument");
|
658
|
+
|
659
|
+
u.query(function(data) {
|
660
|
+
return {
|
661
|
+
bla: 'blubb'
|
662
|
+
};
|
663
|
+
});
|
664
|
+
equal(u.query(), 'bla=blubb', "overwrite returned value");
|
665
|
+
});
|
666
|
+
test("setQuery", function() {
|
667
|
+
var u = URI('?foo=bar');
|
668
|
+
u.setQuery('foo', 'bam');
|
669
|
+
equal(u.query(), 'foo=bam', "set name, value");
|
670
|
+
|
671
|
+
u.setQuery('array', ['one', 'two']);
|
672
|
+
equal(u.query(), 'foo=bam&array=one&array=two', "set name, array");
|
673
|
+
|
674
|
+
u.query('?foo=bar');
|
675
|
+
u.setQuery({'obj': 'bam', foo: "baz"});
|
676
|
+
equal(u.query(), 'foo=baz&obj=bam', "set {name: value}");
|
677
|
+
|
678
|
+
u.setQuery({'foo': 'foo', bar: ['1', '2']});
|
679
|
+
equal(u.query(), 'foo=foo&obj=bam&bar=1&bar=2', "set {name: array}");
|
680
|
+
|
681
|
+
u.query('?foo=bar');
|
682
|
+
u.setQuery({'bam': null, 'baz': ''});
|
683
|
+
equal(u.query(), 'foo=bar&bam&baz=', "set {name: null}");
|
684
|
+
|
685
|
+
u.query('?foo=bar');
|
686
|
+
u.setQuery('empty');
|
687
|
+
equal(u.query(), 'foo=bar&empty', "set undefined");
|
688
|
+
|
689
|
+
u.query('?foo=bar');
|
690
|
+
u.setQuery('empty', "");
|
691
|
+
equal(u.query(), 'foo=bar&empty=', "set empty string");
|
692
|
+
|
693
|
+
u.query('');
|
694
|
+
u.setQuery('some value', "must be encoded because of = and ? and #");
|
695
|
+
equal(u.query(), 'some+value=must+be+encoded+because+of+%3D+and+%3F+and+%23', "encoding");
|
696
|
+
equal(u.query(true)['some value'], "must be encoded because of = and ? and #", "decoding");
|
697
|
+
});
|
698
|
+
test("addQuery", function() {
|
699
|
+
var u = URI('?foo=bar');
|
700
|
+
u.addQuery('baz', 'bam');
|
701
|
+
equal(u.query(), 'foo=bar&baz=bam', "add name, value");
|
702
|
+
|
703
|
+
u.addQuery('array', ['one', 'two']);
|
704
|
+
equal(u.query(), 'foo=bar&baz=bam&array=one&array=two', "add name, array");
|
705
|
+
|
706
|
+
u.query('?foo=bar');
|
707
|
+
u.addQuery({'obj': 'bam', foo: "baz"});
|
708
|
+
equal(u.query(), 'foo=bar&foo=baz&obj=bam', "add {name: value}");
|
709
|
+
|
710
|
+
u.addQuery({'foo': 'bam', bar: ['1', '2']});
|
711
|
+
equal(u.query(), 'foo=bar&foo=baz&foo=bam&obj=bam&bar=1&bar=2', "add {name: array}");
|
712
|
+
|
713
|
+
u.query('?foo=bar');
|
714
|
+
u.addQuery({'bam': null, 'baz': ''});
|
715
|
+
equal(u.query(), 'foo=bar&bam&baz=', "add {name: null}");
|
716
|
+
|
717
|
+
u.query('?foo=bar');
|
718
|
+
u.addQuery('empty');
|
719
|
+
equal(u.query(), 'foo=bar&empty', "add undefined");
|
720
|
+
|
721
|
+
u.query('?foo=bar');
|
722
|
+
u.addQuery('empty', "");
|
723
|
+
equal(u.query(), 'foo=bar&empty=', "add empty string");
|
724
|
+
|
725
|
+
u.query('');
|
726
|
+
u.addQuery('some value', "must be encoded because of = and ? and #");
|
727
|
+
equal(u.query(), 'some+value=must+be+encoded+because+of+%3D+and+%3F+and+%23', "encoding");
|
728
|
+
equal(u.query(true)['some value'], "must be encoded because of = and ? and #", "decoding");
|
729
|
+
});
|
730
|
+
test("removeQuery", function() {
|
731
|
+
var u = new URI('?foo=bar&foo=baz&foo=bam&obj=bam&bar=1&bar=2&bar=3');
|
732
|
+
|
733
|
+
u.removeQuery('foo', 'bar');
|
734
|
+
equal(u.query(), 'foo=baz&foo=bam&obj=bam&bar=1&bar=2&bar=3', 'removing name, value');
|
735
|
+
|
736
|
+
u.removeQuery('foo');
|
737
|
+
equal(u.query(), 'obj=bam&bar=1&bar=2&bar=3', 'removing name');
|
738
|
+
|
739
|
+
u.removeQuery('bar', ['1', '3']);
|
740
|
+
equal(u.query(), 'obj=bam&bar=2', 'removing name, array');
|
741
|
+
|
742
|
+
u.query('?foo=bar&foo=baz&foo=bam&obj=bam&bar=1&bar=2&bar=3');
|
743
|
+
u.removeQuery(['foo', 'bar']);
|
744
|
+
equal(u.query(), 'obj=bam', 'removing array');
|
745
|
+
|
746
|
+
u.query('?foo=bar&foo=baz&foo=bam&obj=bam&bar=1&bar=2&bar=3');
|
747
|
+
u.removeQuery({foo: 'bar', obj: undefined, bar: ["1", "2"]});
|
748
|
+
equal(u.query(), 'foo=baz&foo=bam&bar=3', 'removing object');
|
749
|
+
});
|
750
|
+
test("duplicateQueryParameters", function() {
|
751
|
+
var u = new URI('?bar=1&bar=1&bar=1');
|
752
|
+
|
753
|
+
u.normalizeQuery();
|
754
|
+
equal(u.toString(), '?bar=1', "parameters de-duplicated");
|
755
|
+
|
756
|
+
u = new URI('?bar=1&bar=1&bar=1');
|
757
|
+
u.duplicateQueryParameters(true);
|
758
|
+
ok(u._parts.duplicateQueryParameters, "duplicateQueryParameters enabled");
|
759
|
+
u.normalizeQuery();
|
760
|
+
equal(u.toString(), '?bar=1&bar=1&bar=1', "parameters NOT de-duplicated");
|
761
|
+
ok(u._parts.duplicateQueryParameters, "duplicateQueryParameters still enabled after normalizeQuery()");
|
762
|
+
|
763
|
+
u.duplicateQueryParameters(false);
|
764
|
+
u.normalizeQuery();
|
765
|
+
equal(u.toString(), '?bar=1', "parameters de-duplicated again");
|
766
|
+
ok(!u._parts.duplicateQueryParameters, "duplicateQueryParameters still disabled after normalizeQuery()");
|
767
|
+
|
768
|
+
URI.duplicateQueryParameters = true;
|
769
|
+
u = new URI('?bar=1&bar=1&bar=1');
|
770
|
+
u.normalizeQuery();
|
771
|
+
equal(u.toString(), '?bar=1&bar=1&bar=1', "global configuration");
|
772
|
+
|
773
|
+
URI.duplicateQueryParameters = false;
|
774
|
+
|
775
|
+
// test cloning
|
776
|
+
u = new URI('?bar=1&bar=1&bar=1');
|
777
|
+
u = u.duplicateQueryParameters(true).clone();
|
778
|
+
ok(u._parts.duplicateQueryParameters, "duplicateQueryParameters still enabled after clone()");
|
779
|
+
u.normalizeQuery();
|
780
|
+
equal(u.toString(), '?bar=1&bar=1&bar=1', "parameters NOT de-duplicated");
|
781
|
+
|
782
|
+
// test adding
|
783
|
+
u = new URI('?bar=1&bar=1&bar=1');
|
784
|
+
u.duplicateQueryParameters(true);
|
785
|
+
u.addQuery('bar', 1);
|
786
|
+
equal(u.toString(), '?bar=1&bar=1&bar=1&bar=1', "parameters NOT de-duplicated after addQuery()");
|
787
|
+
});
|
788
|
+
test("escapeQuerySpace", function() {
|
789
|
+
var u = new URI('?bar=foo+bar&bam+baz=foo');
|
790
|
+
var data = u.query(true);
|
791
|
+
|
792
|
+
equal(data.bar, 'foo bar', "value un-spac-escaped");
|
793
|
+
equal(data['bam baz'], 'foo', "name un-spac-escaped");
|
794
|
+
|
795
|
+
u.escapeQuerySpace(false);
|
796
|
+
data = u.query(true);
|
797
|
+
equal(data.bar, 'foo+bar', "value not un-spac-escaped");
|
798
|
+
equal(data['bam+baz'], 'foo', "name not un-spac-escaped");
|
799
|
+
|
800
|
+
u.escapeQuerySpace(true);
|
801
|
+
data = u.query(true);
|
802
|
+
|
803
|
+
equal(data.bar, 'foo bar', "value un-spac-escaped again");
|
804
|
+
equal(data['bam baz'], 'foo', "name un-spac-escaped again");
|
805
|
+
|
806
|
+
u.escapeQuerySpace(false);
|
807
|
+
|
808
|
+
u.addQuery('alpha bravo', 'charlie delta');
|
809
|
+
equal(u.toString(), '?bar=foo%2Bbar&bam%2Bbaz=foo&alpha%20bravo=charlie%20delta', 'serialized un/escaped space');
|
810
|
+
|
811
|
+
URI.escapeQuerySpace = false;
|
812
|
+
u = new URI('?bar=foo+bar&bam+baz=foo');
|
813
|
+
data = u.query(true);
|
814
|
+
equal(data.bar, 'foo+bar', "value not un-spac-escaped by default");
|
815
|
+
equal(data['bam+baz'], 'foo', "name not un-spac-escaped by default");
|
816
|
+
|
817
|
+
// reset
|
818
|
+
URI.escapeQuerySpace = true;
|
819
|
+
});
|
820
|
+
test("hasQuery", function() {
|
821
|
+
var u = URI('?string=bar&list=one&list=two&number=123&null&empty=');
|
822
|
+
|
823
|
+
// exists
|
824
|
+
equal(u.hasQuery('string'), true, "simple exists check - passing");
|
825
|
+
equal(u.hasQuery('nono'), false, "simple exists check - failing");
|
826
|
+
|
827
|
+
// truthy value
|
828
|
+
equal(u.hasQuery('string', true), true, "has truthy value check - passing string");
|
829
|
+
equal(u.hasQuery('number', true), true, "has truthy value check - passing number");
|
830
|
+
equal(u.hasQuery('list', true), true, "has truthy value check - passing list");
|
831
|
+
equal(u.hasQuery('empty', true), false, "has truthy value check - failing empty");
|
832
|
+
equal(u.hasQuery('null', true), false, "has truthy value check - failing null");
|
833
|
+
|
834
|
+
// falsy value
|
835
|
+
equal(u.hasQuery('string', false), false, "has falsy value check - failing string");
|
836
|
+
equal(u.hasQuery('number', false), false, "has falsy value check - failing number");
|
837
|
+
equal(u.hasQuery('list', false), false, "has falsy value check - failing list");
|
838
|
+
equal(u.hasQuery('empty', false), true, "has falsy value check - passing empty");
|
839
|
+
equal(u.hasQuery('null', false), true, "has falsy value check - passing null");
|
840
|
+
|
841
|
+
// match value
|
842
|
+
equal(u.hasQuery('string', "bar"), true, "value check - passing string");
|
843
|
+
equal(u.hasQuery('number', 123), true, "value check - passing number");
|
844
|
+
equal(u.hasQuery('number', "123"), true, "value check - passing number as string");
|
845
|
+
equal(u.hasQuery('list', "one"), false, "value check - failing list");
|
846
|
+
equal(u.hasQuery('empty', ""), true, "value check - passing empty");
|
847
|
+
equal(u.hasQuery('null', ""), false, "value check - failing null");
|
848
|
+
|
849
|
+
// matching RegExp
|
850
|
+
equal(u.hasQuery('string', /ar$/), true, "RegExp check - passing string");
|
851
|
+
equal(u.hasQuery('number', /2/), true, "RegExp check - passing number");
|
852
|
+
equal(u.hasQuery('string', /nono/), false, "RegExp check - failing string");
|
853
|
+
equal(u.hasQuery('number', /999/), false, "RegExp check - failing number");
|
854
|
+
|
855
|
+
// matching array
|
856
|
+
equal(u.hasQuery('string', ['one']), false, "array check - failing string");
|
857
|
+
equal(u.hasQuery('list', ['one']), false, "array check - failing incomplete list");
|
858
|
+
equal(u.hasQuery('list', ['one', 'two']), true, "array check - passing list");
|
859
|
+
equal(u.hasQuery('list', ['two', 'one']), true, "array check - passing unsorted list");
|
860
|
+
|
861
|
+
// matching part of array
|
862
|
+
equal(u.hasQuery('string', ['one'], true), false, "in array check - failing string");
|
863
|
+
equal(u.hasQuery('list', 'one', true), true, "in array check - passing value");
|
864
|
+
equal(u.hasQuery('list', ['one'], true), true, "in array check - passing incomplete list");
|
865
|
+
equal(u.hasQuery('list', ['one', 'two'], true), true, "in array check - passing list");
|
866
|
+
equal(u.hasQuery('list', ['two', 'one'], true), true, "in array check - passing unsorted list");
|
867
|
+
equal(u.hasQuery('list', /ne$/, true), true, "in array check - passing RegExp");
|
868
|
+
equal(u.hasQuery('list', [/ne$/], true), true, "in array check - passing RegExp list");
|
869
|
+
|
870
|
+
// comparison function
|
871
|
+
equal(u.hasQuery('string', function(value, name, data) {
|
872
|
+
equal(value, "bar", "Function check - param value");
|
873
|
+
equal(name, "string", "Function check - param name");
|
874
|
+
equal(typeof data, "object", "Function check - param data");
|
875
|
+
return true;
|
876
|
+
}), true, "Function check - passing true");
|
877
|
+
equal(u.hasQuery('string', function(value, name, data) {
|
878
|
+
return false;
|
879
|
+
}), false, "Function check - passing false");
|
880
|
+
});
|
881
|
+
|
882
|
+
module("normalizing");
|
883
|
+
test("normalize", function() {
|
884
|
+
var u = new URI("http://www.exämple.org:80/food/woo/.././../baz.html?&foo=bar&&baz=bam&&baz=bau&#");
|
885
|
+
u.normalize();
|
886
|
+
equal(u+"", "http://www.xn--exmple-cua.org/baz.html?foo=bar&baz=bam&baz=bau", "fully normalized URL");
|
887
|
+
});
|
888
|
+
test("normalizeProtocol", function() {
|
889
|
+
var u = new URI("hTTp://example.org/foobar.html");
|
890
|
+
u.normalizeProtocol();
|
891
|
+
equal(u+"", "http://example.org/foobar.html", "lowercase http");
|
892
|
+
});
|
893
|
+
test("normalizeHost", function() {
|
894
|
+
if (window.punycode) {
|
895
|
+
var u = new URI("http://exämple.org/foobar.html");
|
896
|
+
u.normalizeHostname();
|
897
|
+
equal(u+"", "http://xn--exmple-cua.org/foobar.html", "converting IDN to punycode");
|
898
|
+
}
|
899
|
+
|
900
|
+
if (window.IPv6) {
|
901
|
+
u = new URI("http://fe80:0000:0000:0000:0204:61ff:fe9d:f156/foobar.html");
|
902
|
+
u.normalizeHostname();
|
903
|
+
equal(u+"", "http://fe80::204:61ff:fe9d:f156/foobar.html", "best IPv6 representation");
|
904
|
+
}
|
905
|
+
|
906
|
+
u = new URI("http://wWw.eXamplE.Org/foobar.html");
|
907
|
+
u.normalizeHostname();
|
908
|
+
equal(u+"", "http://www.example.org/foobar.html", "lower case hostname");
|
909
|
+
});
|
910
|
+
test("normalizePort", function() {
|
911
|
+
var u = new URI("http://example.org:80/foobar.html");
|
912
|
+
u.normalizePort();
|
913
|
+
equal(u+"", "http://example.org/foobar.html", "dropping port 80 for http");
|
914
|
+
|
915
|
+
u = new URI("ftp://example.org:80/foobar.html");
|
916
|
+
u.normalizePort();
|
917
|
+
equal(u+"", "ftp://example.org:80/foobar.html", "keeping port 80 for ftp");
|
918
|
+
|
919
|
+
});
|
920
|
+
test("normalizePath", function() {
|
921
|
+
// relative URL
|
922
|
+
var u = new URI('/food/bar/baz.html');
|
923
|
+
|
924
|
+
u.normalizePath();
|
925
|
+
equal(u.path(), '/food/bar/baz.html', "absolute path without change");
|
926
|
+
|
927
|
+
u.path('food/bar/baz.html').normalizePath();
|
928
|
+
equal(u.path(), 'food/bar/baz.html', "relative path without change");
|
929
|
+
|
930
|
+
u.path('/food/../bar/baz.html').normalizePath();
|
931
|
+
equal(u.path(), '/bar/baz.html', "single parent");
|
932
|
+
|
933
|
+
u.path('/food/woo/../../bar/baz.html').normalizePath();
|
934
|
+
equal(u.path(), '/bar/baz.html', "double parent");
|
935
|
+
|
936
|
+
u.path('/food/woo/../bar/../baz.html').normalizePath();
|
937
|
+
equal(u.path(), '/food/baz.html', "split double parent");
|
938
|
+
|
939
|
+
u.path('/food/woo/.././../baz.html').normalizePath();
|
940
|
+
equal(u.path(), '/baz.html', "cwd-split double parent");
|
941
|
+
|
942
|
+
u.path('food/woo/../bar/baz.html').normalizePath();
|
943
|
+
equal(u.path(), 'food/bar/baz.html', "relative parent");
|
944
|
+
|
945
|
+
u.path('./food/woo/../bar/baz.html').normalizePath();
|
946
|
+
equal(u.path(), 'food/bar/baz.html', "dot-relative parent");
|
947
|
+
|
948
|
+
// absolute URL
|
949
|
+
u = new URI('http://example.org/foo/bar/baz.html');
|
950
|
+
u.normalizePath();
|
951
|
+
equal(u.path(), '/foo/bar/baz.html', "URL: absolute path without change");
|
952
|
+
|
953
|
+
u.path('foo/bar/baz.html').normalizePath();
|
954
|
+
equal(u.path(), '/foo/bar/baz.html', "URL: relative path without change");
|
955
|
+
|
956
|
+
u.path('/foo/../bar/baz.html').normalizePath();
|
957
|
+
equal(u.path(), '/bar/baz.html', "URL: single parent");
|
958
|
+
|
959
|
+
u.path('/foo/woo/../../bar/baz.html').normalizePath();
|
960
|
+
equal(u.path(), '/bar/baz.html', "URL: double parent");
|
961
|
+
|
962
|
+
u.path('/foo/woo/../bar/../baz.html').normalizePath();
|
963
|
+
equal(u.path(), '/foo/baz.html', "URL: split double parent");
|
964
|
+
|
965
|
+
u.path('/foo/woo/.././../baz.html').normalizePath();
|
966
|
+
equal(u.path(), '/baz.html', "URL: cwd-split double parent");
|
967
|
+
|
968
|
+
u.path('foo/woo/../bar/baz.html').normalizePath();
|
969
|
+
equal(u.path(), '/foo/bar/baz.html', "URL: relative parent");
|
970
|
+
|
971
|
+
u.path('./foo/woo/../bar/baz.html').normalizePath();
|
972
|
+
equal(u.path(), '/foo/bar/baz.html', "URL: dot-relative parent");
|
973
|
+
|
974
|
+
u.path('/.//').normalizePath();
|
975
|
+
equal(u.path(), '/', "root /.//");
|
976
|
+
|
977
|
+
u.path('/.').normalizePath();
|
978
|
+
equal(u.path(), '/', "root /.");
|
979
|
+
|
980
|
+
// encoding
|
981
|
+
u._parts.path = '/~userhome/@mine;is %2F and/';
|
982
|
+
u.normalize();
|
983
|
+
equal(u.pathname(), '/~userhome/@mine;is%20%2F%20and/', "path encoding");
|
984
|
+
});
|
985
|
+
test("normalizeQuery", function() {
|
986
|
+
var u = new URI("http://example.org/foobar.html?");
|
987
|
+
u.normalizeQuery();
|
988
|
+
equal(u+"", "http://example.org/foobar.html", "dropping empty query sign");
|
989
|
+
|
990
|
+
u.query("?&foo=bar&&baz=bam&").normalizeQuery();
|
991
|
+
equal(u.query(), "foo=bar&baz=bam", "bad query resolution");
|
992
|
+
|
993
|
+
u.query("?&foo=bar&&baz=bam&&baz=bau&").normalizeQuery();
|
994
|
+
equal(u.query(), "foo=bar&baz=bam&baz=bau", "bad query resolution");
|
995
|
+
|
996
|
+
u.query("?&foo=bar&foo=bar").normalizeQuery();
|
997
|
+
equal(u.query(), "foo=bar", "duplicate key=value resolution");
|
998
|
+
});
|
999
|
+
test("normalizeFragment", function() {
|
1000
|
+
var u = new URI("http://example.org/foobar.html#");
|
1001
|
+
u.normalizeFragment();
|
1002
|
+
equal(u+"", "http://example.org/foobar.html", "dropping empty fragment sign");
|
1003
|
+
});
|
1004
|
+
test("readable", function() {
|
1005
|
+
var u = new URI("http://foo:bar@www.xn--exmple-cua.org/hello%20world/ä.html?foo%5B%5D=b+är#fragment");
|
1006
|
+
equal(u.readable(), "http://www.exämple.org/hello world/ä.html?foo[]=b är#fragment", "readable URL");
|
1007
|
+
});
|
1008
|
+
|
1009
|
+
module("resolving URLs");
|
1010
|
+
test("absoluteTo", function() {
|
1011
|
+
// this being "../bar/baz.html?foo=bar"
|
1012
|
+
// base being "http://example.org/foo/other/file.html"
|
1013
|
+
// return being http://example.org/foo/bar/baz.html?foo=bar"
|
1014
|
+
var tests = [{
|
1015
|
+
name: 'relative resolve',
|
1016
|
+
url: 'relative/path?blubber=1#hash1',
|
1017
|
+
base: 'http://www.example.org/path/to/file?some=query#hash',
|
1018
|
+
result: 'http://www.example.org/path/to/relative/path?blubber=1#hash1'
|
1019
|
+
}, {
|
1020
|
+
name: 'absolute resolve',
|
1021
|
+
url: '/absolute/path?blubber=1#hash1',
|
1022
|
+
base: 'http://www.example.org/path/to/file?some=query#hash',
|
1023
|
+
result: 'http://www.example.org/absolute/path?blubber=1#hash1'
|
1024
|
+
}, {
|
1025
|
+
name: 'relative resolve full URL',
|
1026
|
+
url: 'relative/path?blubber=1#hash3',
|
1027
|
+
base: 'http://user:pass@www.example.org:1234/path/to/file?some=query#hash',
|
1028
|
+
result: 'http://user:pass@www.example.org:1234/path/to/relative/path?blubber=1#hash3'
|
1029
|
+
}, {
|
1030
|
+
name: 'absolute resolve full URL',
|
1031
|
+
url: '/absolute/path?blubber=1#hash3',
|
1032
|
+
base: 'http://user:pass@www.example.org:1234/path/to/file?some=query#hash',
|
1033
|
+
result: 'http://user:pass@www.example.org:1234/absolute/path?blubber=1#hash3'
|
1034
|
+
}, {
|
1035
|
+
name: 'absolute resolve full URL without scheme',
|
1036
|
+
url: '//user:pass@www.example.org:1234/path/to/file?some=query#hash',
|
1037
|
+
base: 'proto://user:pass@www.example.org:1234/path/to/file?some=query#hash',
|
1038
|
+
result: 'proto://user:pass@www.example.org:1234/path/to/file?some=query#hash'
|
1039
|
+
}, {
|
1040
|
+
name: 'path-relative resolve',
|
1041
|
+
url: './relative/path?blubber=1#hash3',
|
1042
|
+
base: 'http://user:pass@www.example.org:1234/path/to/file?some=query#hash',
|
1043
|
+
result: 'http://user:pass@www.example.org:1234/path/to/relative/path?blubber=1#hash3'
|
1044
|
+
}, {
|
1045
|
+
name: 'path-relative parent resolve',
|
1046
|
+
url: '../relative/path?blubber=1#hash3',
|
1047
|
+
base: 'http://user:pass@www.example.org:1234/path/to/file?some=query#hash',
|
1048
|
+
result: 'http://user:pass@www.example.org:1234/path/relative/path?blubber=1#hash3'
|
1049
|
+
}, {
|
1050
|
+
name: 'path-relative path resolve',
|
1051
|
+
url: './relative/path?blubber=1#hash3',
|
1052
|
+
base: '/path/to/file?some=query#hash',
|
1053
|
+
result: '/path/to/relative/path?blubber=1#hash3'
|
1054
|
+
}, {
|
1055
|
+
name: 'path-relative parent path resolve',
|
1056
|
+
url: '../relative/path?blubber=1#hash3',
|
1057
|
+
base: '/path/to/file?some=query#hash',
|
1058
|
+
result: '/path/relative/path?blubber=1#hash3'
|
1059
|
+
}, {
|
1060
|
+
name: 'base query string',
|
1061
|
+
url: '#hash3',
|
1062
|
+
base: '/path/to/file?some=query#hash',
|
1063
|
+
result: '/path/to/file?some=query#hash3'
|
1064
|
+
}, {
|
1065
|
+
name: 'relative path - urljoin',
|
1066
|
+
url: 'the_relative_url',
|
1067
|
+
base: 'rel/path/',
|
1068
|
+
result: 'rel/path/the_relative_url'
|
1069
|
+
}, {
|
1070
|
+
name: 'relative path file - urljoin',
|
1071
|
+
url: 'the_relative_url',
|
1072
|
+
base: 'rel/path/something',
|
1073
|
+
result: 'rel/path/the_relative_url'
|
1074
|
+
}, {
|
1075
|
+
name: 'relative parent path file - urljoin',
|
1076
|
+
url: '../the_relative_url',
|
1077
|
+
base: 'rel/path/',
|
1078
|
+
result: 'rel/the_relative_url'
|
1079
|
+
}, {
|
1080
|
+
name: 'relative root path file - urljoin',
|
1081
|
+
url: '/the_relative_url',
|
1082
|
+
base: 'rel/path/',
|
1083
|
+
result: '/the_relative_url'
|
1084
|
+
}, {
|
1085
|
+
name: 'relative root file - urljoin',
|
1086
|
+
url: '/the_relative_url',
|
1087
|
+
base: 'http://example.com/rel/path/',
|
1088
|
+
result: 'http://example.com/the_relative_url'
|
1089
|
+
}, {
|
1090
|
+
name: 'absolute passthru - urljoin',
|
1091
|
+
url: 'http://github.com//the_relative_url',
|
1092
|
+
base: 'http://example.com/foo/bar',
|
1093
|
+
result: 'http://github.com//the_relative_url'
|
1094
|
+
}, {
|
1095
|
+
name: 'file paths - urljoin',
|
1096
|
+
url: 'anotherFile',
|
1097
|
+
base: 'aFile',
|
1098
|
+
result: 'anotherFile'
|
1099
|
+
}
|
1100
|
+
];
|
1101
|
+
|
1102
|
+
for (var i = 0, t; t = tests[i]; i++) {
|
1103
|
+
var u = new URI(t.url),
|
1104
|
+
r = u.absoluteTo(t.base);
|
1105
|
+
|
1106
|
+
equal(r + "", t.result, t.name);
|
1107
|
+
}
|
1108
|
+
|
1109
|
+
});
|
1110
|
+
test("relativeTo", function() {
|
1111
|
+
var tests = [{
|
1112
|
+
name: 'same parent',
|
1113
|
+
url: '/relative/path?blubber=1#hash1',
|
1114
|
+
base: '/relative/file?some=query#hash',
|
1115
|
+
result: 'path?blubber=1#hash1'
|
1116
|
+
}, {
|
1117
|
+
name: 'direct parent',
|
1118
|
+
url: '/relative/path?blubber=1#hash1',
|
1119
|
+
base: '/relative/sub/file?some=query#hash',
|
1120
|
+
result: '../path?blubber=1#hash1'
|
1121
|
+
}, {
|
1122
|
+
name: 'second parent',
|
1123
|
+
url: '/relative/path?blubber=1#hash1',
|
1124
|
+
base: '/relative/sub/sub/file?some=query#hash',
|
1125
|
+
result: '../../path?blubber=1#hash1'
|
1126
|
+
}, {
|
1127
|
+
name: 'third parent',
|
1128
|
+
url: '/relative/path?blubber=1#hash1',
|
1129
|
+
base: '/relative/sub/foo/sub/file?some=query#hash',
|
1130
|
+
result: '../../../path?blubber=1#hash1'
|
1131
|
+
}, {
|
1132
|
+
name: 'parent top level',
|
1133
|
+
url: '/relative/path?blubber=1#hash1',
|
1134
|
+
base: '/path/to/file?some=query#hash',
|
1135
|
+
result: '../../relative/path?blubber=1#hash1'
|
1136
|
+
}, {
|
1137
|
+
name: 'descendant',
|
1138
|
+
url: '/base/path/with/subdir/inner.html',
|
1139
|
+
base: '/base/path/top.html',
|
1140
|
+
result: 'with/subdir/inner.html'
|
1141
|
+
}, {
|
1142
|
+
name: 'absolute /',
|
1143
|
+
url: 'http://example.org/foo/bar/bat',
|
1144
|
+
base: 'http://example.org/',
|
1145
|
+
result: 'foo/bar/bat'
|
1146
|
+
}, {
|
1147
|
+
name: 'absolute /foo',
|
1148
|
+
url: 'http://example.org/foo/bar/bat',
|
1149
|
+
base: 'http://example.org/foo',
|
1150
|
+
result: 'foo/bar/bat'
|
1151
|
+
}, {
|
1152
|
+
name: 'absolute /foo/',
|
1153
|
+
url: 'http://example.org/foo/bar/bat',
|
1154
|
+
base: 'http://example.org/foo/',
|
1155
|
+
result: 'bar/bat'
|
1156
|
+
}, {
|
1157
|
+
name: 'same scheme',
|
1158
|
+
url: 'http://example.org/foo/bar/bat',
|
1159
|
+
base: 'http://example.com/foo/',
|
1160
|
+
result: '//example.org/foo/bar/bat'
|
1161
|
+
}, {
|
1162
|
+
name: 'different scheme',
|
1163
|
+
url: 'http://example.org/foo/bar',
|
1164
|
+
base: 'https://example.org/foo/',
|
1165
|
+
result: 'http://example.org/foo/bar'
|
1166
|
+
}, {
|
1167
|
+
name: 'base with no scheme or host',
|
1168
|
+
url: 'http://example.org/foo/bar',
|
1169
|
+
base: '/foo/',
|
1170
|
+
result: 'http://example.org/foo/bar'
|
1171
|
+
}, {
|
1172
|
+
name: 'base with no scheme',
|
1173
|
+
url: 'http://example.org/foo/bar',
|
1174
|
+
base: '//example.org/foo/bar',
|
1175
|
+
result: 'http://example.org/foo/bar'
|
1176
|
+
}, {
|
1177
|
+
name: 'denormalized base',
|
1178
|
+
url: '/foo/bar/bat',
|
1179
|
+
base: '/foo/./bar/',
|
1180
|
+
result: 'bat'
|
1181
|
+
}, {
|
1182
|
+
name: 'denormalized url',
|
1183
|
+
url: '/foo//bar/bat',
|
1184
|
+
base: '/foo/bar/',
|
1185
|
+
result: 'bat'
|
1186
|
+
}, {
|
1187
|
+
name: 'credentials',
|
1188
|
+
url: 'http://user:pass@example.org/foo/bar',
|
1189
|
+
base: 'http://example.org/foo/',
|
1190
|
+
result: '//user:pass@example.org/foo/bar'
|
1191
|
+
}, {
|
1192
|
+
name: 'base credentials',
|
1193
|
+
url: 'http://example.org/foo/bar',
|
1194
|
+
base: 'http://user:pass@example.org/foo/bar',
|
1195
|
+
result: '//example.org/foo/bar'
|
1196
|
+
}, {
|
1197
|
+
name: 'same credentials different host',
|
1198
|
+
url: 'http://user:pass@example.org/foo/bar',
|
1199
|
+
base: 'http://user:pass@example.com/foo/bar',
|
1200
|
+
result: '//user:pass@example.org/foo/bar'
|
1201
|
+
}, {
|
1202
|
+
name: 'different port 1',
|
1203
|
+
url: 'http://example.org/foo/bar',
|
1204
|
+
base: 'http://example.org:8080/foo/bar',
|
1205
|
+
result: '//example.org/foo/bar'
|
1206
|
+
}, {
|
1207
|
+
name: 'different port 2',
|
1208
|
+
url: 'http://example.org:8081/foo/bar',
|
1209
|
+
base: 'http://example.org:8080/foo/bar',
|
1210
|
+
result: '//example.org:8081/foo/bar'
|
1211
|
+
}, {
|
1212
|
+
name: 'different port 3',
|
1213
|
+
url: 'http://example.org:8081/foo/bar',
|
1214
|
+
base: 'http://example.org/foo/bar',
|
1215
|
+
result: '//example.org:8081/foo/bar'
|
1216
|
+
}, {
|
1217
|
+
name: 'same path - fragment',
|
1218
|
+
url: 'http://www.example.com:8080/dir/file#abcd',
|
1219
|
+
base: 'http://www.example.com:8080/dir/file',
|
1220
|
+
result: '#abcd'
|
1221
|
+
}, {
|
1222
|
+
name: 'same path - query',
|
1223
|
+
url: 'http://www.example.com:8080/dir/file?abcd=123',
|
1224
|
+
base: 'http://www.example.com:8080/dir/file',
|
1225
|
+
result: '?abcd=123'
|
1226
|
+
}, {
|
1227
|
+
name: 'same path - query and fragment',
|
1228
|
+
url: 'http://www.example.com:8080/dir/file?abcd=123#alpha',
|
1229
|
+
base: 'http://www.example.com:8080/dir/file',
|
1230
|
+
result: '?abcd=123#alpha'
|
1231
|
+
}, {
|
1232
|
+
name: 'already relative',
|
1233
|
+
url: 'foo/bar',
|
1234
|
+
base: '/foo/',
|
1235
|
+
'throws': true
|
1236
|
+
}, {
|
1237
|
+
name: 'relative base',
|
1238
|
+
url: '/foo/bar',
|
1239
|
+
base: 'foo/',
|
1240
|
+
'throws': true
|
1241
|
+
}
|
1242
|
+
];
|
1243
|
+
|
1244
|
+
for (var i = 0, t; t = tests[i]; i++) {
|
1245
|
+
var u = new URI(t.url),
|
1246
|
+
b = new URI(t.base),
|
1247
|
+
caught = false;
|
1248
|
+
var r;
|
1249
|
+
|
1250
|
+
try {
|
1251
|
+
r = u.relativeTo(b);
|
1252
|
+
} catch (e) {
|
1253
|
+
caught = true;
|
1254
|
+
}
|
1255
|
+
|
1256
|
+
if (t['throws']) {
|
1257
|
+
ok(caught, t.name + " should throw exception");
|
1258
|
+
} else {
|
1259
|
+
ok(!caught, t.name + " should not throw exception");
|
1260
|
+
equal(r + "", t.result, t.name);
|
1261
|
+
|
1262
|
+
var a = r.absoluteTo(t.base);
|
1263
|
+
var n = u.clone().normalize();
|
1264
|
+
equal(a.toString(), n.toString(), t.name + " reversed");
|
1265
|
+
}
|
1266
|
+
}
|
1267
|
+
|
1268
|
+
equal("b/c",
|
1269
|
+
new URI("http://example.org/a/b/c")
|
1270
|
+
.scheme("")
|
1271
|
+
.authority("")
|
1272
|
+
.relativeTo("/a/")
|
1273
|
+
.toString(),
|
1274
|
+
"bug #103");
|
1275
|
+
|
1276
|
+
equal("b/c",
|
1277
|
+
new URI("//example.org/a/b/c")
|
1278
|
+
.authority("")
|
1279
|
+
.relativeTo("/a/")
|
1280
|
+
.toString(),
|
1281
|
+
"bug #103 (2)");
|
1282
|
+
});
|
1283
|
+
|
1284
|
+
module("static helpers");
|
1285
|
+
test("withinString", function() {
|
1286
|
+
var source = "Hello www.example.com,\n"
|
1287
|
+
+ "http://google.com is a search engine, like http://www.bing.com\n"
|
1288
|
+
+ "http://exämple.org/foo.html?baz=la#bumm is an IDN URL,\n"
|
1289
|
+
+ "http://123.123.123.123/foo.html is IPv4 and http://fe80:0000:0000:0000:0204:61ff:fe9d:f156/foobar.html is IPv6.\n"
|
1290
|
+
+ "links can also be in parens (http://example.org) or quotes »http://example.org«.",
|
1291
|
+
expected = "Hello <a>www.example.com</a>,\n"
|
1292
|
+
+ "<a>http://google.com</a> is a search engine, like <a>http://www.bing.com</a>\n"
|
1293
|
+
+ "<a>http://exämple.org/foo.html?baz=la#bumm</a> is an IDN URL,\n"
|
1294
|
+
+ "<a>http://123.123.123.123/foo.html</a> is IPv4 and <a>http://fe80:0000:0000:0000:0204:61ff:fe9d:f156/foobar.html</a> is IPv6.\n"
|
1295
|
+
+ "links can also be in parens (<a>http://example.org</a>) or quotes »<a>http://example.org</a>«.",
|
1296
|
+
result = URI.withinString(source, function(url) {
|
1297
|
+
return '<a>' + url + '</a>';
|
1298
|
+
});
|
1299
|
+
|
1300
|
+
equal(result, expected, "in string URI identification");
|
1301
|
+
});
|
1302
|
+
test("noConflict", function() {
|
1303
|
+
var actual_lib = URI; // actual library; after loading, before noConflict()
|
1304
|
+
var unconflicted = URI.noConflict();
|
1305
|
+
|
1306
|
+
strictEqual( unconflicted, actual_lib, "noConflict() returns the URI object" );
|
1307
|
+
strictEqual( URI, URI_pre_lib, "noConflict() restores the `URI` variable" );
|
1308
|
+
|
1309
|
+
// restore for other tests
|
1310
|
+
window.URI = actual_lib;
|
1311
|
+
});
|
1312
|
+
test("noConflict(removeAll=true)", function() {
|
1313
|
+
var actual = {
|
1314
|
+
URI: URI,
|
1315
|
+
URITemplate: URITemplate,
|
1316
|
+
IPv6: IPv6,
|
1317
|
+
SecondLevelDomains: SecondLevelDomains
|
1318
|
+
};
|
1319
|
+
|
1320
|
+
var unconflicted = URI.noConflict(true);
|
1321
|
+
|
1322
|
+
deepEqual( unconflicted, actual, "noConflict(true) returns the { URI, URITemplate, IPv6, SecondLevelDomains } object" );
|
1323
|
+
strictEqual( URI, URI_pre_lib, "noConflict(true) restores the `URI` variable" );
|
1324
|
+
strictEqual( URITemplate, URITemplate_pre_lib, "noConflict(true) restores the `URITemplate` variable" );
|
1325
|
+
strictEqual( IPv6, IPv6_pre_lib, "noConflict(true) restores the `IPv6` variable" );
|
1326
|
+
strictEqual( SecondLevelDomains, SecondLevelDomains_pre_lib, "noConflict(true) restores the `SecondLevelDomains` variable" );
|
1327
|
+
|
1328
|
+
// restore for other tests
|
1329
|
+
window.URI = actual.URI;
|
1330
|
+
window.URITemplate = actual.URITemplate;
|
1331
|
+
window.IPv6 = actual.IPv6;
|
1332
|
+
window.SecondLevelDomains = actual.SecondLevelDomains;
|
1333
|
+
});
|
1334
|
+
|
1335
|
+
module("comparing URLs");
|
1336
|
+
test("equals", function() {
|
1337
|
+
var u = new URI("http://example.org/foo/bar.html?foo=bar&hello=world&hello=mars#fragment"),
|
1338
|
+
e = [
|
1339
|
+
"http://example.org/foo/../foo/bar.html?foo=bar&hello=world&hello=mars#fragment",
|
1340
|
+
"http://exAmple.org/foo/bar.html?foo=bar&hello=world&hello=mars#fragment",
|
1341
|
+
"http://exAmple.org:80/foo/bar.html?foo=bar&hello=world&hello=mars#fragment",
|
1342
|
+
"http://example.org/foo/bar.html?foo=bar&hello=mars&hello=world#fragment",
|
1343
|
+
"http://example.org/foo/bar.html?hello=mars&hello=world&foo=bar&#fragment"
|
1344
|
+
],
|
1345
|
+
d = [
|
1346
|
+
"http://example.org/foo/../bar.html?foo=bar&hello=world&hello=mars#fragment",
|
1347
|
+
"http://example.org/foo/bar.html?foo=bar&hello=world&hello=mars#frAgment",
|
1348
|
+
"http://example.org/foo/bar.html?foo=bar&hello=world&hello=mArs#fragment",
|
1349
|
+
"http://example.org/foo/bar.hTml?foo=bar&hello=world&hello=mars#fragment",
|
1350
|
+
"http://example.org:8080/foo/bar.html?foo=bar&hello=world&hello=mars#fragment",
|
1351
|
+
"http://user:pass@example.org/foo/bar.html?foo=bar&hello=world&hello=mars#fragment",
|
1352
|
+
"ftp://example.org/foo/bar.html?foo=bar&hello=world&hello=mars#fragment",
|
1353
|
+
"http://example.org/foo/bar.html?foo=bar&hello=world&hello=mars&hello=jupiter#fragment"
|
1354
|
+
],
|
1355
|
+
i, c;
|
1356
|
+
|
1357
|
+
for (i = 0; c = e[i]; i++) {
|
1358
|
+
equal(u.equals(c), true, "equality " + i);
|
1359
|
+
}
|
1360
|
+
|
1361
|
+
for (i = 0; c = d[i]; i++) {
|
1362
|
+
equal(u.equals(c), false, "different " + i);
|
1363
|
+
}
|
1364
|
+
});
|
1365
|
+
|
1366
|
+
module("Charset");
|
1367
|
+
test("iso8859", function() {
|
1368
|
+
var u = new URI("/ä.html");
|
1369
|
+
u.normalizePath();
|
1370
|
+
equal(u.path(), "/%C3%A4.html", 'Unicode');
|
1371
|
+
|
1372
|
+
URI.iso8859();
|
1373
|
+
u = new URI("/ä.html");
|
1374
|
+
u.normalizePath();
|
1375
|
+
equal(u.path(), "/%E4.html", 'ISO8859');
|
1376
|
+
u.path('/ö.html');
|
1377
|
+
equal(u.path(), "/%F6.html", 'ISO8859');
|
1378
|
+
|
1379
|
+
URI.unicode();
|
1380
|
+
u = new URI("/ä.html");
|
1381
|
+
u.normalizePath();
|
1382
|
+
equal(u.path(), "/%C3%A4.html", 'Unicode again');
|
1383
|
+
|
1384
|
+
u = new URI("/ä.html");
|
1385
|
+
u.normalizePath();
|
1386
|
+
equal(u.path(), "/%C3%A4.html", 'convert unicode start');
|
1387
|
+
u.iso8859();
|
1388
|
+
equal(u.path(), "/%E4.html", 'convert iso8859');
|
1389
|
+
u.unicode();
|
1390
|
+
equal(u.path(), "/%C3%A4.html", 'convert unicode');
|
1391
|
+
});
|
1392
|
+
test("bad charset in QueryString", function() {
|
1393
|
+
var uri = new URI("http://www.google.com.hk/search?q=pennytel%20downloads&sa=%20%CB%D1%20%CB%F7%20&forid=1&prog=aff&ie=GB2312&oe=GB2312&safe=active&source=sdo_sb_html&hl=zh-CN");
|
1394
|
+
var data = uri.query(true);
|
1395
|
+
|
1396
|
+
equal(data.sa, "%20%CB%D1%20%CB%F7%20", 'undecodable value returned');
|
1397
|
+
equal(data.forid, "1", 'decodable value returned');
|
1398
|
+
|
1399
|
+
uri.normalizeQuery();
|
1400
|
+
data = uri.query(true);
|
1401
|
+
equal(data.sa, "%20%CB%D1%20%CB%F7%20", 'undecodable value returned');
|
1402
|
+
equal(data.forid, "1", 'decodable value returned');
|
1403
|
+
});
|
1404
|
+
|
1405
|
+
module("Encoding");
|
1406
|
+
test("encodeReserved", function() {
|
1407
|
+
equal(URI.encodeReserved("ä:/?#[]@!$&'()*+,;="), "%C3%A4:/?#[]@!$&'()*+,;=");
|
1408
|
+
});
|
1409
|
+
})();
|