Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Allow protocol relative urls in resolveUrl #184

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Core.js
Expand Up @@ -329,7 +329,7 @@ function resolveUrl(url){
url = url.replace(reDoubleSlash, "$1/");

// If the url is a valid url we do nothing
if (!url.match(/^(http||https):\/\//)) {
if (!url.match(/^(http:||https:)?\/\//)) {
// If this is a relative path
var path = (url.substring(0, 1) === "/") ? "" : location.pathname;
if (path.substring(path.length - 1) !== "/") {
Expand Down
22 changes: 21 additions & 1 deletion src/tests/tests.js
Expand Up @@ -112,7 +112,9 @@ function runTests(){
this.url2 = "http://foo.bar:80/a/b/c?d=e#f";
this.url3 = "http://foo.bar:88/a/b/c?d=e#f";
this.url4 = "hTtp://Foo.Bar:88/a/b/c?d=e#f";

this.url5 = "/a/b/c?d=e#f";
this.url6 = "https://foo.bar/a/b/c?d=e#f";
this.url7 = "//foo.bar/a/b/c?d=e#f"
},
steps: [{
name: "getDomainName",
Expand Down Expand Up @@ -147,6 +149,24 @@ function runTests(){
}) ===
"http://foo.bar:80/a/b/c?d=e&g=h#f";
}
}, {
name: "resolveUrl",
run: function(){
return resolveUrl(this.url5) ===
location.protocol + "//" + location.host + "/a/b/c?d=e#f";
}
}, {
name: "resolveUrl with different protocol",
run: function(){
return resolveUrl(this.url6) ===
"https://foo.bar/a/b/c?d=e#f";
}
}, {
name: "resolveUrl with relative protocol",
run: function(){
return resolveUrl(this.url7) ===
"//foo.bar/a/b/c?d=e#f";
}
}]
}, {
name: "Check the ACL feature",
Expand Down