Skip to content

Closes #11884 fix searchtools.js: docContent.textContent #11885

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 21, 2024

Conversation

kkntl
Copy link
Contributor

@kkntl kkntl commented Jan 16, 2024

Subject: fix bug #11884 (searchtools.js, docContent would be null instead of undefined)

Feature or Bugfix

  • Bugfix

Purpose

  • Check docContent, returned by document.querySelector, for "truthy" instead of !== undefined.

@AA-Turner
Copy link
Member

Is it possible to add a test for this?

@@ -164,7 +164,7 @@ const Search = {
const htmlElement = new DOMParser().parseFromString(htmlString, 'text/html');
htmlElement.querySelectorAll(".headerlink").forEach((el) => { el.remove() });
const docContent = htmlElement.querySelector('[role="main"]');
if (docContent !== undefined) return docContent.textContent;
if (docContent) return docContent.textContent;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, and seems consistent with our validation of querySelector results in doctools.js here:

const prevLink = document.querySelector('link[rel="prev"]');
if (prevLink && prevLink.href) {

@AA-Turner AA-Turner merged commit 7041f11 into sphinx-doc:master Jan 21, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 21, 2024
@AA-Turner AA-Turner added this to the 7.3.0 milestone Jul 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants