Skip to content

Commit

Permalink
Fix: Empty glob pattern incorrectly expands to "/**" (#11476)
Browse files Browse the repository at this point in the history
* Fix: Empty glob pattern incorrectly expands to "/**"

* Chore: Move empty pattern ignoring to listFilesToProcess

It didn't work inside resolveFileGlobPatterns because that function
needs to return an array of the same length as its input (15d77bd).
  • Loading branch information
bdchauvette authored and btmills committed Mar 15, 2019
1 parent 448e8da commit a5dae7c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/util/glob-utils.js
Expand Up @@ -70,6 +70,10 @@ function processPath(options) {
* @private
*/
return function(pathname) {
if (pathname === "") {
return "";
}

let newPath = pathname;
const resolvedPath = path.resolve(cwd, pathname);

Expand Down Expand Up @@ -201,6 +205,13 @@ function listFilesToProcess(globPatterns, providedOptions) {

debug("Creating list of files to process.");
const resolvedPathsByGlobPattern = resolvedGlobPatterns.map(pattern => {
if (pattern === "") {
return [{
filename: "",
behavior: SILENTLY_IGNORE
}];
}

const file = path.resolve(cwd, pattern);

if (options.globInputPaths === false || (fs.existsSync(file) && fs.statSync(file).isFile())) {
Expand Down Expand Up @@ -240,7 +251,7 @@ function listFilesToProcess(globPatterns, providedOptions) {
});

const allPathDescriptors = resolvedPathsByGlobPattern.reduce((pathsForAllGlobs, pathsForCurrentGlob, index) => {
if (pathsForCurrentGlob.every(pathDescriptor => pathDescriptor.behavior === SILENTLY_IGNORE)) {
if (pathsForCurrentGlob.every(pathDescriptor => pathDescriptor.behavior === SILENTLY_IGNORE && pathDescriptor.filename !== "")) {
throw new (pathsForCurrentGlob.length ? AllFilesIgnoredError : NoFilesFoundError)(globPatterns[index]);
}

Expand Down
7 changes: 7 additions & 0 deletions tests/lib/util/glob-utils.js
Expand Up @@ -329,6 +329,13 @@ describe("globUtils", () => {
}, `No files matching '${patterns[0]}' were found.`);
});

it("should ignore empty patterns", () => {
const patterns = [""];
const result = globUtils.listFilesToProcess(patterns);

assert.deepStrictEqual(result, []);
});

it("should return an ignored file, if ignore option is turned off", () => {
const options = { ignore: false };
const patterns = [getFixturePath("glob-util", "ignored", "**/*.js")];
Expand Down

0 comments on commit a5dae7c

Please sign in to comment.