Skip to content

Commit

Permalink
fix: Properly handle glob-like characters in paths (#117)
Browse files Browse the repository at this point in the history
chore: Add tests for paths with square brackets
chore: Upgrade to-absolute-glob to properly escape glob-like characters in paths
chore: Update glob to properly support escaped glob-like characters

Co-authored-by: PWall <34860495+PWall2222@users.noreply.github.com>
  • Loading branch information
phated and pwall2222 authored Nov 18, 2022
1 parent f37bccc commit 872a957
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
"test": "nyc mocha --async-only"
},
"dependencies": {
"glob": "^7.2.0",
"glob": "^8.0.3",
"glob-parent": "^6.0.2",
"is-negated-glob": "^1.0.0",
"ordered-read-streams": "^1.0.1",
"pumpify": "^2.0.1",
"readable-stream": "^3.6.0",
"remove-trailing-separator": "^1.1.0",
"to-absolute-glob": "^2.0.2",
"to-absolute-glob": "^3.0.0",
"unique-stream": "^2.3.1"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/has [brackets]/test.foo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is a test
49 changes: 39 additions & 10 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ describe('glob-stream', function () {
);
});

it('finds files in paths that contain ( ) when they match the glob', function (done) {
it('finds files in paths that contain ( ) or [ ] when they match the glob', function (done) {
var expected = [
{
cwd: dir,
Expand All @@ -136,24 +136,53 @@ describe('glob-stream', function () {
{
cwd: dir,
base: dir + '/fixtures',
path: dir + '/fixtures/stuff/run.dmc',
},
{
cwd: dir,
base: dir + '/fixtures',
path: dir + '/fixtures/stuff/test.dmc',
path: dir + '/fixtures/has [brackets]/test.foo',
},
];

function assert(pathObjs) {
expect(pathObjs.length).toEqual(3);
expect(pathObjs.length).toEqual(2);
expect(pathObjs).toContainEqual(expected[0]);
expect(pathObjs).toContainEqual(expected[1]);
expect(pathObjs).toContainEqual(expected[2]);
}

pipe([globStream('./fixtures/has*/*', { cwd: dir }), concat(assert)], done);
});

it('properly handles [ ] in cwd path', function (done) {
var cwd = dir + '/fixtures/has [brackets]';

var expected = {
cwd: cwd,
base: cwd,
path: cwd + '/test.foo',
};

function assert(pathObjs) {
expect(pathObjs.length).toEqual(1);
expect(pathObjs[0]).toEqual(expected);
}

pipe([globStream('*.foo', { cwd: cwd }), concat(assert)], done);
});

it('sets the correct base when [ ] in glob', function (done) {
var expected = {
cwd: dir,
base: dir + '/fixtures/has [brackets]',
path: dir + '/fixtures/has [brackets]/test.foo',
};

function assert(pathObjs) {
expect(pathObjs.length).toEqual(1);
expect(pathObjs[0]).toEqual(expected);
}

pipe(
[globStream('./fixtures/**/*.dmc', { cwd: dir }), concat(assert)],
[
globStream('./fixtures/has \\[brackets\\]/*.foo', { cwd: dir }),
concat(assert),
],
done
);
});
Expand Down

0 comments on commit 872a957

Please sign in to comment.