Skip to content
Open
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
8 changes: 4 additions & 4 deletions packages/core/src/ripgrep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ export class Service extends Context.Service<Service, Interface>()("@opencode/Ri

const failure = (message: string, cause?: unknown) => new Error({ message, cause })

// A backslash is a literal character in Unix file names; only Windows reports separators that way.
const normalizePath = (value: string) =>
value
.replace(/^(?:\.[\\/])+/u, "")
.replace(/^[\\/]+/u, "")
.replaceAll("\\", "/")
process.platform === "win32"
? value.replace(/^(?:\.[\\/])+/u, "").replace(/^[\\/]+/u, "").replaceAll("\\", "/")
: value.replace(/^(?:\.\/)+/u, "").replace(/^\/+/u, "")

const isInvalidPattern = (stderr: string) =>
stderr.includes("regex parse error") || stderr.includes("error parsing regex")
Expand Down
21 changes: 21 additions & 0 deletions packages/core/test/ripgrep.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,27 @@ describe("Ripgrep", () => {
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
),
)

const posixOnly = process.platform === "win32" ? it.live.skip : it.live

posixOnly("keeps literal backslashes in Unix file names", () =>
Effect.acquireUseRelease(
Effect.promise(() => tmpdir()),
(tmp) =>
Effect.gen(function* () {
const file = "actual\\name.txt"
yield* Effect.promise(() => fs.writeFile(path.join(tmp.path, file), "needle\n"))

const ripgrep = yield* Ripgrep.Service
const files = yield* ripgrep.glob({ cwd: tmp.path, pattern: "*.txt", limit: 10 })
expect(files.map((item) => item.path)).toEqual([RelativePath.make(file)])

const matches = yield* ripgrep.grep({ cwd: tmp.path, pattern: "needle", limit: 10 })
expect(matches.map((item) => item.entry.path)).toEqual([RelativePath.make(file)])
}),
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
),
)
})

describe("RipgrepBinary.verify", () => {
Expand Down
Loading