Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ jobs:
- name: Install modules
run: npm install

- name: Audit production dependencies
run: npm audit --omit=dev --audit-level=moderate

- name: Run lint
run: npm run lint

Expand Down
25 changes: 25 additions & 0 deletions __tests__/symlink-security.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ describe("symlink security", () => {
// This test documents the current loadMdFiles behavior.
});

test("loadMdFiles does not recurse through symlinked directories", async () => {
const realDir = path.join(tmpDir, "real");
const nestedDir = path.join(realDir, "nested");
fs.mkdirSync(nestedDir, { recursive: true });
fs.writeFileSync(path.join(nestedDir, "a.md"), "# a");
fs.symlinkSync(realDir, path.join(tmpDir, "link"), "dir");

const result = await loadMdFiles([path.join(tmpDir, "**", "*.md")], []);

expect(result).toEqual([path.join(nestedDir, "a.md")]);
});

test("loadMdFiles deduplicates overlapping patterns", async () => {
const filePath = path.join(tmpDir, "dup.md");
fs.writeFileSync(filePath, "# dup");
Expand Down Expand Up @@ -119,6 +131,19 @@ describe("symlink security", () => {
expect(result).not.toContain(path.join(tmpDir, "b.txt"));
});

test("loadMdFiles excludes directories and ignored files", async () => {
const includedFile = path.join(tmpDir, "included.md");
const ignoredFile = path.join(tmpDir, "ignored.md");
const directory = path.join(tmpDir, "directory.md");
fs.writeFileSync(includedFile, "# included");
fs.writeFileSync(ignoredFile, "# ignored");
fs.mkdirSync(directory);

const result = await loadMdFiles([path.join(tmpDir, "*")], [ignoredFile]);

expect(result).toEqual([includedFile]);
});

test("safeWriteFile rejects symlink", async () => {
const target = path.join(tmpDir, "target.md");
const symlink = path.join(tmpDir, "link.md");
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"name": "@lint-md/cli",
"version": "2.5.0",
"engines": {
"node": ">=20"
},
"description": "CLI tool to lint your markdown file for Chinese.",
"bin": {
"lint-md": "lib/src/lint-md.js"
Expand Down Expand Up @@ -57,7 +60,7 @@
"@lint-md/core": "^2.6.0",
"chalk": "^4",
"commander": "^9.4.1",
"glob": "^13.0.6",
"glob": "^14.0.3",
"piscina": "^5.1.4",
"strip-ansi": "^6.0.1",
"text-table": "^0.2.0"
Expand Down
Loading