Skip to content

Search highlighting does not properly escape HTML #2879

@jbms

Description

@jbms

Contribution guidelines

I've found a bug and checked that ...

  • ... the problem doesn't occur with the mkdocs or readthedocs themes
  • ... the problem persists when all overrides are removed, i.e. custom_dir, extra_javascript and extra_css
  • ... the documentation does not mention anything about my problem
  • ... there are no open or closed issues that are related to my problem

Description

Search highlighting obtains the textContent of nodes, applies replacements, and then adds it back as innerHTML.

Consequently, text that looks like HTML tags can get mangled.

Instead, escapeHTML(value) should be used prior to applying the replacements in src/assets/javascripts/integrations/search/highlighter/index.ts.

Example link:

https://squidfunk.github.io/mkdocs-material/customization/?h=your#additional-variables

Note that the the <!-- Add your additional information here --> text disappears when we add the ?h=your parameter.

Expected behaviour

n/a

Actual behaviour

n/a

Steps to reproduce

n/a

Package versions

mkdocs-material master as of 2021-07-28:

e29dfd0

Configuration

n/a

System information

n/a

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue reports a bugresolvedIssue is resolved, yet unreleased if open

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions