Skip to content

Commit 872a957

Browse files
phatedpwall2222
andauthoredNov 18, 2022
fix: Properly handle glob-like characters in paths (#117)
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>
1 parent f37bccc commit 872a957

File tree

3 files changed

+42
-12
lines changed

3 files changed

+42
-12
lines changed
 

‎package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
"test": "nyc mocha --async-only"
2525
},
2626
"dependencies": {
27-
"glob": "^7.2.0",
27+
"glob": "^8.0.3",
2828
"glob-parent": "^6.0.2",
2929
"is-negated-glob": "^1.0.0",
3030
"ordered-read-streams": "^1.0.1",
3131
"pumpify": "^2.0.1",
3232
"readable-stream": "^3.6.0",
3333
"remove-trailing-separator": "^1.1.0",
34-
"to-absolute-glob": "^2.0.2",
34+
"to-absolute-glob": "^3.0.0",
3535
"unique-stream": "^2.3.1"
3636
},
3737
"devDependencies": {

‎test/fixtures/has [brackets]/test.foo

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this is a test

‎test/index.js

+39-10
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ describe('glob-stream', function () {
126126
);
127127
});
128128

129-
it('finds files in paths that contain ( ) when they match the glob', function (done) {
129+
it('finds files in paths that contain ( ) or [ ] when they match the glob', function (done) {
130130
var expected = [
131131
{
132132
cwd: dir,
@@ -136,24 +136,53 @@ describe('glob-stream', function () {
136136
{
137137
cwd: dir,
138138
base: dir + '/fixtures',
139-
path: dir + '/fixtures/stuff/run.dmc',
140-
},
141-
{
142-
cwd: dir,
143-
base: dir + '/fixtures',
144-
path: dir + '/fixtures/stuff/test.dmc',
139+
path: dir + '/fixtures/has [brackets]/test.foo',
145140
},
146141
];
147142

148143
function assert(pathObjs) {
149-
expect(pathObjs.length).toEqual(3);
144+
expect(pathObjs.length).toEqual(2);
150145
expect(pathObjs).toContainEqual(expected[0]);
151146
expect(pathObjs).toContainEqual(expected[1]);
152-
expect(pathObjs).toContainEqual(expected[2]);
147+
}
148+
149+
pipe([globStream('./fixtures/has*/*', { cwd: dir }), concat(assert)], done);
150+
});
151+
152+
it('properly handles [ ] in cwd path', function (done) {
153+
var cwd = dir + '/fixtures/has [brackets]';
154+
155+
var expected = {
156+
cwd: cwd,
157+
base: cwd,
158+
path: cwd + '/test.foo',
159+
};
160+
161+
function assert(pathObjs) {
162+
expect(pathObjs.length).toEqual(1);
163+
expect(pathObjs[0]).toEqual(expected);
164+
}
165+
166+
pipe([globStream('*.foo', { cwd: cwd }), concat(assert)], done);
167+
});
168+
169+
it('sets the correct base when [ ] in glob', function (done) {
170+
var expected = {
171+
cwd: dir,
172+
base: dir + '/fixtures/has [brackets]',
173+
path: dir + '/fixtures/has [brackets]/test.foo',
174+
};
175+
176+
function assert(pathObjs) {
177+
expect(pathObjs.length).toEqual(1);
178+
expect(pathObjs[0]).toEqual(expected);
153179
}
154180

155181
pipe(
156-
[globStream('./fixtures/**/*.dmc', { cwd: dir }), concat(assert)],
182+
[
183+
globStream('./fixtures/has \\[brackets\\]/*.foo', { cwd: dir }),
184+
concat(assert),
185+
],
157186
done
158187
);
159188
});

0 commit comments

Comments
 (0)
Please sign in to comment.