fix(hashline): use strict whitespace hashing (trimEnd only, preserve leading indentation)

Previously computeLineHash stripped ALL whitespace before hashing, making
indentation changes invisible to hash validation. This weakened the stale-line
detection guarantee, especially for indentation-sensitive files (Python, YAML).

Now only trailing whitespace and carriage returns are stripped, matching
oh-my-pi upstream behavior. Leading indentation is preserved in the hash,
so indentation-only changes correctly trigger hash mismatches.
This commit is contained in:
YeonGyu-Kim
2026-03-12 16:42:41 +09:00
parent 04b0d62a55
commit 0cbc15da96
2 changed files with 29 additions and 3 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ import { createHashlineChunkFormatter } from "./hashline-chunk-formatter"
const RE_SIGNIFICANT = /[\p{L}\p{N}]/u
export function computeLineHash(lineNumber: number, content: string): string {
const stripped = content.endsWith("\r") ? content.slice(0, -1).replace(/\s+/g, "") : content.replace(/\s+/g, "")
const stripped = content.replace(/\r/g, "").trimEnd()
const seed = RE_SIGNIFICANT.test(stripped) ? 0 : lineNumber
const hash = Bun.hash.xxHash32(stripped, seed)
const index = hash % 256