Fix #357 - Path.resolve() should not crash with missing Path.relative()

This commit is contained in:
David Humphrey (:humph) david.humphrey@senecacollege.ca 2015-06-29 11:38:51 -04:00
parent f338991ace
commit c85fa1851f
3 changed files with 20 additions and 2 deletions

View File

@ -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;

17
tests/bugs/issue357.js Normal file
View File

@ -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');
});
});

View File

@ -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");