Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Keep hash and search params when using makeRelPath
Browse files Browse the repository at this point in the history
Fixes #19
  • Loading branch information
dfreedm committed Apr 29, 2014
1 parent ce0ac12 commit 3ccf932
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,16 @@ function makeDocumentRelPath(url) {
var u = new URL(url, root);
if (u.host === root.host && u.port === root.port &&
u.protocol === root.protocol) {
return makeRelPath(root.pathname, u.pathname);
return makeRelPath(root, u);
} else {
return url;
}
}

// make a relative path from source to target
function makeRelPath(source, target) {
function makeRelPath(sourceUrl, targetUrl) {
var source = source.pathname;
var target = target.pathname;
var s = source.split('/');
var t = target.split('/');
while (s.length && s[0] === t[0]){
Expand All @@ -115,7 +117,7 @@ function makeRelPath(source, target) {
for (var i = 0, l = s.length - 1; i < l; i++) {
t.unshift('..');
}
return t.join('/');
return t.join('/') + targetUrl.search + targetUrl.hash;
}

// exports
Expand Down

0 comments on commit 3ccf932

Please sign in to comment.