fix: escape markdown special characters in markdown reporter#6155
Open
deeferentleeg wants to merge 2 commits into
Open
fix: escape markdown special characters in markdown reporter#6155deeferentleeg wants to merge 2 commits into
deeferentleeg wants to merge 2 commits into
Conversation
Suite and test titles containing markdown special characters (e.g. *, _, #, [], ()) were inserted verbatim into the generated markdown, breaking its semantics. Add an escapeMarkdown() helper that backslash-escapes GitHub-Flavored Markdown special characters and apply it to suite titles in TOC links and headings, and to test titles in pass output. closes mochajs#2306
Add test cases verifying that markdown special characters in suite and test titles are properly escaped in the markdown reporter output. Refs mochajs#2306
|
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.
PR Checklist
status: accepting prsOverview
The markdown reporter (
-R md) inserts suite and test titles verbatim into the generated markdown. When a title contains characters that have special meaning in GitHub-Flavored Markdown (e.g.*,_,#,[,],(,), backticks), the output's semantics are broken — headings render incorrectly, links point to wrong anchors, and emphasis marks are misinterpreted.This PR adds an
escapeMarkdown()helper that backslash-escapes the full set of GFM special characters and applies it in three places:stringifyTOC): suite titles in the table of contents are now escaped.title()->EVENT_SUITE_BEGIN): suite titles used as markdown headings are now escaped.EVENT_TEST_PASS): test titles in the body output are now escaped.The
utils.slug()function (used for anchor names) already strips all non-word characters, so anchor links remain unaffected — only the human-visible text is escaped.Example
Before:
After:
AI Disclosure
Portions of this PR were generated with the assistance of AI tools. The code has been manually reviewed for correctness, security, and adherence to project conventions. I am responsible for understanding and maintaining this code.