Skip to content

Commit 1267d6f

Browse files
committed
fix: handle paths outside cwd in RooProtectedController to prevent RangeError
- Add check for paths starting with ".." before calling ignore library - Return false (not protected) for paths outside the cwd - Add test cases to verify paths outside cwd are handled gracefully - Fixes #6583
1 parent 8513263 commit 1267d6f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/core/protect/RooProtectedController.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ export class RooProtectedController {
4141
const absolutePath = path.resolve(this.cwd, filePath)
4242
const relativePath = path.relative(this.cwd, absolutePath).toPosix()
4343

44+
// Check if the path goes outside the cwd (starts with ..)
45+
if (relativePath.startsWith("..")) {
46+
// Paths outside the cwd are not protected
47+
return false
48+
}
49+
4450
// Use ignore library to check if file matches any protected pattern
4551
return this.ignoreInstance.ignores(relativePath)
4652
} catch (error) {

src/core/protect/__tests__/RooProtectedController.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,19 @@ describe("RooProtectedController", () => {
8080
expect(controller.isWriteProtected(".roo\\config.json")).toBe(true)
8181
expect(controller.isWriteProtected(".roo/config.json")).toBe(true)
8282
})
83+
84+
it("should handle paths outside the cwd gracefully", () => {
85+
// Paths that go outside the cwd should not be protected
86+
expect(controller.isWriteProtected("../../.roo/rules")).toBe(false)
87+
expect(controller.isWriteProtected("../../../.rooignore")).toBe(false)
88+
expect(controller.isWriteProtected("../.roo/config.json")).toBe(false)
89+
})
90+
91+
it("should not throw error for paths outside cwd", () => {
92+
// This should not throw an error
93+
expect(() => controller.isWriteProtected("../../.roo/rules")).not.toThrow()
94+
expect(() => controller.isWriteProtected("../outside/path/.rooignore")).not.toThrow()
95+
})
8396
})
8497

8598
describe("getProtectedFiles", () => {

0 commit comments

Comments
 (0)