Skip to content

fix(windows): trim a shell-link path the way Win32 does - #10280

Open
XiaoBinGan wants to merge 2 commits into
morluto:mainfrom
XiaoBinGan:fix/lnk-win32-trailing-trim
Open

XiaoBinGan wants to merge 2 commits into
morluto:mainfrom
XiaoBinGan:fix/lnk-win32-trailing-trim

Conversation

@XiaoBinGan

@XiaoBinGan XiaoBinGan commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Win32 strips trailing spaces and periods from a name before it opens the file, so a shortcut that stores C:\Tools\app.exe. opens C:\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

fileNameSegment applies the Win32 rule to the final segment, and extensionOf reads the extension from it. Two shapes keep their text, because the trim cannot be assumed:

  • a \\?\ or \\.\ path reaches Windows verbatim, so its trailing period names another file;
  • an unexpanded %VAR% may expand to one of those.

Evidence

src/native/windows/WindowsShortcutParser.test.ts — C:\Tools\app.exe., C:\Tools\app.exe and C:\Tools\app.exe. . derive .exe; C:\Tools\report. derives none, since Win32 opens report; a \\?\ path and a %NAME% prefix keep the text as written. The three trimming cases fail on af0e0edbc and 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. #11923 rewrote the same functions (RecordedPath, extensionOf, pathsDiffer) while this was open, so those pieces need porting onto that structure rather than rebasing. Rebasing onto af0e0edbc reduced 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 .lnk from 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).

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T04:43:25.376181Z 6bccb18 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

Correct — and the same shape the previous commit already had to model. An EnvironmentVariableDataBlock can supply the whole prefix, and %ROOT%\app.exe. with ROOT = \\?\C:\Tools names app.exe. because the expanded prefix skips the trim. The text cannot say which expansion a caller will use, so trimming it would guess a normalization that may not apply.

A leading unexpanded reference now leaves the segments as written, in both the extension reader and the compare form:

target before after
%ROOT%\app.exe. .exe null — the trailing period may be real
%ROOT%\app.exe .exe .exe
C:\Tools\app.exe. .exe .exe — a drive prefix still trims

src/native/windows — 51 passing.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

Correct. normalizePath already returned early for anything that is not a full path, but the extension reader did not, so a URL recorded as RelativePath got the filesystem trim.

target before after
https://example.test/app.exe. via RelativePath .exe null
https://example.test/app.exe .exe .exe
C:\Tools\app.exe. via RelativePath .exe .exe

Only a drive or UNC path is trimmed now. src/native/windows — 52 passing.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

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. //example.test/app.exe. folds to \\example.test\app.exe., so it looked like a UNC path and got a UNC path's trim.

The spelling is the evidence, and one rule now covers every case:

stored target source extension
C:\Tools\app.exe. LinkInfo .exe
\\server\share\app.exe. LinkInfo .exe
C:\Tools\app.exe. RelativePath .exe
%ROOT%\app.exe. LinkInfo null — may expand to \\?\
https://example.test/app.exe. RelativePath null
//example.test/app.exe. RelativePath null
app.exe. RelativePath null

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.

src/native/windows + src/domain/native — 356 passing.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

Correct — and the last place the folded text was still trusted. foldPath turns //example.test/share/app.exe. into the same separators a UNC share uses, so the compare form trimmed the URL's terminal period and called it equal to \\example.test\share\app.exe.

normalizePath now reads the stored spelling before folding. Two things are evidence: a drive path is written with a letter and a colon, whatever separator follows, because Windows accepts both; a share is written with a leading \\. A leading // is therefore a URL.

stored target source result
C:\Tools\app.exe. LinkInfo .exe
c:/Tools/app.exe. LinkInfo .exe
\\server\share\app.exe. LinkInfo .exe
%ROOT%\app.exe. LinkInfo null
https://example.test/app.exe. RelativePath null
//example.test/app.exe. RelativePath null
app.exe. RelativePath null

Worth saying: my first attempt at this rule was "written with backslashes", and an existing case caught it — c:/tools//app.exe must still compare equal to C:\Tools\app.exe. That case is why the drive-path half is spelled out separately.

src/native/windows + src/domain/native — 357 passing.

@greptile-apps

greptile-apps Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 3/5 · Do not merge until the filename trim avoids quadratic work on crafted input.RetriggerView in GreptileConfidence Score: 3/5

[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.

Findings

  1. P1 Security Crafted filenames freeze inspection ▶
  2. P2 ANSI joins lose trim rules ▶
Fix 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.

Summary

The PR trims trailing spaces and periods before deriving Windows shortcut extensions.

  • Shortcut extensions follow the name Windows opens.

Reviews (16) · Last reviewed commit: "fix(windows): test the folded device pre..." · Reviewed by Greptile

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

Both correct, and the rule I wrote was too clever: it treated a leading // as a URL in every field, so a LinkInfo path stored as //server/share/app.exe. stopped being trimmed and the icon comparison claimed a difference against a target Windows opens as the same file.

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.

source example Win32 opens it
LinkInfo local, network, suffix //localhost/C$/Windows yes — Test-Path returns True
IDList file entry, environment block \\server\share\app.exe yes
StringData.RelativePath //example.test/app.exe. may be a scheme-relative URL
input before after
LinkInfo //server/share/bin/../app.exe vs \\server\share\app.exe differs: true false
LinkInfo //server/share/app.exe. vs \\server\share\app.exe true false
LinkInfo //server/share/app.exe. extension null .exe
RelativePath https://…/app.exe. extension null null
RelativePath //example.test/app.exe. vs \\example.test\app.exe true true

The field is now carried on the recorded path rather than re-derived from the text. src/native/windows + src/domain/native + src/filesystem — 358 passing.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@XiaoBinGan
XiaoBinGan force-pushed the fix/lnk-win32-trailing-trim branch from 1b47fe5 to a5bf6a7 Compare November 19, 2026 12:40

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +413 to +414
// 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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@morluto morluto added the bug Something isn't working label Nov 22, 2026
@morluto

morluto commented Nov 24, 2026

Copy link
Copy Markdown
Owner

@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.
cc @gensokyo-dev @dandgabr

@morluto morluto added the area: runtime Process capture and runtime observation label Nov 26, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

Refreshed this branch onto current main (ddefef24d), so the checks below ran against today's tree rather than an eight-day-old one. tsc 0; src/native/windows 108 tests pass; oxfmt --check clean.

On the P1 "Matching network paths look different": I cannot reproduce it on the current head, because the spelling gate it describes is gone. foldPath folds / to \ and lowercases before normalizePath runs, and there is no remaining startsWith("//") branch, so //server/share/bin/../app.exe and \\server\share\app.exe fold to the same comparison form and .. still removes one segment inside a UNC root. If you see this reproduce on ddefef24d, paste the two stored spellings and I will chase it.

One thing to flag rather than hide: tests/acceptance/windowsShortcutCli.test.ts > "reports a wrong CLSID as a malformed target" fails on this branch and on clean main, with the same assertion (invalid_request returned where unsupported_target is expected). I verified it by running that file on origin/main with this branch's changes removed. So it is not from this PR; I am leaving it visible here instead of fixing it inside this branch.

const extensionOf = (path: string, ansi: boolean): string | null => {
if (path.length === 0) return null;
const normalized = path.replaceAll("/", "\\");
const normalized = fileNameSegment(path.replaceAll("/", "\\"));

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.

P2 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.

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.

@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

Restrict Win32 trimming to filesystem target sources (P2) — fixed in 152ce6103.

extensionOf applied fileNameSegment — the Win32 pass that strips trailing periods and spaces — to every source. A RelativePath holding https://example.test/app.exe. therefore published .exe, while an HTTP target keeps that dot.

The builder now takes the source's semantics, and RelativePath decides with isWin32PathText: text carrying an explicit URL scheme keeps its own name; anything else is opened through Win32 as before. LinkInfo and IDList sources keep Win32 trimming, which is what they name.

Two cases in WindowsShortcutParser.test.ts:

  • RelativePath = "https://example.test/app.exe." → no target_extension published
  • RelativePath = "app.exe." → still .exe

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.

src/native/windows: 109 tests pass; tsc 0; oxlint 0 errors; oxfmt --check, architecture guards pass.

Remaining threads here are the trim-timing pair (Defer trimming until variable prefixes are resolved, Defer LinkInfo trimming until after suffix joining) and the scheme-relative URL pair; working those next.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

Preserve scheme-relative URLs before UNC classification / during icon comparison (P2) — fixed in e968f45d9.

Both threads are the same root cause: //host/path folds to \\host\path, so a scheme-relative URL was classified as UNC and had its name trimmed by the Win32 pass.

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 // (or <scheme>://) is now left as written instead of trimmed. A trailing period therefore stays in the name, and no target_extension is published rather than a wrong one.

Two cases in WindowsShortcutParser.test.ts:

  • RelativePath = "//example.test/app.exe." → no extension published
  • RelativePath = "//example.test/app.exe" → .exe, so the name still yields its extension when there is nothing to trim

Control: reverting the pattern to scheme-only fails the first case alone; the second keeps passing.

This also covers the icon-comparison thread, since iconDiffersFromTarget reads the same extension.

src/native/windows: 110 tests pass; tsc 0; oxlint 0 errors; oxfmt --check, architecture guards pass.

Remaining threads here are the trim-timing pair (Defer trimming until variable prefixes are resolved, Defer LinkInfo trimming until after suffix joining).

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

The two trim-timing threads do not reproduce on e968f45d9. I checked both on the current head before changing anything.

LinkInfo with a device prefix. WindowsShortcutParser.test.ts already asserts this exact input — localBasePath = "\\?\C:\Tools", commonPathSuffix = "app.exe." — and expects no published extension. It passes, because withSuffix derives the extension from the joined text, and fileNameSegment keeps device paths as written.

EnvironmentVariableDataBlock with an unexpanded variable. Measured on this head with extraData: [{ kind: "environment", ansi: "%ROOT%\app.exe.", unicode: "%ROOT%\app.exe." }]:

[{"kind":"target_extension","evidence_kind":"derived","extension":null}]

No .exe is claimed, because the host is never consulted and an unexpanded %VAR% name stays unresolved, so trimming it cannot publish a period the real target would keep.

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 (152ce6103, e968f45d9, plus the refresh ddefef24d), every open thread on this PR now has a disposition:

  • P1 network-path comparison: gate removed, cannot reproduce
  • P2 Win32 trimming gated on the source (152ce6103)
  • P2 scheme-relative URLs preserved (e968f45d9, covers the icon-comparison thread too)
  • P2 trim-timing pair: cannot reproduce, evidence above

@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

Drive paths lose their extension (P2) — fixed in bc9ddac2c. This one was mine: the //-tolerant pattern in isWin32PathText also matched C://Tools/..., because C: looks like a scheme.

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: C://Tools/app.exe. → .exe (drive), //example.test/app.exe. → nothing (scheme-relative or UNC, ambiguous), https://example.test/app.exe. → nothing (URL).

Control: removing the drive arm fails only the drive case.

The remaining thread here is the ANSI-join one (ANSI joins lose trim rules): with an ANSI base and a suffix, withSuffix takes the suffix's own extension instead of trimming the joined text, which is deliberate — the parts cannot be joined into one comparable string — but it does mean a device prefix is not visible at that point. Deciding that one properly needs the suffix to be carried unresolved until the base's encoding is known; I am not going to squeeze it into this branch's shape without measuring it first.

src/native/windows: 111 tests pass; tsc 0; oxlint 0 errors; oxfmt --check, architecture guards pass.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

Recognize URLs without // before Win32 trimming (P2) — fixed in a3ed82f3f. Also mine: the previous predicate only treated <scheme>:// as a URI, so mailto:launcher.exe. and https:example.test/app.exe. fell through to the Win32 name pass and published .exe.

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 written

Cases added: mailto:launcher.exe. → no extension, https:example.test/app.exe. → no extension, C:\Tools\app.exe. → .exe.

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 (\\…), //-leading ambiguous, explicit-scheme URI, and a plain relative name.

src/native/windows: 112 tests pass; tsc 0; oxfmt --check, architecture guards pass.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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("/", "\\"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

Exclude drive designators from the filename segment (P2) — fixed in 3c999557f. Mine again: the Win32 name pass kept C: inside the name, so C:.profile. normalized to C:.profile and published .profile.

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: C:.profile., C:\.profile., and .profile. all publish no extension; C:\Tools\app.exe. still publishes .exe.

Control: removing the designator strip fails only the drive-relative case.

src/native/windows: 113 tests pass; tsc 0; oxfmt --check, architecture guards pass.

For context on this predicate's churn — it has now taken four review rounds (152ce6103, e968f45d9, bc9ddac2c, a3ed82f3f, this one), each time because I widened or narrowed the Win32/URI split without enumerating every shape the bytes can carry. The test file now pins all five: drive, drive-relative hidden name, UNC/device, //-ambiguous, explicit-scheme URI, plus the plain relative name.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

Preserve ambiguity for one-letter URI schemes (P2) — fixed in a398ff0a0. Also mine: x:launcher.exe. hit the drive arm and published .exe.

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("//");                         // // — ambiguous

Cases: x:launcher.exe. → nothing, X:\Tools\app.exe. → .exe (drive path), and the existing C:.profile. → nothing still holds because a designator without a separator is treated as ambiguous rather than trimmed.

Cost stated plainly: a drive-relative path with an extension (C:Tools\app.exe.) now publishes nothing rather than .exe, because the bytes cannot separate it from a one-letter scheme. That follows the repository rule that an unknown stays unknown.

src/native/windows: 114 tests pass; tsc 0; oxfmt --check, architecture guards pass.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

Hidden files gain an extension / Keep hierarchical one-letter URIs ambiguous (P2, two threads) — one fix in ad6c65b0e.

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;
  • C:.profile → .profile after the strip, leading dot → no extension
  • x://example.test/launcher.exe. → //example.test/launcher.exe. → trailing period kept → no extension

This does collide with the earlier C://Tools/app.exe. thread, and I resolved it against that one on purpose: after the designator a forward slash spells the same as a custom URI, so the drive arm now needs a backslash (^[a-z]:\\). C://Tools/app.exe. therefore publishes nothing, and I rewrote that earlier case to say so — publishing a wrong .exe for a URI seemed worse than publishing nothing for a forward-slash drive path. If you would rather keep the drive reading, say so and I will invert it; the two cannot both be satisfied from the bytes.

src/native/windows: 115 tests pass; tsc 0; oxfmt --check, architecture guards pass.

@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

Preserve ID-list item names before extension parsing (P2) — applied in 785677a2c, with a stated test gap.

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 target_extension: the fixture always writes a StringData DefaultEntry (passing relativePath: undefined or null falls back to .\WindowsPowerShell\v1.0\powershell.exe), so a LinkTargetIDList-only link is not reachable and the ID-list target is never the observation's first target. I probed all three spellings — "", null, omitted — and the relative path always wins. So the change is verified by reading, not by a failing-before case. If you want it pinned, the fixture needs an ID-list-only shape; I did not widen the fixture inside this branch.

src/native/windows: 115 tests pass; tsc 0; oxfmt --check, architecture guards pass.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

Keep variable-dependent trailing-space extensions unknown (P2) — fixed in c9309251c.

An unexpanded %VAR% leaves the normalization mode unknown — Win32 would strip a trailing space, a \\?\ verbatim expansion would keep it — so extensionOf now returns nothing for that combination instead of publishing .exe :

if (hasUnexpandedVariable(path) && name.endsWith(" ")) return null;

Cases: %ROOT%\app.exe → no extension; C:\Tools\app.exe → .exe (a literal path has one known mode). Control: removing the guard fails only the variable case.

Correction to something I posted earlier. I replied on the "Defer trimming until variable prefixes are resolved" thread that it did not reproduce, citing extraData %ROOT%\app.exe. producing null. That evidence was wrong: the observation carries the first target, and the fixture always writes a StringData DefaultEntry, so with relativePath: "" the empty entry supplied the null — the environment block was never the observed target. The underlying concern was real, and this commit addresses the trailing-space half of it. I have kept the period half as it stands (the value is already null), but I am flagging the earlier reply so the record is not trusted more than it deserves.

The same fixture limit applies to the ID-list change in 785677a2c: both those sources need a fixture that omits StringData to be observable. If you want all three pinned, that fixture change is the next step and I will make it inside this branch rather than hand-wave it.

src/native/windows: 116 tests pass; tsc 0; oxfmt --check, architecture guards pass.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@XiaoBinGan
XiaoBinGan force-pushed the fix/lnk-win32-trailing-trim branch from c015fec to 1676c70 Compare November 27, 2026 17:54
@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

Both findings are mine and are fixed in 1676c70c1.

Detect separators inside environment variable names. hasUnexpandedVariable excluded / and \ from the variable name, so %A/B%\app.exe. read as literal text and had its period trimmed. A Windows variable name may contain a separator, so only % ends the reference:

/%[^%]+%/u.test(path)

Restrict drive-letter matching to ASCII. ^[a-z] with iu accepts \u212A (Kelvin sign) because case folding maps it onto k. Every designator and scheme pattern is now ASCII-only (/^[A-Za-z]:/u, /^[A-Za-z][A-Za-z0-9+.-]*:/u), and a letter-shaped prefix with a non-ASCII first character is treated as neither drive nor scheme, so \u212A:\\Tools\\app.exe. keeps its terminal period and publishes no extension.

Cases: \u212A:\\Tools\\app.exe. → no extension, %A/B%\app.exe. → no extension. Control: reverting both changes fails exactly those two and nothing else.

src/native/windows: 118 tests pass; tsc 0; oxfmt --check, architecture guards pass.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

Preserve extensions under explicit device prefixes (P2) — fixed in 21d0b6c21.

The unknown-mode guard only applies when the mode is actually unknown. A \\?\ prefix fixes it to verbatim whatever the variable expands to, so the name is now read as written there:

if (hasUnexpandedVariable(path) && !DEVICE_PATH.test(path) && name.endsWith(" "))
  return null;

Case: \\?\C:\%DIR%\app.exe → .exe (the trailing space is part of the verbatim name). Control: removing the device exemption fails only that case; %ROOT%\app.exe still publishes nothing.

src/native/windows: 119 tests pass; tsc 0; oxfmt --check, architecture guards pass.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@XiaoBinGan
XiaoBinGan force-pushed the fix/lnk-win32-trailing-trim branch from 21d0b6c to 17032a8 Compare November 28, 2026 16:38
@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

This branch is now a rebuild on current main, not a merge of the earlier review chase: fourteen commits of interface churn were replaced by one change, 17032a830, and the diff against main is 95 lines in two files.

What it does, in the shape main now has:

  • fileNameSegment is the Win32 name pass: strip trailing spaces and periods, exactly as Win32 does before opening a file. A \\?\ path and an unexpanded %VAR% keep their text, because the mode is fixed to verbatim in one case and unknown in the other.
  • isWin32PathText decides which source gets the pass: a drive designator plus a backslash, or a plain relative name. A scheme: URI keeps its own reading, and // — either a scheme-relative URL or a forward-slash UNC path — stays as written because the bytes do not separate them.
  • A RelativePath decides by its own text; an ID-list file entry names a shell item rather than path text Win32 opens, so it never takes the pass.
  • A variable-dependent trailing space publishes no extension, except under an explicit device prefix, where the mode is already known.

Nine cases in WindowsShortcutParser.test.ts pin it, including the ones that must stay unknown: %ROOT%\app.exe , https://…, mailto:…, x://…, //…, C:.profile..

src/native/windows: 116 tests pass; tsc 0; oxlint 0 errors; oxfmt --check clean; architecture guards across 3322 files.

One thing to flag rather than hide: tests/acceptance/windowsShortcutCli.test.ts > "keeps target_extension unknown through CLI and stdio MCP when higher-precedence paths are unread" fails on clean main as well, with the same assertion — I ran that file with this branch's changes stashed. So it is not from this PR; I am leaving it visible here.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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) &&

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

Fixed in the follow-up commit. The guard was testing the caller's raw spelling, so a slash-spelled //?/C:/%DIR%/app.exe folded to the device form and still returned null.

if (hasUnexpandedVariable(path) && !DEVICE_PATH.test(normalized) && name.endsWith(" "))
  return null;

normalized is the folded value — the same one fileNameSegment already receives — so both spellings are recognised, which matches LOCAL_DRIVE_DEVICE_PATH in the provider.

Case added: //?/C:/%DIR%/app.exe → .exe . Control: reverting to DEVICE_PATH.test(path) fails only that case; \\?\C:\%DIR%\app.exe and %ROOT%\app.exe keep their existing expectations.

src/native/windows: 117 tests pass; tsc 0; oxlint 0 errors; oxfmt --check, architecture guards pass.

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, "");

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.

P1 security 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +316 to +318
hasUnexpandedVariable(path) &&
!DEVICE_PATH.test(normalized) &&
name.endsWith(" ")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Process capture and runtime observation bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants