Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Better basedir.

  • Loading branch information...
commit 19ea629590e3c7802926255c7174f5dd66bddb8e 1 parent 8c70958
mde authored
Showing with 20 additions and 7 deletions.
  1. +10 −2 lib/utils/file.js
  2. +10 −5 tests/file_utils.js
View
12 lib/utils/file.js
@@ -246,8 +246,16 @@ var fileUtils = new (function () {
if (abs) {
return abs;
}
- str = str.replace(/\*/g, '').split('/')[0];
- return str || '.';
+ // Split into segments
+ str = str.split(/\\|\//)[0];
+ // If the path has a leading asterisk, basedir is the current dir
+ if (str.indexOf('*') > -1) {
+ return '.';
+ }
+ // Otherwise it's the first segment in the path
+ else {
+ return str;
+ }
};
})();
View
15 tests/file_utils.js
@@ -44,27 +44,32 @@ var tests = {
assert.equal('/', fileUtils.basedir(p));
}
-, 'test basedir with Unix absolute path and globstar': function () {
+, 'test basedir with Unix absolute path and double-asterisk': function () {
var p = '/**/foo/bar/baz';
assert.equal('/', fileUtils.basedir(p));
}
-, 'test basedir with leading globstar': function () {
+, 'test basedir with leading double-asterisk': function () {
var p = '**/foo';
assert.equal('.', fileUtils.basedir(p));
}
-, 'test basedir with leading dot-slash and globstar': function () {
+, 'test basedir with leading asterisk': function () {
+ var p = '*.js';
+ assert.equal('.', fileUtils.basedir(p));
+ }
+
+, 'test basedir with leading dot-slash and double-asterisk': function () {
var p = './**/foo';
assert.equal('.', fileUtils.basedir(p));
}
-, 'test basedir with leading dirname and globstar': function () {
+, 'test basedir with leading dirname and double-asterisk': function () {
var p = 'a/**/*.js';
assert.equal('a', fileUtils.basedir(p));
}
-, 'test basedir with leading dot-dot-slash and globstar': function () {
+, 'test basedir with leading dot-dot-slash and double-asterisk': function () {
var p = '../test/**/*.js';
assert.equal('..', fileUtils.basedir(p));
}
Please sign in to comment.
Something went wrong with that request. Please try again.