fix(utils): stop createExcerpt leaking a multi-line JSX element into the description#12215
fix(utils): stop createExcerpt leaking a multi-line JSX element into the description#12215gunjanjaswal wants to merge 2 commits into
Conversation
|
Hi @gunjanjaswal! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Motivation
Fixes #12214.
createExcerptbuilds the autodescription/og:descriptionby scanning a doc line by line. It strips HTML/JSX with/<[^>]*>/g, which only matches a tag that opens and closes on the same line. When the first content node is a multi-line JSX/MDX element, only its first line is seen (e.g.<MyComponent), the regex finds no>, nothing is stripped, and that partial tag becomes the page description — e.g.<meta name="description" content="<MyComponent">.This adds an
inHTMLstate next to the existinginImport/inCodehandling: when a line opens a tag with no>on the same line, skip lines until it closes. Single-line and self-closing tags are unchanged (the existing regex still handles them). The guard only triggers when a line starts (after whitespace) with<Tagand has no>, so it doesn't touch prose or current behavior.Test Plan
Added
creates excerpt after a multi-line JSX elementinmarkdownUtils.test.ts. It fails before the change (excerpt is<MyComponent) and passes after. Runs with the existingdocusaurus-utilsunit tests.