Commit e4aafdf9 e4aafdf9a0d47428c5bdae9b0fa7a4407b84b3bd by Nicolas Perriault

fixes #41 - injecting casperjs lib crashes cmd.exe on Windows 7

1 parent 5d79ee63
......@@ -54,7 +54,7 @@ phantom.loadCasper = function() {
}
if (!fs.hasOwnProperty('dirname')) {
fs.dirname = function(path) {
return path.replace(/\/[^\/]*\/?$/, '');
return path.replace(/\\/g, '/').replace(/\/[^\/]*$/, '');
};
}
if (!fs.hasOwnProperty('pathJoin')) {
......@@ -151,7 +151,7 @@ phantom.loadCasper = function() {
}
// trick to locate source file location on error
scriptCode += ";var __fe__ = new CasperError('__sourceId__')";
scriptCode += ";__fe__.fileName = '" + file + "'";
scriptCode += ";__fe__.fileName = '" + file.replace(/\\+/g, '/') + "'";
scriptCode += ";throw __fe__;";
return scriptCode;
};
......@@ -211,7 +211,7 @@ phantom.loadCasper = function() {
paths.push(path);
} else {
dir = fs.absolute(requireDir);
while (dir !== '') {
while (dir !== '' && dir.lastIndexOf(':') !== dir.length - 1) {
// nodejs compatibility
paths.push(fs.pathJoin(dir, 'node_modules', path));
dir = fs.dirname(dir);
......
var fs = require('fs'), t = casper.test;
// Testing added methods
(function() {
t.comment('fs.dirname()');
var tests = {
'/local/plop/foo.js': '/local/plop',
'local/plop/foo.js': 'local/plop',
'./local/plop/foo.js': './local/plop',
'c:\\local\\plop\\foo.js': 'c:/local/plop',
'D:\\local\\plop\\foo.js': 'D:/local/plop',
'D:\\local\\plop\\': 'D:/local/plop',
'c:\\': 'c:',
'c:': 'c:'
};
for (var testCase in tests) {
t.assertEquals(fs.dirname(testCase), tests[testCase], 'fs.dirname() does its job for ' + testCase);
}
})();
t.done();
\ No newline at end of file