Skip to content

fix(desktop): skip only ASCII whitespace before a desktop entry key - #13126

Merged
N0zoM1z0 merged 1 commit into
morluto:mainfrom
Shelden-Hao:fix/desktop-entry-ascii-line-padding
Nov 21, 2026
Merged

N0zoM1z0 merged 1 commit into
morluto:mainfrom
Shelden-Hao:fix/desktop-entry-ascii-line-padding

Conversation

@Shelden-Hao

@Shelden-Hao Shelden-Hao commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes a parse drift in the desktop-entry reader: REA stripped each line with JavaScript's Unicode-aware trimStart(), while GLib skips only g_ascii_isspace before a key. A record indented with U+00A0, U+3000 or U+FEFF was read as a normal Name=/Hidden= line by REA and as a malformed record by GLib.

This follows #12708, which closed the same gap for group headers by validating the captured padding against GLib's ASCII set. The blank-line, comment and key checks still used the Unicode-aware trim.

Problem and expected behavior

Smallest trigger:

[Desktop Entry]
Type=Application
Name=User notes
\u00a0Hidden=true

GLib keeps the U+00A0 in the key, so it never reads Hidden and the entry stays visible. REA read hidden: true and no malformed_line, so findHiddenDesktopEntry() claimed the deletion that masks the application.

Violated invariant: the hidden override may only claim a deletion after the entry establishes its structure (Claim deletion only after the hidden entry establishes its structure). A padding the format owner rejects must not create that claim.

Expected behavior: a line whose leading whitespace is not GLib's ASCII set is malformed, so the override is refused instead of masking the application.

Change and scope

readDesktopEntryFields now strips only [ \t\f\r] before deciding whether a line is blank, a comment or a key, and hands that same string to the record matcher. GROUP.exec(raw) still receives the raw line, because the group branch needs the original padding for its own validation.

The ASCII set is the one #12708 and BOOLEAN_TRUE already use, so all three checks in this reader now agree on what GLib skips.

Not included: the APT reader and the other desktop readers. aptRepositories.ts already routes deb822 lines through trimDeb822Line, whose comment states it matches APT's ASCII whitespace; changing unrelated readers would widen this diff beyond the reported drift.

Contract and boundary impact

  • Semantic owner and earliest changed stage: readDesktopEntryFields in src/domain/desktop/desktopEntry.ts owns the line classification. Consumers are parseDesktopEntry, replaceDesktopExec and, through them, LinuxApplicationInventory (findHiddenDesktopEntry, launcher rewrite). No superseded path is left behind: the Unicode trim was the only place that widened the padding.
  • Contribution scope fit and linked maintainer decision: ordinary fix inside an existing boundary; no new provider, execution, injection or mutation authority. Not applicable.
  • CLI and MCP/tool-catalog contract: none. The parsed DesktopEntry shape and the refusal reasons are unchanged.
  • Provider, bridge, target-format, or platform compatibility: linux-desktop-entry only. The parser is platform-independent and runs on Windows, where the Linux inventory suite is skipped.
  • Evidence, artifact, provenance, or reconstruction contract: a malformed structure now surfaces as malformed_line, so an override that GLib would not honour is refused with desktop_entry_invalid instead of producing a hidden claim.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): findHiddenDesktopEntry refuses the entry; it does not delete anything new.
  • Generated metadata, package, or installation impact: none.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: three parseDesktopEntry cases for a key indented with U+00A0, U+3000 and U+FEFF; two cases asserting such a line is neither blank nor a comment; one regression case keeping ASCII space and tab indentation parsed without malformed_line; two rows in the refuses a hidden override with malformed structure table for inventory.

  • Base reproduction or other evidence: reverting only the source change (keeping the new tests) fails 6 of them, while the ASCII regression case still passes:

    × refuses a key indented with "\u00a0", which GLib keeps inside the key
    × refuses a key indented with "\u3000", which GLib keeps inside the key
    × refuses a key indented with "\ufeff", which GLib keeps inside the key
    × does not read a "\u00a0" line as a blank or a comment
    × does not read a "\u3000" line as a blank or a comment
    × does not read a "\ufeff" line as a blank or a comment
    
  • User-visible CLI/MCP output: not applicable; no output shape changes.

  • Remaining proof gaps: the LinuxApplicationInventory suite is describe.skipIf(process.platform === "win32"), so the two inventory rows only execute in CI on Linux. No real GLib run was available here; the expected behaviour is taken from g_ascii_isspace and from the ASCII set fix(desktop): validate group padding before hidden ID masking #12708 already established in this file.

Validation performed

  • node node_modules/vitest/vitest.mjs run src/domain/desktop/desktopEntry.test.ts — 45 passed
  • node node_modules/vitest/vitest.mjs run src/domain/desktop/desktopEntry.test.ts src/desktop/LinuxApplicationInventory.test.ts — 45 passed, 71 skipped (Windows host)
  • node node_modules/oxfmt/bin/oxfmt --check src/domain/desktop/desktopEntry.ts src/domain/desktop/desktopEntry.test.ts src/desktop/LinuxApplicationInventory.test.ts — all matched files use the correct format
  • node scripts/run-typescript.mjs --noEmit — exit 0
  • node node_modules/oxlint/bin/oxlint src/domain/desktop/desktopEntry.ts src/domain/desktop/desktopEntry.test.ts src/desktop/LinuxApplicationInventory.test.ts — 0 errors; the two warnings (no-control-regex on the existing group-name class, complexity on the existing reader) are present on the base revision too

Compatibility, safety, and release

  • Breaking changes or migration steps: none. ASCII space and tab indentation keep parsing as before; only lines whose padding GLib rejects become malformed.
  • Real Hopper/Ghidra, browser, or OS coverage: no provider involved. The desktop-entry parser is pure text; the two inventory rows run in CI's Linux lane.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: this narrows an over-claim. A hidden override padded with a Unicode space is now refused, so it cannot mask an application that the desktop environment still shows.

Author readiness

Human owner: @Shelden-Hao

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

The key reader stripped each line with JavaScript's trimStart(), which also
removes Unicode spaces such as U+00A0 and U+3000. GLib skips only
g_ascii_isspace, so it keeps those bytes inside the key and the record never
matches Name= or Hidden=.

The drift had a safety direction: a line indented with U+00A0 and reading
Hidden=true was accepted as a hidden override by REA but never by the desktop
environment, so findHiddenDesktopEntry() claimed a deletion that GLib would not
honour. morluto#12708 closed this for group headers by validating the captured padding
against GLib's ASCII set; the blank-line, comment and key checks still used the
Unicode-aware trim.

I now strip only [ \t\f\r] before deciding whether a line is blank, a comment
or a key, and hand that same string to the record matcher. ASCII indentation
still parses as before. The inventory test covers the refusal when a hidden
override carries the padding, and the domain tests cover the three Unicode
spaces for keys, blank lines and comments.
@greptile-apps

greptile-apps Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issue was found.

Summary

The PR makes readDesktopEntryFields remove only ASCII padding before checking blank lines, comments, and keys.

  • Desktop-entry lines keep Unicode padding that GLib does not skip.

Reviews (3) · Last reviewed commit: "fix(desktop): skip only ASCII whitespace..." · Reviewed by Greptile

@Shelden-Hao
Shelden-Hao marked this pull request as ready for review November 21, 2026 15:33

@gensokyo-dev gensokyo-dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Verified: the new desktopEntry cases fail on main and pass here; LinuxApplicationInventory and desktopEntry suites pass (116 tests). Leading-space set matches the existing GLib group padding rule. Thanks.

@N0zoM1z0
N0zoM1z0 merged commit a44e705 into morluto:main Nov 21, 2026
40 of 42 checks passed
@morluto morluto added bug Something isn't working area: runtime Process capture and runtime observation labels Nov 22, 2026
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.

5 participants