Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Allow protocol relative urls in resolveUrl #184

Open
wants to merge 1 commit into from

1 participant

@submitteddenied
  • Added some tests to validate the behaviour of this function
  • This fixes issue #179
Michael Jensen Allow protocol relative urls in resolveUrl
* Added some tests to validate the behaviour of this function
4cb2ae2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 21, 2012
  1. Allow protocol relative urls in resolveUrl

    Michael Jensen authored
    * Added some tests to validate the behaviour of this function
This page is out of date. Refresh to see the latest.
Showing with 22 additions and 2 deletions.
  1. +1 −1  src/Core.js
  2. +21 −1 src/tests/tests.js
View
2  src/Core.js
@@ -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) !== "/") {
View
22 src/tests/tests.js
@@ -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",
@@ -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",
Something went wrong with that request. Please try again.