Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Empty glob pattern incorrectly expands to "/**" #11476

Merged
merged 2 commits into from Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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