Table of contents highlight stops working when a heading id contains a percent sign

Aperta Adatta ai principianti
#15,297 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript
Ambito
frontend

Direzione di ricerca

Inizia dal gestore DOMContentLoaded in src/resources/formats/html/quarto.js, in particolare dalla chiamata a decodeURI alle righe 145–152. Riproduci il problema con il documento Quarto fornito che usa id="bad%zz", poi verifica che lo scorrimento aggiorni l’indice e che la destinazione malformata non generi più un URIError non gestito. Il rapporto suggerisce di ripiegare sulla destinazione originale quando la decodifica non riesce.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug html
I have:
  • searched the issue tracker for similar issues
  • installed the latest version of Quarto CLI
  • formatted my issue following the Bug Reports guide
Bug description

quarto.js passes each table of contents data-scroll-target through decodeURI.
A heading id with a % that does not start a valid escape, such as {id="bad%zz"}, makes decodeURI throw URIError: URI malformed.
The error is not caught, so the rest of that DOMContentLoaded handler does not run.
The visible effect: the table of contents no longer follows the scroll position.

https://github.com/quarto-dev/quarto-cli/blob/089ba530b3ed4ec156a355d41b6b7de2db3e44ea/src/resources/formats/html/quarto.js#L145-L152

This is an edge case.
Only an explicit id="..." attribute triggers it.
Automatic ids drop the %, and Pandoc does not read {#bad%zz} as an attribute, so both are safe.
A valid escape such as id="bad%20ok" is also safe.
At render time, Quarto already warns: WARN: Invalid URI '#bad%zz' in attribute 'href' of element 'A'.

Steps to reproduce
---
title: "Repro"
format:
  html:
    toc: true
---

## Fine

Text.

## Bad target {id="bad%zz"}

Text.

## Last

Text.
  1. Run quarto render and serve the output over HTTP.
  2. Open the page and scroll down.
Actual behavior

The console shows Uncaught URIError: URI malformed from quarto.js.
After scrolling, the table of contents still highlights "Fine".

Expected behavior

The table of contents highlights the section in view, as it does when the id has no %.
A target that cannot be decoded could fall back to the raw value.

Your environment
  • IDE: none, command line.
  • OS: macOS 27.2.
  • Browser: Brave, Chromium 156.0.8078.80.
Quarto check output

Reproduced with a development build of main at 089ba530b.

Quarto 99.9.9
[✓] Checking environment information...
      Quarto cache location: /Users/mcanouil/Library/Caches/quarto
      Project: none found (single-file mode)
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.10.0: OK
      Dart Sass version 1.107.1: OK
      Deno version 2.9.8: OK
      Typst version 0.15.1: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 99.9.9
      commit: 089ba530b3ed4ec156a355d41b6b7de2db3e44ea
      Path: /Users/mcanouil/Projects/quarto-dev/quarto-cli/package/dist/bin
[✓] Checking tools....................OK
      TinyTeX: v2026.07
      Chrome Headless Shell: (not installed)
      VeraPDF: (not installed)
[✓] Checking LaTeX....................OK
      Using: TinyTex
      Path: /Users/mcanouil/Library/TinyTeX/bin/universal-darwin
      Version: 2026
[✓] Checking Chrome Headless....................OK
      Using: Chrome from QUARTO_CHROMIUM
      Path: /Applications/Brave Browser.app/Contents/MacOS/Brave Browser
[✓] Checking basic markdown render....OK
Lingua principale
JavaScript
Stelle
6.1k
Fork
478
Merge medio
17h 53m
PR unite (30g)
135

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di quarto-dev/quarto-cli

Tutte le issue di quarto-dev/quarto-cli

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.