Repository navigation
fix(windows): trim a shell-link path the way Win32 does - #10280
XiaoBinGan wants to merge 2 commits into
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6b2e3794c8
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
Correct — and the same shape the previous commit already had to model. An A leading unexpanded reference now leaves the segments as written, in both the extension reader and the compare form:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 26ef5380d4
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
Correct.
Only a drive or UNC path is trimmed now. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4acd3eeb0c
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
Right again, and it is the third round on the same reader — which is the signal that patching one URL form at a time does not hold. The spelling is the evidence, and one rule now covers every case:
A filesystem path Win32 opens is written with backslashes — a drive or a share — while a URL keeps forward slashes, including the scheme-relative form that folds to the same separators. So the check runs on the stored text rather than on the folded path.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 09d791702f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
Correct — and the last place the folded text was still trusted.
Worth saying: my first attempt at this rule was "written with backslashes", and an existing case caught it —
|
[Low impact] The change stays within extension reporting for parsed Windows shortcuts. Do not merge until the filename trim avoids quadratic work on crafted input. FindingsFix with agent prompt### Issue 1
src/native/windows/WindowsShortcutParser.ts:279
The new `/[. ]+$/u` search in `fileNameSegment` retries at every period when a long run ends in `x`. Doubling the filename length roughly quadruples the work. The exact expression took about 437 ms at 32 KiB and 1.77 seconds at 64 KiB, which the default string budget permits. Callers can raise that budget to 1 MiB.
This runs synchronously, so a crafted shortcut blocks other requests and delays cancellation. Scan backward from the end instead.
**How this was verified:** LinkInfo names reach this expression after the string budget admits them, and doubling a nonmatching period run repeatedly increased the measured time roughly fourfold.
### Issue 2
src/native/windows/WindowsShortcutParser.ts:undefined-270
For an ANSI `LocalBasePath` of `\\?\C:\café` and a `CommonPathSuffix` of `app.exe.`, the `base.ansi` branch copies `suffix.extension`. This new trim has already changed that suffix’s extension to `.exe`, without seeing the device prefix. The report therefore says `.exe` instead of `null`, even though the full path must keep its final period.
Carry the base’s trim rules into suffix extraction, or leave the extension unknown when those rules cannot be established.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryThe PR trims trailing spaces and periods before deriving Windows shortcut extensions.
Reviews (16) · Last reviewed commit: "fix(windows): test the folded device pre..." · Reviewed by Greptile |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8d83e5eb8a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
Both correct, and the rule I wrote was too clever: it treated a leading The spelling was never the right evidence — which field the text came from is, because that says whether it is a filesystem path at all.
The field is now carried on the recorded path rather than re-derived from the text. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
1b47fe5 to
a5bf6a7
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a5bf6a73b3
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 18fdaaf62e
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // The parts cannot be joined into one comparable string, but the extension still comes | ||
| // from the final segment, which is the suffix's own name. |
There was a problem hiding this comment.
Preserve device normalization through opaque LinkInfo joins
When an ANSI LinkInfo base contains non-ASCII bytes, for example \\?\C:\Té plus the ASCII CommonPathSuffix app.exe., base.ansi takes this opaque-join branch and reuses suffix.extension; the new extensionOf logic has already trimmed that suffix to .exe without seeing the device prefix. The complete target is a verbatim path and retains the terminal period, so target_extension should stay null; although the earlier all-ASCII LinkInfo case is now fixed, this branch is fresh evidence that the same normalization mode is still lost. Preserve the recognized prefix through the branch or leave the extension unknown.
AGENTS.md reference: AGENTS.md:L37-L37
Useful? React with 👍 / 👎.
|
@XiaoBinGan thanks for the PR — there are 2 open review threads here:
Could you address or reply to these? Once they're resolved and CI is green we can take another look. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Refreshed this branch onto current On the P1 "Matching network paths look different": I cannot reproduce it on the current head, because the spelling gate it describes is gone. One thing to flag rather than hide: |
| const extensionOf = (path: string, ansi: boolean): string | null => { | ||
| if (path.length === 0) return null; | ||
| const normalized = path.replaceAll("/", "\\"); | ||
| const normalized = fileNameSegment(path.replaceAll("/", "\\")); |
There was a problem hiding this comment.
For an ANSI LocalBasePath of \\?\C:\café and a CommonPathSuffix of app.exe., the base.ansi branch copies suffix.extension. This new trim has already changed that suffix’s extension to .exe, without seeing the device prefix. The report therefore says .exe instead of null, even though the full path must keep its final period.
Carry the base’s trim rules into suffix extraction, or leave the extension unknown when those rules cannot be established.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/native/windows/WindowsShortcutParser.ts
Line: 270
Comment:
**ANSI joins lose trim rules**
For an ANSI `LocalBasePath` of `\\?\C:\café` and a `CommonPathSuffix` of `app.exe.`, the `base.ansi` branch copies `suffix.extension`. This new trim has already changed that suffix’s extension to `.exe`, without seeing the device prefix. The report therefore says `.exe` instead of `null`, even though the full path must keep its final period.
Carry the base’s trim rules into suffix extraction, or leave the extension unknown when those rules cannot be established.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.|
Restrict Win32 trimming to filesystem target sources (P2) — fixed in
The builder now takes the source's semantics, and Two cases in
Control: reverting the source gate fails only the URL case; the Win32 relative-name case keeps passing, so the test pins the gate and not extension derivation in general.
Remaining threads here are the trim-timing pair ( |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Preserve scheme-relative URLs before UNC classification / during icon comparison (P2) — fixed in Both threads are the same root cause: The bytes carry nothing that separates a scheme-relative URL from a forward-slash UNC path, so the reader does not guess between them: text starting Two cases in
Control: reverting the pattern to scheme-only fails the first case alone; the second keeps passing. This also covers the icon-comparison thread, since
Remaining threads here are the trim-timing pair ( |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
The two trim-timing threads do not reproduce on LinkInfo with a device prefix. EnvironmentVariableDataBlock with an unexpanded variable. Measured on this head with [{"kind":"target_extension","evidence_kind":"derived","extension":null}]No If either reproduces for you, paste the bytes or the fixture and I will chase it — the fix would be to defer the name pass until the full path is assembled, which is a larger change than this branch currently makes. With the three earlier commits (
|
|
Drive paths lose their extension (P2) — fixed in A single letter and a colon is a drive, so that spelling now keeps the Win32 name pass: /^[a-z]:/iu.test(path) || !/^(?:[a-z][a-z0-9+.-]*:)?\/\//iu.test(path)Three cases now hold apart: Control: removing the drive arm fails only the drive case. The remaining thread here is the ANSI-join one (
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bc9ddac2c7
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // Otherwise an explicit scheme names a URL. Text starting `//` is either that | ||
| // or a forward-slash UNC path, and the bytes carry nothing that separates them, | ||
| // so its name is left as written rather than trimmed. | ||
| !/^(?:[a-z][a-z0-9+.-]*:)?\/\//iu.test(path); |
There was a problem hiding this comment.
Recognize URLs without
// before Win32 trimming
When RelativePath contains a URL whose scheme does not use //, such as mailto:launcher.exe. or https:example.test/app.exe., this predicate classifies it as a Win32 path, so fileNameSegment removes the URI's terminal period and publishes .exe. These are valid scheme forms whose final period remains URI data; unlike the fixed https:// case, this commit therefore changes the previously null extension into a false executable extension. Recognize non-drive scheme: forms or leave them unknown before applying Win32 name normalization.
AGENTS.md reference: AGENTS.md:L33-L33
Useful? React with 👍 / 👎.
|
Recognize URLs without The decision is now three explicit branches: if (/^[a-z]:/.test(path)) return true; // drive: Win32
if (/^[a-z][a-z0-9+.-]*:/.test(path)) return false; // any other scheme: URI
return !/^\/\//.test(path); // //: ambiguous, leave as writtenCases added: Control: removing the scheme branch fails both URI cases, and the drive case keeps passing. State of this predicate's coverage should now be complete for the shapes the bytes can produce: drive, UNC/device (
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a3ed82f3f5
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // there does a trailing period or space leave the extension unchanged. A URL | ||
| // recorded in the same field keeps its own trailing dot. | ||
| const normalized = win32Names | ||
| ? fileNameSegment(path.replaceAll("/", "\\")) |
There was a problem hiding this comment.
Exclude drive designators from the filename segment
When RelativePath is a valid drive-relative hidden name such as C:.profile., this new normalization produces C:.profile; with no slash, the following dot test treats C: as part of the filename and publishes .profile. Win32's final filename segment is .profile, for which this function's own dot <= 0 rule yields no extension (as it does for .profile. and C:\.profile.), so parse or remove the drive designator before extracting the normalized filename.
AGENTS.md reference: AGENTS.md:L27-L27
Useful? React with 👍 / 👎.
|
Exclude drive designators from the filename segment (P2) — fixed in A drive designator names no file, so it is removed before the name test: const normalized = win32Names
? fileNameSegment(folded).replace(/^[a-z]:/iu, "")
: folded;Cases added: Control: removing the designator strip fails only the drive-relative case.
For context on this predicate's churn — it has now taken four review rounds ( |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3c999557f3
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const isWin32PathText = (path: string): boolean => { | ||
| // A single letter and a colon is a drive, so `C://Tools/app.exe.` keeps Win32 | ||
| // name trimming even though its prefix also spells a scheme. | ||
| if (/^[a-z]:/iu.test(path)) return true; |
There was a problem hiding this comment.
Preserve ambiguity for one-letter URI schemes
When RelativePath is a valid one-letter custom URI such as x:launcher.exe., this branch treats x: as a drive designator, runs the Win32 filename trim, and publishes .exe; for the URI, the terminal period is resource data and the result should remain null/unknown, just like the newly handled mailto: case. Because the stored text cannot distinguish a drive-relative path from a one-letter scheme, preserve that ambiguity instead of unconditionally applying Win32 normalization.
AGENTS.md reference: AGENTS.md:L33-L33
Useful? React with 👍 / 👎.
|
Preserve ambiguity for one-letter URI schemes (P2) — fixed in The drive arm now needs a separator, so only an unambiguous drive path takes the Win32 pass: if (/^[a-z]:[\\/]/.test(path)) return true; // drive path
if (/^[a-z][a-z0-9+.-]*:/.test(path)) return false; // URI, or drive-relative — ambiguous
return !path.startsWith("//"); // // — ambiguousCases: Cost stated plainly: a drive-relative path with an extension (
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a398ff0a03
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const isWin32PathText = (path: string): boolean => { | ||
| // A drive designator followed by a separator names a path Win32 opens, so its | ||
| // name takes the Win32 pass. | ||
| if (/^[a-z]:[\\/]/iu.test(path)) return true; |
There was a problem hiding this comment.
Keep hierarchical one-letter URIs ambiguous
When RelativePath stores a valid custom URI such as x://example.test/launcher.exe., this branch treats it as a drive path, strips the URI's terminal period, and publishes .exe; a separator does not disambiguate the text because one-letter schemes may also have hierarchical paths. The new separator-specific branch is fresh evidence beyond the fixed x:launcher.exe. case, so preserve these forms as unknown unless the source proves drive semantics.
AGENTS.md reference: AGENTS.md:L33-L33
Useful? React with 👍 / 👎.
| [...text].every((char) => char <= "\u007f"); | ||
|
|
||
| const recorded = (path: string, ansi: boolean) => { | ||
| const recorded = (path: string, ansi: boolean, win32Names: boolean = true) => { |
There was a problem hiding this comment.
Preserve ID-list item names before extension parsing
When a link has only a LinkTargetIDList and its last file-entry item stores app.exe., the unchanged ID-list call to recorded omits the third argument, so this new true default strips the item's terminal period and changes target_extension to .exe. An ID list carries shell-item identity rather than path text passed through Win32 parsing and can describe namespace or verbatim names; this still-defaulted caller is fresh evidence beyond the fixed RelativePath source case, so pass source semantics explicitly and leave this extension raw or unknown.
AGENTS.md reference: AGENTS.md:L19-L19
Useful? React with 👍 / 👎.
|
Hidden files gain an extension / Keep hierarchical one-letter URIs ambiguous (P2, two threads) — one fix in Both come from the designator strip living only in the Win32 branch. It now happens once, for either branch: const designatorFree = folded.replace(/^[a-z]:/iu, "");
const normalized = win32Names ? fileNameSegment(designatorFree) : designatorFree;
This does collide with the earlier
|
|
Preserve ID-list item names before extension parsing (P2) — applied in The ID-list call now passes the source explicitly instead of relying on the new default: recorded(lastFile.short_name, (lastFile.type_byte & 0x04) === 0, false)A shell item carries a namespace identity rather than path text Win32 opens, so its stored name is no longer trimmed. Gap, measured rather than hidden. I could not pin this through
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 785677a2c7
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| * path skips that pass, and an unexpanded `%VAR%` may expand to one, so both keep their text. | ||
| */ | ||
| const fileNameSegment = (path: string): string => { | ||
| if (DEVICE_PATH.test(path) || hasUnexpandedVariable(path)) return path; |
There was a problem hiding this comment.
Keep variable-dependent trailing-space extensions unknown
When an EnvironmentVariableDataBlock contains %ROOT%\app.exe , %ROOT% can expand either to C:\Tools (Win32 strips the final space and the extension is .exe) or to \\?\C:\Tools (the verbatim filename keeps it, so the extension is .exe ). This guard returns the raw path for both, after which extensionOf publishes .exe instead of preserving the unresolved normalization mode as null; the trailing-space input is fresh evidence beyond the now-fixed trailing-period case. Carry an unknown normalization state through extension derivation rather than treating “do not normalize” as a known verbatim path.
AGENTS.md reference: AGENTS.md:L33-L33
Useful? React with 👍 / 👎.
|
Keep variable-dependent trailing-space extensions unknown (P2) — fixed in An unexpanded if (hasUnexpandedVariable(path) && name.endsWith(" ")) return null;Cases: Correction to something I posted earlier. I replied on the "Defer trimming until variable prefixes are resolved" thread that it did not reproduce, citing The same fixture limit applies to the ID-list change in
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c9309251c3
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| * path skips that pass, and an unexpanded `%VAR%` may expand to one, so both keep their text. | ||
| */ | ||
| const fileNameSegment = (path: string): string => { | ||
| if (DEVICE_PATH.test(path) || hasUnexpandedVariable(path)) return path; |
There was a problem hiding this comment.
Detect separators inside environment variable names
When an EnvironmentVariableDataBlock stores %A/B%\app.exe. and the legal Windows variable name A/B expands to \\?\C:\Tools, hasUnexpandedVariable returns false because its character class excludes /; this guard therefore applies Win32 trimming before expansion and publishes .exe, although the verbatim expanded filename retains the final period and leaves the extension unknown. The %ROOT% case from the earlier review is fixed, but this separator-bearing name is fresh evidence that the detector needs to follow %...% expansion syntax.
AGENTS.md reference: AGENTS.md:L33-L33
Useful? React with 👍 / 👎.
| const isWin32PathText = (path: string): boolean => { | ||
| // Only a backslash after the designator is unambiguously a path; `x://host/...` | ||
| // spells the same as a custom URI, so it stays ambiguous below. | ||
| if (/^[a-z]:\\/iu.test(path)) return true; |
There was a problem hiding this comment.
Restrict drive-letter matching to ASCII
When a RelativePath-only link stores K:\Tools\app.exe., ECMAScript Unicode case folding makes ^[a-z] with iu match the Kelvin sign, so this branch treats K: as a drive, trims the final period, and publishes .exe. Windows drive designators and URI schemes are ASCII, so path semantics are not established; match ASCII letters without Unicode case folding, including in the sibling designator and scheme expressions, so this remains null instead of inventing a filesystem extension.
AGENTS.md reference: AGENTS.md:L33-L33
Useful? React with 👍 / 👎.
c015fec to
1676c70
Compare
|
Both findings are mine and are fixed in Detect separators inside environment variable names. /%[^%]+%/u.test(path)Restrict drive-letter matching to ASCII. Cases:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1676c70c11
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // An unexpanded variable leaves the normalization mode unknown: the same text | ||
| // opens through Win32, which strips a trailing space, or through a `\\?\` verbatim | ||
| // path, which keeps it. A trailing space therefore names no known extension. | ||
| if (hasUnexpandedVariable(path) && name.endsWith(" ")) return null; |
There was a problem hiding this comment.
Preserve extensions under explicit device prefixes
When a RelativePath contains \\?\C:\%DIR%\app.exe , this guard returns null solely because %DIR% is unresolved. The leading device prefix already fixes the normalization mode regardless of the expansion, so the verbatim target keeps the trailing space and has the known extension .exe ; restrict the variable-based unknown branch to paths whose expansion can actually select normal versus verbatim handling.
AGENTS.md reference: AGENTS.md:L33-L33
Useful? React with 👍 / 👎.
|
Preserve extensions under explicit device prefixes (P2) — fixed in The unknown-mode guard only applies when the mode is actually unknown. A if (hasUnexpandedVariable(path) && !DEVICE_PATH.test(path) && name.endsWith(" "))
return null;Case:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 21d0b6c213
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| * path skips that pass, and an unexpanded `%VAR%` may expand to one, so both keep their text. | ||
| */ | ||
| const fileNameSegment = (path: string): string => { | ||
| if (DEVICE_PATH.test(path) || hasUnexpandedVariable(path)) return path; |
There was a problem hiding this comment.
Trim variable-bearing names under fixed Win32 prefixes
Unlike the now-covered leading-device case, a target such as C:\Tools\%DIR%\app.exe has an unexpanded variable after an explicit drive prefix, so this unconditional return skips the Win32 name pass and the later trailing-space check reports target_extension: null. Expansion cannot replace the fixed C:\ prefix with \\?\, so normal Win32 trimming is known and the extension is .exe; leave the mode unknown only when the variable can determine the leading prefix.
AGENTS.md reference: AGENTS.md:L33-L33
Useful? React with 👍 / 👎.
21d0b6c to
17032a8
Compare
|
This branch is now a rebuild on current What it does, in the shape
Nine cases in
One thing to flag rather than hide: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 17032a830b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // path, which keeps it. A trailing space therefore names no known extension. | ||
| if ( | ||
| hasUnexpandedVariable(path) && | ||
| !DEVICE_PATH.test(path) && |
There was a problem hiding this comment.
Check the folded device prefix before returning unknown
When a valid environment target uses the slash-spelled device form //?/C:/%DIR%/app.exe , fileNameSegment(normalized) and the sibling LOCAL_DRIVE_DEVICE_PATH in src/native/windows/WindowsShortcutProvider.ts both recognize a fixed verbatim prefix, so %DIR% cannot select normal Win32 trimming and the known extension is .exe . This condition instead retests the original slash spelling, misses DEVICE_PATH, and returns null; test the folded value (or carry the mode from fileNameSegment). The backslash-prefix case is now covered, but the repository's accepted slash spelling is fresh evidence that the earlier repair is incomplete.
AGENTS.md reference: AGENTS.md:L31-L31
Useful? React with 👍 / 👎.
|
Fixed in the follow-up commit. The guard was testing the caller's raw spelling, so a slash-spelled if (hasUnexpandedVariable(path) && !DEVICE_PATH.test(normalized) && name.endsWith(" "))
return null;
Case added:
|
| const fileNameSegment = (path: string): string => { | ||
| if (DEVICE_PATH.test(path) || hasUnexpandedVariable(path)) return path; | ||
| const at = Math.max(path.lastIndexOf("\\"), path.lastIndexOf("/")) + 1; | ||
| const name = path.slice(at).replace(/[. ]+$/u, ""); |
There was a problem hiding this comment.
Crafted filenames freeze inspection
The new /[. ]+$/u search in fileNameSegment retries at every period when a long run ends in x. Doubling the filename length roughly quadruples the work. The exact expression took about 437 ms at 32 KiB and 1.77 seconds at 64 KiB, which the default string budget permits. Callers can raise that budget to 1 MiB.
This runs synchronously, so a crafted shortcut blocks other requests and delays cancellation. Scan backward from the end instead.
How this was verified: LinkInfo names reach this expression after the string budget admits them, and doubling a nonmatching period run repeatedly increased the measured time roughly fourfold.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/native/windows/WindowsShortcutParser.ts
Line: 279
Comment:
**Crafted filenames freeze inspection**
The new `/[. ]+$/u` search in `fileNameSegment` retries at every period when a long run ends in `x`. Doubling the filename length roughly quadruples the work. The exact expression took about 437 ms at 32 KiB and 1.77 seconds at 64 KiB, which the default string budget permits. Callers can raise that budget to 1 MiB.
This runs synchronously, so a crafted shortcut blocks other requests and delays cancellation. Scan backward from the end instead.
**How this was verified:** LinkInfo names reach this expression after the string budget admits them, and doubling a nonmatching period run repeatedly increased the measured time roughly fourfold.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6bccb18502
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| hasUnexpandedVariable(path) && | ||
| !DEVICE_PATH.test(normalized) && | ||
| name.endsWith(" ") |
There was a problem hiding this comment.
Honor non-Win32 source semantics in the variable guard
When an ID-list file entry stores a namespace name such as %ROOT%.exe , its call to recorded(..., false) deliberately opts out of Win32 name normalization, but this condition still fires because it ignores win32Names, changing target_extension from the stored .exe to null. %ROOT% is literal shell-item identity in this source, so expansion cannot switch its normalization mode; gate this ambiguity check on win32Names (or otherwise carry source kind) so the new opt-out actually preserves the name.
AGENTS.md reference: AGENTS.md:L19-L19
Useful? React with 👍 / 👎.
Win32 strips trailing spaces and periods from a name before it opens the file, so a shortcut that stores
C:\Tools\app.exe.opensC:\Tools\app.exe. The extension this parser derives came from the stored name, so it reported no extension for those and disagreed with the file the shortcut opens.Approach
fileNameSegmentapplies the Win32 rule to the final segment, andextensionOfreads the extension from it. Two shapes keep their text, because the trim cannot be assumed:\\?\or\\.\path reaches Windows verbatim, so its trailing period names another file;%VAR%may expand to one of those.Evidence
src/native/windows/WindowsShortcutParser.test.ts—C:\Tools\app.exe.,C:\Tools\app.exeandC:\Tools\app.exe. .derive.exe;C:\Tools\report.derives none, since Win32 opensreport; a\\?\path and a%NAME%prefix keep the text as written. The three trimming cases fail onaf0e0edbcand pass here.src/native/windows: 72 passed.tsc --noEmit,oxlint(0 errors),oxfmt --check,scripts/verify/architecture-guards.mjs: pass.Narrowed scope
This branch previously carried six commits covering the icon-versus-target comparison, the forward-slash share spelling and a stored-spelling source distinction.
#11923rewrote the same functions (RecordedPath,extensionOf,pathsDiffer) while this was open, so those pieces need porting onto that structure rather than rebasing. Rebasing ontoaf0e0edbcreduced it to the extension rule, which is the part that survives unchanged.What is not covered here, and would need its own change: the comparison path still compares trailing periods literally, a forward-slash share recorded in a filesystem field is not trimmed, and there is no distinction between an ANSI and a Unicode spelling of the same trailing period.
Not verified
No real
.lnkfrom Windows was parsed: the fixtures are built in the test file, and the Win32 rule is from the documented behaviour, not from a measurement on this host (macOS).