Skip to content

Commit

Permalink
Better backslash detection/testing
Browse files Browse the repository at this point in the history
  • Loading branch information
es128 committed Apr 19, 2015
1 parent 365f39c commit 7e55160
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
7 changes: 3 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
'use strict';

var micromatch = require('micromatch');
var arrify = require('arrify');

var platform = process.platform;
var micromatch = require('micromatch');
var path = require('path');

var anymatch = function(criteria, value, returnIndex, startIndex, endIndex) {
criteria = arrify(criteria);
Expand All @@ -17,7 +16,7 @@ var anymatch = function(criteria, value, returnIndex, startIndex, endIndex) {
startIndex = startIndex || 0;
var string = value[0];
var altString;
if (platform === 'win32' && typeof string === 'string') {
if (path.sep === '\\' && typeof string === 'string') {
altString = string.split('\\').join('/');
altString = altString === string ? null : altString;
}
Expand Down
16 changes: 6 additions & 10 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var assert = require('assert');
var path = require('path');
var rewire = require('rewire');

var anymatch = rewire('./');
Expand Down Expand Up @@ -135,17 +136,12 @@ describe('anymatch', function() {
});

describe('windows paths', function() {
anymatch.__set__('platform', 'win32');
var origSep = path.sep;
path.sep = '\\';

// this sucks
var mmUtils = rewire('micromatch/lib/utils');
mmUtils.__set__('win32', true);
var mmExpand = rewire('micromatch/lib/expand');
mmExpand.__set__('utils', mmUtils);
var mm = rewire('micromatch');
mm.__set__('expand', mmExpand);
mm.__set__('utils', mmUtils);
anymatch.__set__('micromatch', mm);
after(function() {
path.sep = origSep;
});

it('should resolve backslashes against string matchers', function() {
assert(anymatch(matchers, 'path\\to\\file.js'));
Expand Down

0 comments on commit 7e55160

Please sign in to comment.