From 701d348db0d2f76b8eca1eb341591945aac0f7d2 Mon Sep 17 00:00:00 2001 From: Steve Orvell Date: Thu, 22 Aug 2013 16:38:25 -0700 Subject: [PATCH] Make paths relative only if they start the same. --- src/HTMLImports.js | 6 +++++- test/html/imports/abs.html | 1 + test/html/path.html | 22 +++++++++++++++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 test/html/imports/abs.html diff --git a/src/HTMLImports.js b/src/HTMLImports.js index dc2e8e3..c9f2fb4 100644 --- a/src/HTMLImports.js +++ b/src/HTMLImports.js @@ -288,7 +288,7 @@ var path = { return url; } url = this.compressUrl(this.urlToPath(baseUrl) + url); - if (relativeToDocument && !this.isAbsUrl(url)) { + if (relativeToDocument) { url = path.makeRelPath(path.getDocumentUrl(document), url); } return url; @@ -325,6 +325,10 @@ var path = { var s, t; s = this.compressUrl(inSource).split("/"); t = this.compressUrl(inTarget).split("/"); + // bail if target is not relative to source + if (!s.length || s[0] !== t[0]) { + return inTarget; + } while (s.length && s[0] === t[0]){ s.shift(); t.shift(); diff --git a/test/html/imports/abs.html b/test/html/imports/abs.html new file mode 100644 index 0000000..657c769 --- /dev/null +++ b/test/html/imports/abs.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/html/path.html b/test/html/path.html index 55df8cc..59dce3a 100644 --- a/test/html/path.html +++ b/test/html/path.html @@ -6,6 +6,15 @@ +