Skip to content

Commit 985cb2c

Browse files
cdervclaude
andcommitted
Use CSS.escape() and closest() in tab activation
Escape pane IDs with CSS.escape() before interpolating into querySelector selectors to handle special characters in user-derived tab IDs. Use closest(".tab-content") instead of parentElement for resilience to intermediate wrapper elements. Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent 4ababfe commit 985cb2c

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/resources/projects/website/search/quarto-search.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,8 +1129,8 @@ function activateTabsWithMatches(mainEl) {
11291129
for (const mark of marks) {
11301130
const pane = mark.closest(".tab-pane");
11311131
if (!pane) continue;
1132-
const tabContent = pane.parentElement;
1133-
if (!tabContent || !tabContent.classList.contains("tab-content")) continue;
1132+
const tabContent = pane.closest(".tab-content");
1133+
if (!tabContent) continue;
11341134

11351135
if (!tabsetMatches.has(tabContent)) {
11361136
tabsetMatches.set(tabContent, { activeHasMatch: false, firstInactivePane: null });
@@ -1147,8 +1147,9 @@ function activateTabsWithMatches(mainEl) {
11471147
for (const [, info] of tabsetMatches) {
11481148
if (info.activeHasMatch || !info.firstInactivePane) continue;
11491149

1150+
const escapedId = CSS.escape(info.firstInactivePane.id);
11501151
const tabButton = mainEl.querySelector(
1151-
`[data-bs-toggle="tab"][data-bs-target="#${info.firstInactivePane.id}"]`
1152+
`[data-bs-toggle="tab"][data-bs-target="#${escapedId}"]`
11521153
);
11531154
if (tabButton) {
11541155
new bootstrap.Tab(tabButton).show();

0 commit comments

Comments
 (0)