Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkgs/id/web/src/goto-line.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
])(
Expand Down
6 changes: 5 additions & 1 deletion pkgs/id/web/src/goto-line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down