Fix parseLineAndColumnAware mistaking hex/exponential path segments for line numbers#323835
Open
chatman-media wants to merge 1 commit into
Open
Fix parseLineAndColumnAware mistaking hex/exponential path segments for line numbers#323835chatman-media wants to merge 1 commit into
chatman-media wants to merge 1 commit into
Conversation
…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.
Contributor
There was a problem hiding this comment.
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
`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.