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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user