fix: Windows compatibility — CRLF line endings and cross-drive path traversal (#217)

* fix: Windows compatibility — handle CRLF line endings and cross-drive path traversal

- Replace literal '\n' splits with /\r?\n/ regex across git output parsers
  (status, worktree, hooks, file listing) to handle Windows CRLF line endings
- Fix path traversal security check in isDescendantOrEqual using isAbsolute()
  instead of sep+sep prefix check, preventing cross-drive bypasses on Windows
- Strip trailing \r from ripgrep output in quick-open file listing

* fix(test): align updater test with user-initiated not-available behavior

The test expected 'idle' for a user-initiated check hitting a missing
latest-mac.yml, but the code correctly sends 'not-available' to give
the user explicit feedback that they're on the latest version.
This commit is contained in:
Jinjing
2026-03-29 22:06:59 -07:00
committed by GitHub
parent c625ce882e
commit affa73bcd3
6 changed files with 29 additions and 11 deletions
+6 -2
View File
@@ -34,7 +34,9 @@ export async function getStatus(worktreePath: string): Promise<GitStatusResult>
{ cwd: worktreePath, encoding: 'utf-8' }
)
for (const line of stdout.split('\n')) {
// [Fix]: Split by /\r?\n/ instead of '\n' to correctly parse git output on Windows,
// avoiding trailing \r characters in parsed paths.
for (const line of stdout.split(/\r?\n/)) {
if (!line) {
continue
}
@@ -417,7 +419,9 @@ async function loadBranchChanges(
)
const entries: GitBranchChangeEntry[] = []
for (const line of stdout.split('\n')) {
// [Fix]: Split by /\r?\n/ instead of '\n' to handle Git CRLF output on Windows,
// preventing trailing \r characters in extracted file paths.
for (const line of stdout.split(/\r?\n/)) {
if (!line) {
continue
}
+5 -2
View File
@@ -9,14 +9,17 @@ const execFileAsync = promisify(execFile)
*/
export function parseWorktreeList(output: string): GitWorktreeInfo[] {
const worktrees: GitWorktreeInfo[] = []
const blocks = output.trim().split('\n\n')
// [Fix]: Use /\r?\n\r?\n/ to handle both LF and CRLF (\r\n) line endings,
// which are common when running git on Windows.
const blocks = output.trim().split(/\r?\n\r?\n/)
for (const block of blocks) {
if (!block.trim()) {
continue
}
const lines = block.trim().split('\n')
// [Fix]: Use /\r?\n/ to handle both LF and CRLF (\r\n) line endings.
const lines = block.trim().split(/\r?\n/)
let path = ''
let head = ''
let branch = ''