Fix index.html clean-URL rewrite mangling alternate-format links on index pages#14670
Open
cscheid wants to merge 1 commit into
Open
Fix index.html clean-URL rewrite mangling alternate-format links on index pages#14670cscheid wants to merge 1 commit into
cscheid wants to merge 1 commit into
Conversation
) 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>
Collaborator
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #14667.
Problem
quarto-nav.jsrewrites every link on page load to clean upindex.htmlURLs, using an unanchored regex (/\/index\.html/). Any href that merely contains/index.htmlas a prefix gets mangled: on a site's index page, the "Other Formats" link toindex.html.md(the markdown twin produced whenoutput-file: index.htmlis 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:
/index.html//(same)/index.html#sec/#sec/#sec(same)/index.html?a=1/?a=1/?a=1(same)/index.html.md/.md❌/index.html/foo//foo❌The same unanchored pattern existed in two more places, fixed identically:
itemHasNavTargetinsrc/project/types/website/website-shared.ts(navbar/sidebar active-state matching)src/webui/quarto-preview/src/server/navigation.ts(checked-in bundle rebuilt withnpm run build; one-line diff)Tests
New playwright test (
website-index-html-links.spec.ts+ site undertests/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'soutput-file: index.html+commonmarkconfig 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.mdwhile clean-URL rewriting and navbar active-state marking still behave (existingblog-simple-blogandhtml-toc-jsspecs still pass).🤖 Generated with Claude Code