Merge pull request #2273 from knoxHuang/v1.8

fix cc.path.dirname bug
This commit is contained in:
Jare Guo
2018-01-18 17:30:47 +08:00
committed by GitHub
2 changed files with 15 additions and 1 deletions
+3 -1
View File
@@ -26,6 +26,7 @@
require('../platform/CCSys');
var EXTNAME_RE = /(\.[^\.\/\?\\]*)(\?.*)?$/;
var DIRNAME_RE = /((.*)(\/|\\|\\\\))?(.*?\..*$)?/;
var NORMALIZE_RE = /[^\.\/]+\/\.\.\//;
/**
@@ -104,7 +105,8 @@ cc.path = /** @lends cc.path# */{
* @returns {*}
*/
dirname: function (pathStr) {
return pathStr.replace(/((.*)(\/|\\|\\\\))?(.*?\..*$)?/, '$2');
var temp = DIRNAME_RE.exec(pathStr);
return temp ? temp[2] : '';
},
/**
+12
View File
@@ -0,0 +1,12 @@
module('cc.path', SetupEngine);
test('dirname', function () {
ok(cc.path.dirname('aa/bb/cc') === 'aa/bb', 'get success');
ok(cc.path.dirname('aa/bb/cc.png') === 'aa/bb', 'get success');
ok(cc.path.dirname('aa/bb/cc/') === 'aa/bb/cc', 'get success');
ok(cc.path.dirname('aa/bb/cc.png/ee.png') === 'aa/bb/cc.png', 'get success');
ok(cc.path.dirname('D:\\aa\\bb') === 'D:\\aa', 'get success');
ok(cc.path.dirname('aa/bb/.github/.gitignore') === 'aa/bb/.github', 'get success');
});