Skip to content

Fix index.html clean-URL rewrite mangling alternate-format links on index pages#14670

Open
cscheid wants to merge 1 commit into
mainfrom
fix/14667-index-html-clean-url-rewrite
Open

Fix index.html clean-URL rewrite mangling alternate-format links on index pages#14670
cscheid wants to merge 1 commit into
mainfrom
fix/14667-index-html-clean-url-rewrite

Conversation

@cscheid

@cscheid cscheid commented Jul 11, 2026

Copy link
Copy Markdown
Member

Closes #14667.

Problem

quarto-nav.js rewrites every link on page load to clean up index.html URLs, using an unanchored regex (/\/index\.html/). Any href that merely contains /index.html as a prefix gets mangled: on a site's index page, the "Other Formats" link to index.html.md (the markdown twin produced when output-file: index.html is paired with a markdown format — e.g. by nbdev for llms.txt workflows) was rewritten to /.md, which 404s. Live example in the issue: the CommonMark link on https://fastcore.fast.ai/.

Fix

Anchor the regex to the end of the path, still allowing a query or fragment:

links[i].href = links[i].href.replace(/\/index\.html(?=[?#]|$)/, "/");
href ends with… before after
/index.html / / (same)
/index.html#sec /#sec /#sec (same)
/index.html?a=1 /?a=1 /?a=1 (same)
/index.html.md /.md unchanged ✅
/index.html/foo //foo unchanged ✅

The same unanchored pattern existed in two more places, fixed identically:

  • itemHasNavTarget in src/project/types/website/website-shared.ts (navbar/sidebar active-state matching)
  • the preview reload-target normalization in src/webui/quarto-preview/src/server/navigation.ts (checked-in bundle rebuilt with npm run build; one-line diff)

Tests

New playwright test (website-index-html-links.spec.ts + site under tests/docs/playwright/website/issue-14667/) covering all five cases above; passes in chromium/firefox/webkit and verified to fail against the old regex. The test site uses hand-written links rather than the issue's output-file: index.html + commonmark config because that config cannot currently render — that's a separate pre-existing bug, filed as #14669.

Also verified manually: rebuilt the issue's repro with this branch, served it over http, and confirmed in a browser that the CommonMark link keeps index.html.md while clean-URL rewriting and navbar active-state marking still behave (existing blog-simple-blog and html-toc-js specs still pass).

🤖 Generated with Claude Code

)

The client-side clean-URL rewrite in quarto-nav.js stripped /index.html
anywhere in an href, so on index pages the "Other Formats" link to
index.html.md (the markdown twin produced when output-file: index.html
is paired with a markdown format, e.g. by nbdev for llms.txt workflows)
was rewritten to /.md and 404ed. Anchor the regex to the end of the
path (still allowing a query or fragment) so only genuine index.html
links are cleaned.

Apply the same anchoring to the two other occurrences of the pattern:
itemHasNavTarget in website-shared.ts (navbar/sidebar active-state
matching) and the preview reload-target normalization in
quarto-preview's navigation.ts (bundle rebuilt; one-line diff).

Add a playwright regression test covering the rewrite cases, verified
to fail against the unanchored regex.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@posit-snyk-bot

posit-snyk-bot commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

quarto-nav.js's index.html clean-URL rewrite mangles alternate-format links on index pages

2 participants