feat: Introduce robust hashline anchor validation and new editing tools.
This commit is contained in:
@@ -62,17 +62,14 @@ internal static class HashlineValidator
|
||||
|
||||
if (lineNumber < 1 || lineNumber > lines.Length)
|
||||
{
|
||||
error = $"Anchor '{anchor}': line {lineNumber} is out of range " +
|
||||
$"(file has {lines.Length} line(s)).";
|
||||
error = $"Anchor '{anchor}': line {lineNumber} is out of range. Re-read the file ({lines.Length} lines).";
|
||||
return false;
|
||||
}
|
||||
|
||||
string actualHash = HashlineEncoder.ComputeHash(lines[lineNumber - 1].AsSpan(), lineNumber);
|
||||
if (!string.Equals(actualHash, expectedHash, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
error = $"Anchor '{anchor}': hash mismatch at line {lineNumber} " +
|
||||
$"(expected '{expectedHash}', got '{actualHash}'). " +
|
||||
$"The file has changed — re-read before editing.";
|
||||
error = $"Anchor '{anchor}': hash mismatch at line {lineNumber}. The file has changed — re-read before editing.";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -98,10 +95,7 @@ internal static class HashlineValidator
|
||||
out int endIndex,
|
||||
out string error)
|
||||
{
|
||||
startIndex = -1;
|
||||
endIndex = -1;
|
||||
error = string.Empty;
|
||||
|
||||
if (!TryResolve(startAnchor, lines, out startIndex, out error))
|
||||
return false;
|
||||
|
||||
@@ -110,8 +104,7 @@ internal static class HashlineValidator
|
||||
|
||||
if (startIndex > endIndex)
|
||||
{
|
||||
error = $"Range error: start anchor '{startAnchor}' (line {startIndex + 1}) " +
|
||||
$"is after end anchor '{endAnchor}' (line {endIndex + 1}).";
|
||||
error = $"Range error: start anchor is after end anchor.";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user