Skip to content

fix(validate-refs): flag single-backslash Windows path leaks#2488

Open
zied-jlassi wants to merge 3 commits into
bmad-code-org:mainfrom
zied-jlassi:fix/abs-path-leak-single-backslash
Open

fix(validate-refs): flag single-backslash Windows path leaks#2488
zied-jlassi wants to merge 3 commits into
bmad-code-org:mainfrom
zied-jlassi:fix/abs-path-leak-single-backslash

Conversation

@zied-jlassi

Copy link
Copy Markdown
Contributor

Problem

The absolute-path-leak check misses normal Windows paths. A pasted C:\Users\me\notes.md
isn't flagged, while /Users/... and /home/... are.

Cause

ABS_PATH_LEAK uses [A-Z]:\\\\. In a regex literal that's two backslashes, so it only
matches the escaped C:\\Users form — single-backslash Windows paths slip through.

Fix

Widen the Windows branch to [A-Z]:[\\/] (drive letter + either separator). Also exported
checkAbsolutePathLeaks so it can be unit-tested, and added test/test-abs-path-leak.js
(wired into npm test) covering the single-backslash case plus the existing Unix /
forward-slash paths and code-block stripping.
Fixes #2487

Testing

  • node test/test-abs-path-leak.js -> 6/6 passed
  • node tools/validate-file-refs.js --strict -> Absolute path leaks: 0, exit 0 (the wider
    pattern adds no new false positives on the repo's own content)

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR fixes a regex bug in tools/validate-file-refs.js where ABS_PATH_LEAK used [A-Z]:\\\\, requiring two backslashes and thus missing real Windows paths like C:\Users\me\notes.md. The pattern is corrected to [A-Z]:[\\/]. checkAbsolutePathLeaks is exported for testability. A new test file (test/test-abs-path-leak.js) and a test:leaks script entry are added.

Changes

Absolute-path-leak regex fix and test coverage

Layer / File(s) Summary
Regex fix and export
tools/validate-file-refs.js
ABS_PATH_LEAK regex changed from [A-Z]:\\\\ to [A-Z]:[\\/] to match single-backslash Windows paths. checkAbsolutePathLeaks added to module.exports alongside extractCsvRefs.
Test script and package.json wiring
test/test-abs-path-leak.js, package.json
New standalone test script with a minimal harness; asserts detection of C:\Users, C:/Users, /Users, /home paths, non-detection of relative paths, and skipping of fenced code blocks. Registered as test:leaks and inserted into the composite test script.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main fix: correcting the Windows path leak detection to handle single-backslash paths, which is the primary change in the PR.
Description check ✅ Passed The description is directly related to the changeset, explaining the problem, cause, fix, and testing approach for the absolute path leak detection improvements.
Linked Issues check ✅ Passed The PR fully addresses issue #2487 by fixing the Windows path regex pattern, exporting the function for testing, and adding comprehensive unit tests covering all path variants.
Out of Scope Changes check ✅ Passed All changes directly support the fix for absolute path leak detection: regex correction, function export for testability, and unit test coverage. No unrelated changes detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tools/validate-file-refs.js`:
- Line 72: The ABS_PATH_LEAK regex pattern only matches Windows drive letters in
uppercase (A-Z) with the pattern [A-Z]:[\/], which fails to detect absolute
paths with lowercase drive letters like c:\Users\me\notes.md. Update the regex
pattern in the ABS_PATH_LEAK constant to include both uppercase and lowercase
letters by changing [A-Z] to [A-Za-z] so that Windows paths with lowercase drive
letters are properly detected.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9e0fdfee-7a9e-4267-94b1-8f2c79e21e41

📥 Commits

Reviewing files that changed from the base of the PR and between 9d5739d and eecb6dd.

📒 Files selected for processing (3)
  • package.json
  • test/test-abs-path-leak.js
  • tools/validate-file-refs.js

Comment thread tools/validate-file-refs.js Outdated
const ABS_PATH_LEAK = /(?:\/Users\/|\/home\/|[A-Z]:\\\\)/;
// Windows drive paths use a single separator (C:\Users or C:/Users). In a regex
// literal `\\` already matches one backslash, so the class matches either separator.
const ABS_PATH_LEAK = /(?:\/Users\/|\/home\/|[A-Z]:[\\/])/;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Detect lowercase Windows drive letters too.

[A-Z]:[\\/] still misses valid paths like c:\Users\me\notes.md, so this validator can still leak false negatives.

Proposed patch
-const ABS_PATH_LEAK = /(?:\/Users\/|\/home\/|[A-Z]:[\\/])/;
+const ABS_PATH_LEAK = /(?:\/Users\/|\/home\/|[A-Za-z]:[\\/])/;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const ABS_PATH_LEAK = /(?:\/Users\/|\/home\/|[A-Z]:[\\/])/;
const ABS_PATH_LEAK = /(?:\/Users\/|\/home\/|[A-Za-z]:[\\/])/;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tools/validate-file-refs.js` at line 72, The ABS_PATH_LEAK regex pattern only
matches Windows drive letters in uppercase (A-Z) with the pattern [A-Z]:[\/],
which fails to detect absolute paths with lowercase drive letters like
c:\Users\me\notes.md. Update the regex pattern in the ABS_PATH_LEAK constant to
include both uppercase and lowercase letters by changing [A-Z] to [A-Za-z] so
that Windows paths with lowercase drive letters are properly detected.

@zied-jlassi

Copy link
Copy Markdown
Contributor Author

Good catch on the lowercase drive letters — fixed in 3df821d.

I went with \b[A-Za-z]:[\\/] rather than a bare [A-Za-z]:[\\/]: without the word boundary the forward-slash branch also matches URL schemes (https:// contains s:/), which flagged ~190 doc lines in a quick scan. The \b keeps real drive paths (c:\, c:/) while skipping https://. Added lowercase + a URL-not-flagged case to the test.

The absolute-path-leak check used `[A-Z]:\\\\`, which in a regex literal
needs two backslashes — so a normal Windows path like C:\Users\... slipped
straight through. Widened it to match either separator (C:\ or C:/).

While here, exported checkAbsolutePathLeaks and added a small test
(test/test-abs-path-leak.js, wired into npm test) covering the
single-backslash case plus the existing Unix and code-block behaviour.
Added JSDoc to the test/assert/leakCount helpers so the new test file
documents its own helpers. No behaviour change — 6/6 still pass.
Following review feedback, widen the Windows branch to [A-Za-z] so
lowercase paths (c:\Users\...) are caught too. Kept a \b anchor so URL
schemes like https:// (which also contain "<letter>:/") aren't flagged —
a plain [A-Za-z] would have matched every URL in the docs.

Added lowercase and URL-not-flagged cases to the test (now 8/8).
@zied-jlassi zied-jlassi force-pushed the fix/abs-path-leak-single-backslash branch from 3df821d to 1c1c6e9 Compare June 24, 2026 16:40
@zied-jlassi

Copy link
Copy Markdown
Contributor Author

Rebased onto the latest main to clear a merge conflict.

  • Conflict was in package.json: main added test:skills to the test chain while this branch added test:leaks — resolved by keeping both (… && test:skills && test:leaks && …).
  • Also adapted test/test-abs-path-leak.js to the unicorn/prefer-string-raw rule that main now enforces (the Windows path literals use String.raw\…``; behaviour unchanged).

Full local run is green: npm test passes (refs/install/urls/channels/skills/leaks + eslint + markdownlint + prettier). CI is green here too. Ready for review whenever you have a moment 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Absolute-path-leak check misses single-backslash Windows paths (C:\Users\...)

1 participant