Skip to content

Fix parseLineAndColumnAware mistaking hex/exponential path segments for line numbers#323835

Open
chatman-media wants to merge 1 commit into
microsoft:mainfrom
chatman-media:fix/parse-line-column-strict-decimal
Open

Fix parseLineAndColumnAware mistaking hex/exponential path segments for line numbers#323835
chatman-media wants to merge 1 commit into
microsoft:mainfrom
chatman-media:fix/parse-line-column-strict-decimal

Conversation

@chatman-media

Copy link
Copy Markdown

`parseLineAndColumnAware` (used by the `--goto FILE:LINE(:COLUMN)` CLI flag) decides whether a colon-delimited segment is a line/column by coercing it with `Number()` and checking it's not NaN. That's too permissive: `Number("0x10")` is 16 and `Number("1e3")` is 1000, so a file legitimately named something like `report:0x10` gets its `0x10` segment silently swallowed as line 16 instead of staying part of the path.

Swapped the check for a strict `/^[0-9]+$/` regex so only plain decimal digit segments are treated as line/column, and added a few test cases covering hex- and exponential-looking segments. Existing behavior (plain line/column parsing, Windows drive letters like `C:\foo\bar:33`) is unaffected since those segments were never matched by the loose check either.

…s as line/column

Number(segment) coerces strings like "0x10" or "1e3" into valid numbers,
so a path segment that happens to look like hex or exponential notation
was silently parsed as a line/column instead of staying part of the file
path. Switched to a strict decimal-digit regex and added coverage for it.
Copilot AI review requested due to automatic review settings July 1, 2026 07:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adjusts parseLineAndColumnAware (used by --goto FILE:LINE(:COLUMN)) to avoid incorrectly interpreting hex/exponential-looking colon segments as line/column numbers, preventing valid file paths like report:0x10 from being truncated.

Changes:

  • Replaced the permissive Number()/NaN-based segment check with a strict ^[0-9]+$ regex for line/column detection.
  • Added unit tests ensuring hex- and exponential-looking segments remain part of the path while still allowing a later plain decimal line segment.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/vs/base/common/extpath.ts Tightens line/column parsing to only accept plain decimal digit segments.
src/vs/base/test/common/extpath.test.ts Adds regression tests for 0x10 / 1e3-style segments not being treated as line/column.
Comment on lines +206 to +208
// segments that `Number()` would coerce into a valid number (hex, exponential, ...)
// must still be treated as part of the path, not as line/column. A file can be
// legally named e.g. `report:0x10` without the `0x10` part being mistaken for a line.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants