Skip to content

fix(core): keep literal backslashes in Unix file names - #60506

Open
xzyangha wants to merge 2 commits into
anomalyco:devfrom
xzyangha:ripgrep-backslash-paths
Open

xzyangha wants to merge 2 commits into
anomalyco:devfrom
xzyangha:ripgrep-backslash-paths

Conversation

@xzyangha

Copy link
Copy Markdown

Issue for this PR

Closes #60307

Type of change

  • Bug fix

What does this PR do?

On Unix a backslash is a legal filename character, but normalizePath in packages/core/src/ripgrep.ts replaced every \ with / on all platforms. glob and grep therefore reported actual/name.txt for a file named actual\name.txt, a path that does not exist, so a model reading or editing the reported result targets the wrong file or fails.

That normalization is only needed on Windows, where ripgrep reports separators as backslashes. The function now keeps literal backslashes and only strips a leading ./ or / elsewhere.

How did you verify your code works?

New test in packages/core/test/ripgrep.test.ts creates actual\name.txt and checks both glob and grep. Before the change it fails:

-   "actual\name.txt",
+   "actual/name.txt",

After the change, cd packages/core && bun test test/ripgrep.test.ts:

14 pass
0 fail
27 expect() calls

bun run typecheck:tsc passes.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

normalizePath replaced every backslash with a slash on all platforms, so glob and grep reported a nonexistent path for files whose name contains a backslash on Unix. Only Windows needs separator normalization.

@opencodejr opencodejr 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.

Looks good. I ran the #60307 reproduction against the real ripgrep service on Linux. On the base, glob and grep report actual/name.txt for a file named actual\name.txt; with this change they report the real name. bun test test/ripgrep.test.ts passes, the new test fails on the base, and typecheck:tsc passes.

glob, find and grep all go through normalizePath, so all three are covered. Windows behaviour is unchanged, and on POSIX the leading ./ and / are still stripped as before.

Public API: unchanged.

No concerns.

@opencodejr opencodejr 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.

The new commit only merges dev, and this pull request's own changes are the same as before. I re-ran the #60307 reproduction on the new head: glob and grep still return the real actual\name.txt. test/ripgrep.test.ts and typecheck:tsc pass.

Public API: unchanged.

No concerns.

This branch has not been deployed

No deployments
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.

core: glob and grep rewrite literal backslashes in Unix filenames

1 participant