From 872a957c59cc4d1a1bc674b0370c97809d7c595c Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Fri, 18 Nov 2022 14:12:39 -0700 Subject: [PATCH] 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> --- package.json | 4 +-- test/fixtures/has [brackets]/test.foo | 1 + test/index.js | 49 +++++++++++++++++++++------ 3 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 test/fixtures/has [brackets]/test.foo diff --git a/package.json b/package.json index 47da61b..5d450fb 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/test/fixtures/has [brackets]/test.foo b/test/fixtures/has [brackets]/test.foo new file mode 100644 index 0000000..a8a9406 --- /dev/null +++ b/test/fixtures/has [brackets]/test.foo @@ -0,0 +1 @@ +this is a test \ No newline at end of file diff --git a/test/index.js b/test/index.js index 4d3dad7..56e37bc 100644 --- a/test/index.js +++ b/test/index.js @@ -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, @@ -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 ); });