pax_global_header00006660000000000000000000000064141251624070014514gustar00rootroot0000000000000052 comment=26ce5ecec10c687cffb9891c108fb2d2800b9140 glob-parent-6.0.2/000077500000000000000000000000001412516240700137335ustar00rootroot00000000000000glob-parent-6.0.2/.editorconfig000066400000000000000000000003271412516240700164120ustar00rootroot00000000000000# https://editorconfig.org root = true [*] indent_style = space indent_size = 2 charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true end_of_line = lf [*.md] trim_trailing_whitespace = false glob-parent-6.0.2/.eslintrc000066400000000000000000000000301412516240700155500ustar00rootroot00000000000000{ "extends": "gulp" } glob-parent-6.0.2/.gitattributes000066400000000000000000000001561412516240700166300ustar00rootroot00000000000000* text eol=lf # Denote all files that are truly binary and should not be modified. *.png binary *.jpg binary glob-parent-6.0.2/.github/000077500000000000000000000000001412516240700152735ustar00rootroot00000000000000glob-parent-6.0.2/.github/workflows/000077500000000000000000000000001412516240700173305ustar00rootroot00000000000000glob-parent-6.0.2/.github/workflows/dev.yml000066400000000000000000000030621412516240700206320ustar00rootroot00000000000000name: dev on: pull_request: push: branches: - main env: CI: true jobs: prettier: name: Format code runs-on: ubuntu-latest if: ${{ github.event_name == 'push' }} steps: - name: Checkout uses: actions/checkout@v2 - name: Prettier uses: gulpjs/prettier_action@v3.0 with: commit_message: 'chore: Run prettier' prettier_options: '--write .' test: name: Tests for Node ${{ matrix.node }} on ${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: node: [10, 12, 14] os: [ubuntu-latest, windows-latest, macos-latest] steps: - name: Clone repository uses: actions/checkout@v2 - name: Set Node.js version uses: actions/setup-node@v1 with: node-version: ${{ matrix.node }} - run: node --version - run: npm --version - name: Install npm dependencies run: npm install - name: Run lint run: npm run lint - name: Run tests run: npm test - name: Coveralls uses: coverallsapp/github-action@v1.1.2 with: github-token: ${{ secrets.GITHUB_TOKEN }} flag-name: ${{matrix.os}}-node-${{ matrix.node }} parallel: true coveralls: needs: test name: Finish up runs-on: ubuntu-latest steps: - name: Coveralls Finished uses: coverallsapp/github-action@v1.1.2 with: github-token: ${{ secrets.GITHUB_TOKEN }} parallel-finished: true glob-parent-6.0.2/.github/workflows/release.yml000066400000000000000000000004651412516240700215000ustar00rootroot00000000000000name: release on: push: branches: - main jobs: release-please: runs-on: ubuntu-latest steps: - uses: GoogleCloudPlatform/release-please-action@v2 with: token: ${{ secrets.GITHUB_TOKEN }} release-type: node package-name: release-please-action glob-parent-6.0.2/.gitignore000066400000000000000000000012171412516240700157240ustar00rootroot00000000000000# Logs logs *.log # Runtime data pids *.pid *.seed # Directory for instrumented libs generated by jscoverage/JSCover lib-cov # Coverage directory used by tools like istanbul coverage .nyc_output # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) .grunt # Compiled binary addons (https://nodejs.org/api/addons.html) build/Release # Dependency directory # Commenting this out is preferred by some people, see # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- node_modules # Users Environment Variables .lock-wscript # Garbage files .DS_Store # Test results test.xunit glob-parent-6.0.2/.prettierignore000066400000000000000000000000271412516240700167750ustar00rootroot00000000000000coverage/ .nyc_output/ glob-parent-6.0.2/CHANGELOG.md000066400000000000000000000132471412516240700155530ustar00rootroot00000000000000### [5.1.2](https://github.com/gulpjs/glob-parent/compare/v5.1.1...v5.1.2) (2021-03-06) ### Bug Fixes - eliminate ReDoS ([#36](https://github.com/gulpjs/glob-parent/issues/36)) ([f923116](https://github.com/gulpjs/glob-parent/commit/f9231168b0041fea3f8f954b3cceb56269fc6366)) ### [6.0.2](https://www.github.com/gulpjs/glob-parent/compare/v6.0.1...v6.0.2) (2021-09-29) ### Bug Fixes * Improve performance ([#53](https://www.github.com/gulpjs/glob-parent/issues/53)) ([843f8de](https://www.github.com/gulpjs/glob-parent/commit/843f8de1c177e9a5c06c4cfd2349ca5207168e00)) ### [6.0.1](https://www.github.com/gulpjs/glob-parent/compare/v6.0.0...v6.0.1) (2021-07-20) ### Bug Fixes - Resolve ReDoS vulnerability from CVE-2021-35065 ([#49](https://www.github.com/gulpjs/glob-parent/issues/49)) ([3e9f04a](https://www.github.com/gulpjs/glob-parent/commit/3e9f04a3b4349db7e1962d87c9a7398cda51f339)) ## [6.0.0](https://www.github.com/gulpjs/glob-parent/compare/v5.1.2...v6.0.0) (2021-05-03) ### ⚠ BREAKING CHANGES - Correct mishandled escaped path separators (#34) - upgrade scaffold, dropping node <10 support ### Bug Fixes - Correct mishandled escaped path separators ([#34](https://www.github.com/gulpjs/glob-parent/issues/34)) ([32f6d52](https://www.github.com/gulpjs/glob-parent/commit/32f6d52663b7addac38d0dff570d8127edf03f47)), closes [#32](https://www.github.com/gulpjs/glob-parent/issues/32) ### Miscellaneous Chores - upgrade scaffold, dropping node <10 support ([e83d0c5](https://www.github.com/gulpjs/glob-parent/commit/e83d0c5a411947cf69eb58f36349db80439c606f)) ### [5.1.1](https://github.com/gulpjs/glob-parent/compare/v5.1.0...v5.1.1) (2021-01-27) ### Bug Fixes - unescape exclamation mark ([#26](https://github.com/gulpjs/glob-parent/issues/26)) ([a98874f](https://github.com/gulpjs/glob-parent/commit/a98874f1a59e407f4fb1beb0db4efa8392da60bb)) ## [5.1.0](https://github.com/gulpjs/glob-parent/compare/v5.0.0...v5.1.0) (2021-01-27) ### Features - add `flipBackslashes` option to disable auto conversion of slashes (closes [#24](https://github.com/gulpjs/glob-parent/issues/24)) ([#25](https://github.com/gulpjs/glob-parent/issues/25)) ([eecf91d](https://github.com/gulpjs/glob-parent/commit/eecf91d5e3834ed78aee39c4eaaae654d76b87b3)) ## [5.0.0](https://github.com/gulpjs/glob-parent/compare/v4.0.0...v5.0.0) (2021-01-27) ### ⚠ BREAKING CHANGES - Drop support for node <6 & bump dependencies ### Miscellaneous Chores - Drop support for node <6 & bump dependencies ([896c0c0](https://github.com/gulpjs/glob-parent/commit/896c0c00b4e7362f60b96e7fc295ae929245255a)) ## [4.0.0](https://github.com/gulpjs/glob-parent/compare/v3.1.0...v4.0.0) (2021-01-27) ### ⚠ BREAKING CHANGES - question marks are valid path characters on Windows so avoid flagging as a glob when alone - Update is-glob dependency ### Features - hoist regexps and strings for performance gains ([4a80667](https://github.com/gulpjs/glob-parent/commit/4a80667c69355c76a572a5892b0f133c8e1f457e)) - question marks are valid path characters on Windows so avoid flagging as a glob when alone ([2a551dd](https://github.com/gulpjs/glob-parent/commit/2a551dd0dc3235e78bf3c94843d4107072d17841)) - Update is-glob dependency ([e41fcd8](https://github.com/gulpjs/glob-parent/commit/e41fcd895d1f7bc617dba45c9d935a7949b9c281)) ## [3.1.0](https://github.com/gulpjs/glob-parent/compare/v3.0.1...v3.1.0) (2021-01-27) ### Features - allow basic win32 backslash use ([272afa5](https://github.com/gulpjs/glob-parent/commit/272afa5fd070fc0f796386a5993d4ee4a846988b)) - handle extglobs (parentheses) containing separators ([7db1bdb](https://github.com/gulpjs/glob-parent/commit/7db1bdb0756e55fd14619e8ce31aa31b17b117fd)) - new approach to braces/brackets handling ([8269bd8](https://github.com/gulpjs/glob-parent/commit/8269bd89290d99fac9395a354fb56fdcdb80f0be)) - pre-process braces/brackets sections ([9ef8a87](https://github.com/gulpjs/glob-parent/commit/9ef8a87f66b1a43d0591e7a8e4fc5a18415ee388)) - preserve escaped brace/bracket at end of string ([8cfb0ba](https://github.com/gulpjs/glob-parent/commit/8cfb0ba84202d51571340dcbaf61b79d16a26c76)) ### Bug Fixes - trailing escaped square brackets ([99ec9fe](https://github.com/gulpjs/glob-parent/commit/99ec9fecc60ee488ded20a94dd4f18b4f55c4ccf)) ### [3.0.1](https://github.com/gulpjs/glob-parent/compare/v3.0.0...v3.0.1) (2021-01-27) ### Features - use path-dirname ponyfill ([cdbea5f](https://github.com/gulpjs/glob-parent/commit/cdbea5f32a58a54e001a75ddd7c0fccd4776aacc)) ### Bug Fixes - unescape glob-escaped dirnames on output ([598c533](https://github.com/gulpjs/glob-parent/commit/598c533bdf49c1428bc063aa9b8db40c5a86b030)) ## [3.0.0](https://github.com/gulpjs/glob-parent/compare/v2.0.0...v3.0.0) (2021-01-27) ### ⚠ BREAKING CHANGES - update is-glob dependency ### Features - update is-glob dependency ([5c5f8ef](https://github.com/gulpjs/glob-parent/commit/5c5f8efcee362a8e7638cf8220666acd8784f6bd)) ## [2.0.0](https://github.com/gulpjs/glob-parent/compare/v1.3.0...v2.0.0) (2021-01-27) ### Features - move up to dirname regardless of glob characters ([f97fb83](https://github.com/gulpjs/glob-parent/commit/f97fb83be2e0a9fc8d3b760e789d2ecadd6aa0c2)) ## [1.3.0](https://github.com/gulpjs/glob-parent/compare/v1.2.0...v1.3.0) (2021-01-27) ## [1.2.0](https://github.com/gulpjs/glob-parent/compare/v1.1.0...v1.2.0) (2021-01-27) ### Reverts - feat: make regex test strings smaller ([dc80fa9](https://github.com/gulpjs/glob-parent/commit/dc80fa9658dca20549cfeba44bbd37d5246fcce0)) ## [1.1.0](https://github.com/gulpjs/glob-parent/compare/v1.0.0...v1.1.0) (2021-01-27) ### Features - make regex test strings smaller ([cd83220](https://github.com/gulpjs/glob-parent/commit/cd832208638f45169f986d80fcf66e401f35d233)) ## 1.0.0 (2021-01-27) glob-parent-6.0.2/LICENSE000066400000000000000000000015311412516240700147400ustar00rootroot00000000000000The ISC License Copyright (c) 2015, 2019 Elan Shanker, 2021 Blaine Bublitz , Eric Schoffstall and other contributors Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. glob-parent-6.0.2/README.md000066400000000000000000000101461412516240700152140ustar00rootroot00000000000000

# glob-parent [![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][ci-image]][ci-url] [![Coveralls Status][coveralls-image]][coveralls-url] Extract the non-magic parent path from a glob string. ## Usage ```js var globParent = require('glob-parent'); globParent('path/to/*.js'); // 'path/to' globParent('/root/path/to/*.js'); // '/root/path/to' globParent('/*.js'); // '/' globParent('*.js'); // '.' globParent('**/*.js'); // '.' globParent('path/{to,from}'); // 'path' globParent('path/!(to|from)'); // 'path' globParent('path/?(to|from)'); // 'path' globParent('path/+(to|from)'); // 'path' globParent('path/*(to|from)'); // 'path' globParent('path/@(to|from)'); // 'path' globParent('path/**/*'); // 'path' // if provided a non-glob path, returns the nearest dir globParent('path/foo/bar.js'); // 'path/foo' globParent('path/foo/'); // 'path/foo' globParent('path/foo'); // 'path' (see issue #3 for details) ``` ## API ### `globParent(maybeGlobString, [options])` Takes a string and returns the part of the path before the glob begins. Be aware of Escaping rules and Limitations below. #### options ```js { // Disables the automatic conversion of slashes for Windows flipBackslashes: true; } ``` ## Escaping The following characters have special significance in glob patterns and must be escaped if you want them to be treated as regular path characters: - `?` (question mark) unless used as a path segment alone - `*` (asterisk) - `|` (pipe) - `(` (opening parenthesis) - `)` (closing parenthesis) - `{` (opening curly brace) - `}` (closing curly brace) - `[` (opening bracket) - `]` (closing bracket) **Example** ```js globParent('foo/[bar]/'); // 'foo' globParent('foo/\\[bar]/'); // 'foo/[bar]' ``` ## Limitations ### Braces & Brackets This library attempts a quick and imperfect method of determining which path parts have glob magic without fully parsing/lexing the pattern. There are some advanced use cases that can trip it up, such as nested braces where the outer pair is escaped and the inner one contains a path separator. If you find yourself in the unlikely circumstance of being affected by this or need to ensure higher-fidelity glob handling in your library, it is recommended that you pre-process your input with [expand-braces] and/or [expand-brackets]. ### Windows Backslashes are not valid path separators for globs. If a path with backslashes is provided anyway, for simple cases, glob-parent will replace the path separator for you and return the non-glob parent path (now with forward-slashes, which are still valid as Windows path separators). This cannot be used in conjunction with escape characters. ```js // BAD globParent('C:\\Program Files \\(x86\\)\\*.ext'); // 'C:/Program Files /(x86/)' // GOOD globParent('C:/Program Files\\(x86\\)/*.ext'); // 'C:/Program Files (x86)' ``` If you are using escape characters for a pattern without path parts (i.e. relative to `cwd`), prefix with `./` to avoid confusing glob-parent. ```js // BAD globParent('foo \\[bar]'); // 'foo ' globParent('foo \\[bar]*'); // 'foo ' // GOOD globParent('./foo \\[bar]'); // 'foo [bar]' globParent('./foo \\[bar]*'); // '.' ``` ## License ISC [downloads-image]: https://img.shields.io/npm/dm/glob-parent.svg?style=flat-square [npm-url]: https://www.npmjs.com/package/glob-parent [npm-image]: https://img.shields.io/npm/v/glob-parent.svg?style=flat-square [ci-url]: https://github.com/gulpjs/glob-parent/actions?query=workflow:dev [ci-image]: https://img.shields.io/github/workflow/status/gulpjs/glob-parent/dev?style=flat-square [coveralls-url]: https://coveralls.io/r/gulpjs/glob-parent [coveralls-image]: https://img.shields.io/coveralls/gulpjs/glob-parent/master.svg?style=flat-square [expand-braces]: https://github.com/jonschlinkert/expand-braces [expand-brackets]: https://github.com/jonschlinkert/expand-brackets glob-parent-6.0.2/index.js000066400000000000000000000031161412516240700154010ustar00rootroot00000000000000'use strict'; var isGlob = require('is-glob'); var pathPosixDirname = require('path').posix.dirname; var isWin32 = require('os').platform() === 'win32'; var slash = '/'; var backslash = /\\/g; var escaped = /\\([!*?|[\](){}])/g; /** * @param {string} str * @param {Object} opts * @param {boolean} [opts.flipBackslashes=true] */ module.exports = function globParent(str, opts) { var options = Object.assign({ flipBackslashes: true }, opts); // flip windows path separators if (options.flipBackslashes && isWin32 && str.indexOf(slash) < 0) { str = str.replace(backslash, slash); } // special case for strings ending in enclosure containing path separator if (isEnclosure(str)) { str += slash; } // preserves full path in case of trailing path separator str += 'a'; // remove path parts that are globby do { str = pathPosixDirname(str); } while (isGlobby(str)); // remove escape chars and return result return str.replace(escaped, '$1'); }; function isEnclosure(str) { var lastChar = str.slice(-1); var enclosureStart; switch (lastChar) { case '}': enclosureStart = '{'; break; case ']': enclosureStart = '['; break; default: return false; } var foundIndex = str.indexOf(enclosureStart); if (foundIndex < 0) { return false; } return str.slice(foundIndex + 1, -1).includes(slash); } function isGlobby(str) { if (/\([^()]+$/.test(str)) { return true; } if (str[0] === '{' || str[0] === '[') { return true; } if (/[^\\][{[]/.test(str)) { return true; } return isGlob(str); } glob-parent-6.0.2/package.json000066400000000000000000000020321412516240700162160ustar00rootroot00000000000000{ "name": "glob-parent", "version": "6.0.2", "description": "Extract the non-magic parent path from a glob string.", "author": "Gulp Team (https://gulpjs.com/)", "contributors": [ "Elan Shanker (https://github.com/es128)", "Blaine Bublitz " ], "repository": "gulpjs/glob-parent", "license": "ISC", "engines": { "node": ">=10.13.0" }, "main": "index.js", "files": [ "LICENSE", "index.js" ], "scripts": { "lint": "eslint .", "pretest": "npm run lint", "test": "nyc mocha --async-only" }, "dependencies": { "is-glob": "^4.0.3" }, "devDependencies": { "eslint": "^7.0.0", "eslint-config-gulp": "^5.0.0", "expect": "^26.0.1", "mocha": "^7.1.2", "nyc": "^15.0.1" }, "nyc": { "reporter": [ "lcov", "text-summary" ] }, "prettier": { "singleQuote": true }, "keywords": [ "glob", "parent", "strip", "path", "dirname", "directory", "base", "wildcard" ] } glob-parent-6.0.2/test/000077500000000000000000000000001412516240700147125ustar00rootroot00000000000000glob-parent-6.0.2/test/.gitkeep000066400000000000000000000000001412516240700163310ustar00rootroot00000000000000glob-parent-6.0.2/test/index.test.js000066400000000000000000000220011412516240700173300ustar00rootroot00000000000000'use strict'; var gp = require('../'); var expect = require('expect'); var isWin32 = require('os').platform() === 'win32'; describe('glob-parent', function () { it('should strip glob magic to return parent path', function (done) { expect(gp('.')).toEqual('.'); expect(gp('.*')).toEqual('.'); expect(gp('/.*')).toEqual('/'); expect(gp('/.*/')).toEqual('/'); expect(gp('a/.*/b')).toEqual('a'); expect(gp('a*/.*/b')).toEqual('.'); expect(gp('*/a/b/c')).toEqual('.'); expect(gp('*')).toEqual('.'); expect(gp('*/')).toEqual('.'); expect(gp('*/*')).toEqual('.'); expect(gp('*/*/')).toEqual('.'); expect(gp('**')).toEqual('.'); expect(gp('**/')).toEqual('.'); expect(gp('**/*')).toEqual('.'); expect(gp('**/*/')).toEqual('.'); expect(gp('/*.js')).toEqual('/'); expect(gp('*.js')).toEqual('.'); expect(gp('**/*.js')).toEqual('.'); expect(gp('{a,b}')).toEqual('.'); expect(gp('/{a,b}')).toEqual('/'); expect(gp('/{a,b}/')).toEqual('/'); expect(gp('(a|b)')).toEqual('.'); expect(gp('/(a|b)')).toEqual('/'); expect(gp('./(a|b)')).toEqual('.'); expect(gp('a/(b c)')).toEqual('a'); // not an extglob expect(gp('a/(b c)/')).toEqual('a/(b c)'); // not an extglob expect(gp('a/(b c)/d')).toEqual('a/(b c)'); // not an extglob expect(gp('path/to/*.js')).toEqual('path/to'); expect(gp('/root/path/to/*.js')).toEqual('/root/path/to'); expect(gp('chapter/foo [bar]/')).toEqual('chapter'); expect(gp('path/[a-z]')).toEqual('path'); expect(gp('[a-z]')).toEqual('.'); expect(gp('path/{to,from}')).toEqual('path'); expect(gp('path/(to|from)')).toEqual('path'); expect(gp('path/(foo bar)/subdir/foo.*')).toEqual('path/(foo bar)/subdir'); expect(gp('path/!(to|from)')).toEqual('path'); expect(gp('path/?(to|from)')).toEqual('path'); expect(gp('path/+(to|from)')).toEqual('path'); expect(gp('path/*(to|from)')).toEqual('path'); expect(gp('path/@(to|from)')).toEqual('path'); expect(gp('path/!/foo')).toEqual('path/!'); expect(gp('path/?/foo')).toEqual('path/?'); expect(gp('path/+/foo')).toEqual('path/+'); expect(gp('path/*/foo')).toEqual('path'); expect(gp('path/@/foo')).toEqual('path/@'); expect(gp('path/!/foo/')).toEqual('path/!/foo'); expect(gp('path/?/foo/')).toEqual('path/?/foo'); expect(gp('path/+/foo/')).toEqual('path/+/foo'); expect(gp('path/*/foo/')).toEqual('path'); expect(gp('path/@/foo/')).toEqual('path/@/foo'); expect(gp('path/**/*')).toEqual('path'); expect(gp('path/**/subdir/foo.*')).toEqual('path'); expect(gp('path/subdir/**/foo.js')).toEqual('path/subdir'); expect(gp('path/!subdir/foo.js')).toEqual('path/!subdir'); expect(gp('path/{foo,bar}/')).toEqual('path'); done(); }); it('should respect escaped characters', function (done) { expect(gp('path/\\*\\*/subdir/foo.*')).toEqual('path/**/subdir'); expect(gp('path/\\[\\*\\]/subdir/foo.*')).toEqual('path/[*]/subdir'); expect(gp('path/\\*(a|b)/subdir/foo.*')).toEqual('path'); expect(gp('path/\\*/(a|b)/subdir/foo.*')).toEqual('path/*'); expect(gp('path/\\*\\(a\\|b\\)/subdir/foo.*')).toEqual( 'path/*(a|b)/subdir' ); expect(gp('path/\\[foo bar\\]/subdir/foo.*')).toEqual( 'path/[foo bar]/subdir' ); expect(gp('path/\\[bar]/')).toEqual('path/[bar]'); expect(gp('path/\\[bar]')).toEqual('path'); expect(gp('[bar]')).toEqual('.'); expect(gp('[bar]/')).toEqual('.'); expect(gp('./\\[bar]')).toEqual('.'); expect(gp('\\[bar]/')).toEqual('[bar]'); expect(gp('\\!dir/*')).toEqual('!dir'); expect(gp('[bar\\]/')).toEqual('.'); expect(gp('path/foo \\[bar]/')).toEqual('path/foo [bar]'); expect(gp('path/\\{foo,bar}/')).toEqual('path/{foo,bar}'); expect(gp('\\{foo,bar}/')).toEqual('{foo,bar}'); expect(gp('\\{foo,bar\\}/')).toEqual('{foo,bar}'); expect(gp('{foo,bar\\}/')).toEqual('.'); if (isWin32) { // On Windows we are trying to flip backslashes foo-\\( → foo-/( expect(gp('foo-\\(bar\\).md')).toEqual('foo-'); } else { expect(gp('foo-\\(bar\\).md')).toEqual('.'); expect(gp('\\[bar]')).toEqual('.'); expect(gp('[bar\\]')).toEqual('.'); expect(gp('\\{foo,bar\\}')).toEqual('.'); expect(gp('{foo,bar\\}')).toEqual('.'); } done(); }); it('should respect glob enclosures with embedded separators', function (done) { /* eslint-disable no-useless-escape */ expect(gp('path/{,/,bar/baz,qux}/')).toEqual('path'); expect(gp('path/\\{,/,bar/baz,qux}/')).toEqual('path/{,/,bar/baz,qux}'); expect(gp('path/\\{,/,bar/baz,qux\\}/')).toEqual('path/{,/,bar/baz,qux}'); expect(gp('/{,/,bar/baz,qux}/')).toEqual('/'); expect(gp('/\\{,/,bar/baz,qux}/')).toEqual('/{,/,bar/baz,qux}'); expect(gp('{,/,bar/baz,qux}')).toEqual('.'); expect(gp('\\{,/,bar/baz,qux\\}')).toEqual('{,/,bar/baz,qux}'); expect(gp('\\{,/,bar/baz,qux}/')).toEqual('{,/,bar/baz,qux}'); expect(gp('path/foo[a\\/]/')).toEqual('path'); expect(gp('path/foo\\[a\\/]/')).toEqual('path/foo[a\\/]'); expect(gp('foo[a\\/]')).toEqual('.'); expect(gp('foo\\[a\\/]')).toEqual('foo[a\\/]'); expect(gp('path/(foo/bar|baz)')).toEqual('path'); expect(gp('path/(foo/bar|baz)/')).toEqual('path'); expect(gp('path/\\(foo/bar|baz)/')).toEqual('path/(foo/bar|baz)'); /* eslint-enable no-useless-escape */ done(); }); it('should handle nested braces', function (done) { expect(gp('path/{../,./,{bar,/baz\\},qux\\}/')).toEqual('path'); expect(gp('path/{../,./,\\{bar,/baz},qux}/')).toEqual('path'); expect(gp('path/\\{../,./,\\{bar,/baz\\},qux\\}/')).toEqual( 'path/{../,./,{bar,/baz},qux}' ); expect(gp('{../,./,{bar,/baz\\},qux\\}/')).toEqual('.'); expect(gp('{../,./,{bar,/baz\\},qux\\}')).toEqual('.'); expect(gp('path/{,/,bar/{baz,qux\\}}/')).toEqual('path'); expect(gp('path/{,/,bar/{baz,qux}\\}/')).toEqual('path'); // expect(gp('path/\\{../,./,{bar,/baz},qux}/')).toEqual('path'); done(); }); it('should return parent dirname from non-glob paths', function (done) { expect(gp('path')).toEqual('.'); expect(gp('path/foo')).toEqual('path'); expect(gp('path/foo/')).toEqual('path/foo'); expect(gp('path/foo/bar.js')).toEqual('path/foo'); done(); }); it('should respect disabled auto flip backslashes', function (done) { expect(gp('foo-\\(bar\\).md', { flipBackslashes: false })).toEqual('.'); done(); }); }); describe('glob2base test patterns', function () { it('should get a base name', function (done) { expect(gp('js/*.js')).toEqual('js'); done(); }); it('should get a base name from a nested glob', function (done) { expect(gp('js/**/test/*.js')).toEqual('js'); done(); }); it('should get a base name from a flat file', function (done) { expect(gp('js/test/wow.js')).toEqual('js/test'); expect(gp('js/test/wow.js')).toEqual('js/test'); done(); }); it('should get a base name from character class pattern', function (done) { expect(gp('js/t[a-z]st}/*.js')).toEqual('js'); done(); }); it('should get a base name from brace , expansion', function (done) { expect(gp('js/{src,test}/*.js')).toEqual('js'); done(); }); it('should get a base name from brace .. expansion', function (done) { expect(gp('js/test{0..9}/*.js')).toEqual('js'); done(); }); it('should get a base name from extglob', function (done) { expect(gp('js/t+(wo|est)/*.js')).toEqual('js'); done(); }); it('should get a base name from a path with non-exglob parens', function (done) { expect(gp('js/t(wo|est)/*.js')).toEqual('js'); expect(gp('js/t/(wo|est)/*.js')).toEqual('js/t'); done(); }); it('should get a base name from a complex brace glob', function (done) { expect(gp('lib/{components,pages}/**/{test,another}/*.txt')).toEqual('lib'); expect(gp('js/test/**/{images,components}/*.js')).toEqual('js/test'); expect(gp('ooga/{booga,sooga}/**/dooga/{eooga,fooga}')).toEqual('ooga'); done(); }); it('should not be susceptible to SNYK-JS-GLOBPARENT-1016905', function (done) { // This will time out if susceptible. gp('{' + '/'.repeat(5000)); done(); }); it("should finish in reasonable time for '{' + '/'.repeat(n) [CVE-2021-35065]", function (done) { this.timeout(1000); gp('{' + '/'.repeat(500000)); done(); }); it("should finish in reasonable time for '{'.repeat(n)", function (done) { this.timeout(1000); gp('{'.repeat(500000)); done(); }); it("should finish in reasonable time for '('.repeat(n)", function (done) { this.timeout(1000); gp('('.repeat(500000)); done(); }); it("should finish in reasonable time for '/('.repeat(n) + ')'", function (done) { this.timeout(1000); gp('/('.repeat(500000) + ')'); done(); }); }); if (isWin32) { describe('technically invalid windows globs', function () { it('should manage simple globs with backslash path separator', function (done) { expect(gp('C:\\path\\*.js')).toEqual('C:/path'); done(); }); }); }