diff --git a/src/path.js b/src/path.js index a3e0f25..87c57f7 100644 --- a/src/path.js +++ b/src/path.js @@ -120,8 +120,8 @@ function join() { // path.relative(from, to) function relative(from, to) { - from = exports.resolve(from).substr(1); - to = exports.resolve(to).substr(1); + from = resolve(from).substr(1); + to = resolve(to).substr(1); function trim(arr) { var start = 0; diff --git a/tests/bugs/issue357.js b/tests/bugs/issue357.js new file mode 100644 index 0000000..e494ff4 --- /dev/null +++ b/tests/bugs/issue357.js @@ -0,0 +1,17 @@ +var Path = require('../..').Path; +var expect = require('chai').expect; + +describe('Path.resolve does not work, issue357', function() { + it('Path.relative() should not crash', function() { + expect(Path.relative("/mydir", "/mydir/file")).to.equal("file"); + + // https://nodejs.org/api/path.html#path_path_relative_from_to + expect(Path.relative("/data/orandea/test/aaa", "/data/orandea/impl/bbb")).to.equal("../../impl/bbb"); + }); + + it('Path.resolve() should work as expectedh', function() { + // https://nodejs.org/api/path.html#path_path_resolve_from_to + expect(Path.resolve('/foo/bar', './baz')).to.equal('/foo/bar/baz'); + expect(Path.resolve('/foo/bar', '/tmp/file/')).to.equal('/tmp/file'); + }); +}); diff --git a/tests/index.js b/tests/index.js index ec2b849..c9743ad 100644 --- a/tests/index.js +++ b/tests/index.js @@ -76,3 +76,4 @@ require("./bugs/issue258.js"); require("./bugs/issue267.js"); require("./bugs/issue270.js"); require("./bugs/rename-dir-trailing-slash.js"); +require("./bugs/issue357.js");