fix(utils): correct auto-generated description when H1 heading text contains # (e.g. C#)#12308
Open
DhineshPonnarasan wants to merge 3 commits into
Open
fix(utils): correct auto-generated description when H1 heading text contains # (e.g. C#)#12308DhineshPonnarasan wants to merge 3 commits into
DhineshPonnarasan wants to merge 3 commits into
Conversation
…#12120) The example artifacts were regenerated for the v3.10.1 maintenance release, which reverted the engine field from '>=24.14' back to '>=20.0' and left the sandbox node version at '18'. Update the examples to reflect current maintainer intent: - Bump engines.node from '>=20.0' to '>=24.14' (reapplies PR facebook#11914 change overwritten by PR facebook#11985) - Bump sandbox.config.json node from '18' to '24' (syncs with generateExamples.js updated in PR facebook#12080)
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
…ontains # (e.g. C#) ## Root Cause The H1 heading regex /^#[^#]+#?/gm used [^#]+ (one or more non-hash chars) followed by an optional #?. When heading text contained # (e.g., C#), the [^#]+ matched up to the first # inside the text, and #? consumed it. For # C# Programming Guide: - #[^#]+ matched # C - #? consumed the # (from C#) - Leftover: Programming Guide → became the excerpt ## Fix Changed regex to /^#(?!#).*/gm: - ^# matches the opening hash - (?!#) negative lookahead ensures this is H1 (not ## H2+) - .* consumes the entire line, including any # characters in the text The negative lookahead (?!#) is the correct way to distinguish H1 from H2+ without relying on [^#] as a delimiter for heading text content. ## Tests Added - H1 with C# in heading text - H1 with F# in heading text - H1 with trailing ATX closing marker (# C# Programming Guide #) - H2+ with C# in heading text (regression: H2 extraction unchanged) - Normal H1 (no hash in text) still correctly stripped All 275 existing tests continue to pass. Fixes facebook#12305
DhineshPonnarasan
force-pushed
the
fix/h1-csharp-excerpt
branch
from
July 22, 2026 16:41
f12b126 to
bd44ad2
Compare
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.
Summary
Fixes #12305 — auto-generated meta description is incorrect when an H1 heading contains
#in its text (e.g.,C#,F#).Root Cause
In
createExcerpt(), the H1-stripping regex/^#[^#]+#?/gmuses[^#]+(one or more non-hash characters) followed by an optional#?. The[^#]character class was originally intended as a sentinel to prevent matching##H2+ headings, but it also acts as a delimiter that stops at any#in the heading text.For
# C# Programming Guide:#[^#]+matches# C#?consumes the#(fromC#)# C#, leavingProgramming Guideas the excerptWhy this is the smallest safe fix
The regex is changed from
/^#[^#]+#?/gmto/^#(?!#).*/gm:^#matches the opening hash(?!#)negative lookahead distinguishes H1 from H2+ (equivalent to##).*consumes the entire line, including any#characters in the textThe negative lookahead
(?!#)is the correct semantic primitive — it says "match H1 but not H2+" without introducing a character class that collides with heading text content. No other part of the pipeline changes, and no dependencies are added.Tests added
C#F### C# Programming Guide #also affectedC#All 275 existing tests continue to pass.
AI disclosure: This PR was authored with the assistance of an AI coding agent, under my direction and review.