Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent path relativization #103

Merged
merged 6 commits into from
Aug 8, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/URI.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,14 +381,14 @@ URI.parse = function(string, parts) {
// extract protocol
if (string.substring(0, 2) === '//') {
// relative-scheme
parts.protocol = '';
parts.protocol = null;
string = string.substring(2);
// extract "user:pass@host:port"
string = URI.parseAuthority(string, parts);
} else {
pos = string.indexOf(':');
if (pos > -1) {
parts.protocol = string.substring(0, pos);
parts.protocol = string.substring(0, pos) || null;
if (parts.protocol && !parts.protocol.match(URI.protocol_expression)) {
// : may be within the path
parts.protocol = undefined;
Expand Down Expand Up @@ -836,7 +836,7 @@ generateAccessor = function(_part){
if (v === undefined) {
return this._parts[_part] || "";
} else {
this._parts[_part] = v;
this._parts[_part] = v || null;
this.build(!build);
return this;
}
Expand Down
15 changes: 15 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,21 @@ test("relativeTo", function() {
equal(a.toString(), n.toString(), t.name + " reversed");
}
}

equal("b/c",
new URI("http://example.org/a/b/c")
.scheme("")
.authority("")
.relativeTo("/a/")
.toString(),
"bug #103");

equal("b/c",
new URI("//example.org/a/b/c")
.authority("")
.relativeTo("/a/")
.toString(),
"bug #103 (2)");
});

module("static helpers");
Expand Down
4 changes: 2 additions & 2 deletions test/urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ var urls = [{
url: '://user:pass@example.org:123/some/directory/file.html?query=string#fragment',
_url: '//user:pass@example.org:123/some/directory/file.html?query=string#fragment',
parts: {
protocol: "",
protocol: null,
username: 'user',
password: 'pass',
hostname: 'example.org',
Expand Down Expand Up @@ -476,7 +476,7 @@ var urls = [{
name: 'scheme-relative URL',
url: '//www.example.org/',
parts: {
protocol: '', // not null
protocol: null,
username: null,
password: null,
hostname: 'www.example.org',
Expand Down