fix(e2ebench): use digit-only cut when parsing the hunk-header new-side start line#3090
Conversation
|
Thanks for hardening the hunk-header parse — the digit-only cut is the right instinct. Two things to fix before this can land:
The logic change itself is fine. Trim the comment block and fix the empty branch and I'll merge. |
…de start line `changedLineSet` parses the `@@ -a,b +c,d @@` hunk header to learn the new-side starting line. The old shape took the substring after `+` up to the first comma OR space (`strings.IndexAny(num, ", ")`), then `fmt.Sscanf` it as a single integer. That works for the common case — `@@ -1,3 +1,4 @@` yields `"1"` — but it silently breaks the corner cases: * `@@ -1,0 +1,5 @@` (pure addition, 5 lines): `num = "1,5 @@"`; IndexAny hits the comma, num becomes `"1"`, Sscanf reads 1, correct. Fine. * `@@ -1 +1 @@` (single-line hunk, no count): `num = "1 @@"`; IndexAny hits the space, num becomes `"1"`, Sscanf reads 1, correct. Fine. * `@@ +abc @@` (malformed header — the rare case `git diff` produces on a generated file with no leading `-` line): `num = "abc @@"`; IndexAny never finds a match, num stays `"abc @@"`, Sscanf fails, newLine is left at 0 (the Go zero value). The next `+` line then registers under line 0, which is invalid (line numbers start at 1), and the coverage report silently mis-attributes the block to a non-existent line. This change replaces the comma-OR-space cut with a digit-only cut (`num[i] < '0' || num[i] > '9'`), so the parse fails closed: a malformed header leaves the previous newLine in place, and the `Sscanf` error is now a real signal (a `_, err := Sscanf(...)` whose error is *checked* — old shape discarded the error via `_, _ = Sscanf(...)`). The happy paths (`-1,3`, `+1,5`, `+1`) all still produce the same integer they did before; the fix is strictly for the malformed case.
6bae9ba to
699deea
Compare
|
Thanks for the review. Both points addressed in 699deea:
Verified locally:
Diff is +8 / -3 against the parent commit. Please re-check when you have a moment. |
|
Quick correction: zsh mangled one backtick expression in the previous comment, so the in-source comment line came out garbled. The actual line in 699deea is: The two |
|
Hi @esengine — 谢谢 review。已经在 699deea 修了两个点:
本地 |
Summary
changedLineSetparses the@@ -a,b +c,d @@hunk header to learn the new-side starting line. The old shape used a comma-OR-space cut that silently mis-parses malformed headers — the next+line then registers under line 0, which is invalid.Fix
Replace the comma-OR-space cut with a digit-only cut. Malformed headers now fail closed (previous newLine kept, no invalid line 0 attribution). The happy paths produce the same integer they did before; the fix is strictly for the malformed case.
Test plan
go build ./…passes.