Skip to content

Commit

Permalink
fix: handle long globs
Browse files Browse the repository at this point in the history
prettier wraps lstat to look for cases where a file does not exist...
When it does not exist, it will try treating the argument as a glob.

For very long globs, the system will return ENAMETOOLONG instead of ENOENT.
This is still a case where the file does not exist and where a glob could
exist.

Instead of letting that error bubble up as an uncaught exception,
swallow it in the same manner as ENOENT.
  • Loading branch information
jsoref committed Apr 26, 2024
1 parent 1264a4c commit 3b4bef6
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelog_unreleased/cli/16115.md
@@ -0,0 +1,3 @@
#### Don’t expand globs via symbolic links (#16115 by @jsoref)

Prettier can now handle long globs.
2 changes: 1 addition & 1 deletion src/cli/utils.js
Expand Up @@ -78,7 +78,7 @@ async function lstatSafe(filePath) {
return await fs.lstat(filePath);
} catch (/** @type {any} */ error) {
/* c8 ignore next 3 */
if (error.code !== "ENOENT") {
if (error.code !== "ENOENT" && error.code !== "ENAMETOOLONG") {
throw error;
}
}
Expand Down
Expand Up @@ -99,3 +99,9 @@ exports[`should not ignore file paths contains object prototype keys (stderr) 1`
exports[`should not ignore file paths contains object prototype keys (stdout) 1`] = `"constructor/should-be-formatted.js"`;

exports[`should not ignore file paths contains object prototype keys (write) 1`] = `[]`;

exports[`fixtures-6: should handle very long globs (stderr) 1`] = `""`;

exports[`fixtures-6: should handle very long globs (stdout) 1`] = `""`;

exports[`fixtures-6: should handle very long globs (write) 1`] = `[]`;
13 changes: 13 additions & 0 deletions tests/integration/__tests__/patterns-glob.js
Expand Up @@ -134,3 +134,16 @@ describe("should not ignore file paths contains object prototype keys", () => {
"-l",
]).test({ status: 1 });
});

describe("fixtures-6: should handle very long globs", () => {
const files = [];
var file = "a";
for (var i = 1 ; i < 9 ; ++i) {
const fileName = file + ".json";
files.push(fileName);
file += file;
}
runCli("cli/patterns-glob/fixtures-6", [
"{" + files.join(",") + "}"
]).test({ status: 0 });
});
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.

0 comments on commit 3b4bef6

Please sign in to comment.