poly-js-utils
Advanced tools
Comparing version 1.2.9 to 1.2.10
{ | ||
"name": "poly-js-utils", | ||
"version": "1.2.9", | ||
"version": "1.2.10", | ||
"description": "Common client-side tools used in HSS Sites themes and locators.", | ||
@@ -5,0 +5,0 @@ "main": "main.js", |
@@ -76,2 +76,24 @@ var utils = require('../src/utils'); | ||
}); | ||
it("should return properly when the url is relative", function() { | ||
var url = "www.example.com/example/ex"; | ||
var parsed = utils.parseUrl(url); | ||
expect(parsed.hash).toBe(""); | ||
expect(parsed.hostname).toBe("www.example.com"); | ||
expect(parsed.pathname).toBe("/example/ex"); | ||
expect(parsed.port).toBe(""); | ||
expect(parsed.protocol).toBe("http:"); | ||
expect(parsed.search).toBe(""); | ||
}); | ||
it("should return properly when the url is a path", function() { | ||
var url = "/example/ex"; | ||
var parsed = utils.parseUrl(url); | ||
expect(parsed.hash).toBe(""); | ||
expect(parsed.hostname).toBe(""); | ||
expect(parsed.pathname).toBe("/example/ex"); | ||
expect(parsed.port).toBe(""); | ||
expect(parsed.protocol).toBe("http:"); | ||
expect(parsed.search).toBe(""); | ||
}); | ||
}); | ||
@@ -78,0 +100,0 @@ |
@@ -32,3 +32,4 @@ var _ = require('underscore'); | ||
// Don't want url to be treated as relative (path) | ||
a.href = makeAbsolute(url); | ||
var absoluteUrl = makeAbsolute(url); | ||
a.href = absoluteUrl; | ||
@@ -38,2 +39,11 @@ var parts = ["protocol", "hostname", "port", "pathname", "search", "hash"]; | ||
if(!isAbsolute) { | ||
var splitHref = absoluteUrl.split(/^\/\/\//); | ||
// Checks that url is truly a path (i.e. it follows the "/example" format instead of "www.example.com" format) | ||
if(splitHref[1]) { | ||
parsed.hostname = splitHref[0]; | ||
parsed.pathname = splitHref[1]; | ||
} | ||
} | ||
// Make sure the pathname always beings with a / | ||
@@ -52,3 +62,2 @@ if (parsed.pathname && | ||
parsed.toString = parsed.getUrl; | ||
return parsed; | ||
@@ -55,0 +64,0 @@ }; |
99081
2126