Skip to content

Fix outline crash on empty heading with trailing space#44

Open
hiroakit wants to merge 1 commit into
developfrom
bugfix/heading-trailing-space
Open

Fix outline crash on empty heading with trailing space#44
hiroakit wants to merge 1 commit into
developfrom
bugfix/heading-trailing-space

Conversation

@hiroakit

@hiroakit hiroakit commented Mar 2, 2026

Copy link
Copy Markdown
Owner

Bugfix Overview

Outline generation could crash when an Org heading line is empty but contains a trailing space (e.g. ** ), causing the Outline view to show only partial results or “No symbols found in document”. The outline should remain functional and include subsequent headings even when empty headings exist.

Problem

  • Observed behavior:
    • Documents containing an empty heading with a trailing space (e.g. ** ) can break symbol generation.
    • VS Code logs show name must not be falsy, and headings after the problematic line are missing from the Outline.
  • Expected behavior:
    • Outline generation should not crash on empty headings; it should continue and show subsequent headings.

Reproduction Steps

  1. Open an .org document containing a heading like ** (asterisks + space only).
  2. Open the Outline view.
  3. Observe missing headings after that line and/or “No symbols found in document”, with name must not be falsy in the console.

Root Cause

  • utils.getHeaderTitle() could return an empty string for headings like ** .
  • OrgFoldingAndOutlineDocumentState passes that title to SymbolInformation, and VS Code rejects falsy symbol names, throwing name must not be falsy and interrupting symbol computation.
  • Why it was missed:
    • Existing tests did not exercise the Outline symbol provider path with empty headings.

Fix

  • Fix approach:
    • Ensure getHeaderTitle() never returns an empty string by falling back to a placeholder ((empty heading)) when the extracted title is blank after trimming.
  • Alternatives considered:
    • Skipping empty headings (would hide structure from Outline).
    • Handling it only in the outline provider (would duplicate title-normalization logic).

Verification

  • Automated test added or updated
  • Existing tests pass
  • Test notes:
    • npm test
    • Added test/outline.test.ts to validate that vscode.executeDocumentSymbolProvider does not break on ** and that subsequent headings are still present.

Impact / Risk

  • Affected users:
    • Anyone editing Org documents that contain empty headings with trailing spaces.
  • Backward compatibility:
    • Low risk. Only affects the displayed name for empty headings in Outline.
  • Potential side effects:
    • Empty headings will appear as (empty heading) in Outline instead of being blank (which previously crashed).

Related Issues / PRs

Co-authored-by: hiroakit <hiroakit@users.noreply.github.com>
@hiroakit hiroakit added type:bug Something is broken or regressed. area:core Core extension behavior or commands. area:tests Unit/integration tests. labels Mar 2, 2026
@hiroakit hiroakit added this to the March-April 2026 milestone Mar 2, 2026
@hiroakit hiroakit self-assigned this Mar 2, 2026
@hiroakit hiroakit added the status:in-progress Actively being worked on. label Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core Core extension behavior or commands. area:tests Unit/integration tests. status:in-progress Actively being worked on. type:bug Something is broken or regressed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants