Fix some path normalization on windows

This commit is contained in:
Samy Pessé
2016-02-25 19:15:47 +01:00
parent 73f22332ec
commit 80718cc783
3 changed files with 11 additions and 3 deletions
+1 -1
View File
@@ -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);
+5 -2
View File
@@ -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));
+5
View File
@@ -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');
});
});
});