summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-02-25 19:15:47 +0100
committerSamy Pessé <samypesse@gmail.com>2016-02-25 19:15:47 +0100
commit80718cc783fae9677dde8bb95cce7db3362db978 (patch)
tree703992775883eda094dff4cb867afd71f436b6fa
parent73f22332ec095ec95518d7708cbeeb3db4a88655 (diff)
downloadgitbook-80718cc783fae9677dde8bb95cce7db3362db978.zip
gitbook-80718cc783fae9677dde8bb95cce7db3362db978.tar.gz
gitbook-80718cc783fae9677dde8bb95cce7db3362db978.tar.bz2
Fix some path normalization on windows
-rw-r--r--lib/page/index.js2
-rw-r--r--lib/utils/location.js7
-rw-r--r--test/location.js5
3 files changed, 11 insertions, 3 deletions
diff --git a/lib/page/index.js b/lib/page/index.js
index 2dcf704..f3a8f39 100644
--- a/lib/page/index.js
+++ b/lib/page/index.js
@@ -30,7 +30,7 @@ function Page(book, filename) {
this.description = '';
// Relative path to the page
- this.path = filename;
+ this.path = location.normalize(filename);
// Absolute path to the page
this.rawPath = this.book.resolve(filename);
diff --git a/lib/utils/location.js b/lib/utils/location.js
index d96cf85..ba0c57d 100644
--- a/lib/utils/location.js
+++ b/lib/utils/location.js
@@ -34,9 +34,12 @@ function normalize(s) {
// dir: directory parent of the file currently in rendering process
// outdir: directory parent from the html output
function toAbsolute(_href, dir, outdir) {
- outdir = outdir == undefined? dir : outdir;
-
if (isExternal(_href)) return _href;
+ outdir = outdir == undefined? dir : outdir;
+
+ _href = normalize(_href);
+ dir = normalize(dir);
+ outdir = normalize(outdir);
// Path "_href" inside the base folder
var hrefInRoot = path.normalize(path.join(dir, _href));
diff --git a/test/location.js b/test/location.js
index 2f209e0..3e2294e 100644
--- a/test/location.js
+++ b/test/location.js
@@ -45,6 +45,11 @@ describe('Location', function() {
location.toAbsolute('/test.md', './', './').should.be.equal('test.md');
location.toAbsolute('/test.md', 'test', 'test').should.be.equal('../test.md');
location.toAbsolute('/sub/test.md', 'test', 'test').should.be.equal('../sub/test.md');
+ location.toAbsolute('/test.png', 'folder', '').should.be.equal('test.png');
+ });
+
+ it('should correctly handle absolute path (windows)', function() {
+ location.toAbsolute('\\test.png', 'folder', '').should.be.equal('test.png');
});
});
});