Skip to content

fix(core): match rule globs against file paths containing spaces - #13170

Open
santhiprakash wants to merge 1 commit into
continuedev:mainfrom
santhiprakash:fix/13135-rule-globs-spaces
Open

fix(core): match rule globs against file paths containing spaces#13170
santhiprakash wants to merge 1 commit into
continuedev:mainfrom
santhiprakash:fix/13135-rule-globs-spaces

Conversation

@santhiprakash

Copy link
Copy Markdown

Description

Rule globs like docs/**/*.md or the exact glob docs/foo bar.md silently failed to match files whose names contain spaces, so any rule whose target files lived under e.g. docs/foo bar.md was excluded from the system prompt.

Root cause

core/llm/utils/extractPathsFromCodeBlocks.ts used the regex /([^\s()]+.[a-zA-Z0-9]+)/to pull a filename out of a code-block header. The character class[^\s()] excluded whitespace, so a header like typescript docs/foo bar.md was truncated to just bar.md. The downstream rule matcher never saw the directory portion, so neither the broad glob (docs/**/*.md) nor the exact glob (docs/foo bar.md) could match.

Fix

Replace the regex with a small parser that strips the optional <lang> tag and the optional trailing (<start>-<end>) line range but preserves any spaces inside the path itself. The heuristic for identifying a language tag is that it must be a single token containing no / or \ (paths almost always contain a separator; language tags like typescript, md, py never do).

Tests

  • New vitest suite at core/llm/utils/extractPathsFromCodeBlocks.vitest.ts covers paths with spaces (with and without language tag, with and without line range, in nested directories).
  • New regression test in core/llm/rules/getSystemMessageWithRules.vitest.ts verifies that docs/**/*.md and the exact glob docs/foo bar.md both apply to a file referenced in a code block.
  • Updated existing Jest test core/llm/utils/extractPathsFromCodeBlocks.test.ts with the same regression cases.

Fixes #13135

Checklist

  • I've read the contributing guide
  • The relevant docs, if any, have been updated or created
  • The relevant tests, if any, have been updated or created

Screen recording or screenshot

N/A — backend correctness fix, no UI surface change.

Tests

  • core/llm/utils/extractPathsFromCodeBlocks.vitest.ts (new, 9 tests)
  • core/llm/rules/getSystemMessageWithRules.vitest.ts (2 new tests added)
  • core/llm/utils/extractPathsFromCodeBlocks.test.ts (regression case added)

All pass locally via node_modules/.bin/vitest run in core/. Verified by reverting the fix and re-running: the new regression tests fail on the original code and pass with the fix in place.

Rule globs like `docs/**/*.md` or the exact glob `docs/foo bar.md`
silently failed to match files whose names contain spaces, so any rule
whose target files lived under `docs/foo bar.md` was excluded from the
system prompt.

The root cause is in extractPathsFromCodeBlocks: its filename regex
excluded whitespace, so a code block header like
```typescript docs/foo bar.md` was truncated to just `bar.md`.
Replace the regex with a small parser that strips the optional language
tag and trailing line range but preserves any spaces inside the path.

Fixes continuedev#13135
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.

Rule globs don't match files with spaces in filename

1 participant