diff --git a/pkgs/id/web/src/goto-line.test.ts b/pkgs/id/web/src/goto-line.test.ts index aac529aee4..94021d9414 100644 --- a/pkgs/id/web/src/goto-line.test.ts +++ b/pkgs/id/web/src/goto-line.test.ts @@ -304,6 +304,13 @@ describe("dialog input interaction", () => { ["0", "zero"], ["-3", "negative"], ["2.9", "fractional"], + // #2776: non-decimal spellings that Number() reinterprets as the + // in-range line 2 — out-of-range spellings could not distinguish + // acceptance from rejection on this 3-line fixture. + ["0x2", "hex for line 2"], + ["0b10", "binary for line 2"], + ["2.0", "decimal point for line 2"], + ["+2", "signed line 2"], ["999", "out of range"], ["", "empty"], ])( diff --git a/pkgs/id/web/src/goto-line.ts b/pkgs/id/web/src/goto-line.ts index ec26e10749..e15afa693f 100644 --- a/pkgs/id/web/src/goto-line.ts +++ b/pkgs/id/web/src/goto-line.ts @@ -111,7 +111,11 @@ function openGotoLine(view: EditorView): void { // Invalid input keeps the dialog open with the text selected so // the user can correct it; the cursor does not move. const raw = (dialogInput?.value ?? "").trim(); - const line = Number(raw); + // Only a run of decimal digits counts (#2776): Number() alone + // also reinterprets hex/binary/scientific spellings the field + // never showed as that line ("0x10" -> 16, "1e2" -> 100, + // "2.0" -> 2) — the parseWorldSeed rule (#832). + const line = /^\d+$/.test(raw) ? Number(raw) : Number.NaN; // ⚡ Bolt optimization: compute line starts once instead of traversing doc twice const lineStarts = activeView ? getLineStarts(activeView) : []; const lineCount = Math.max(1, lineStarts.length);