Skip to content
Permalink
Browse files Browse the repository at this point in the history
Merge pull request from GHSA-55xv-f85c-248q
Fix performance issues of tags in blockquote
  • Loading branch information
yhatt committed Dec 17, 2021
2 parents a8613da + 7f739e4 commit 36e4a10
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Fixed

- Fix performance issues of tags in `<blockquote>`

## v4.5.0 - 2021-12-02

### Added
Expand Down
5 changes: 2 additions & 3 deletions src/mrkdwn/escape.ts
Expand Up @@ -8,9 +8,8 @@ const generateReplacerForEscape = (fallback: string) => (matched: string) =>
export const escapeReplacers = {
blockquote: (partial: string) =>
partial
.replace(
/^((?:<.*?>)*)(&gt;)/gm,
(_, leading, character) => `${leading}\u00ad${character}`
.replace(/^((?:<.*?>)*)(.{4})/gm, (matched, leading, character) =>
character === '&gt;' ? `${leading}\u00ad&gt;` : matched
)
.replace(
/^((?:<.*?>)*)()/gm,
Expand Down
15 changes: 15 additions & 0 deletions test/mrkdwn.tsx
Expand Up @@ -587,6 +587,21 @@ describe('HTML parser for mrkdwn', () => {
).toBe('&gt; *A*\n&gt; \n&gt; *_B_*\n&gt; \n&gt; *C*\n&gt; ')
})

it('renders many tags in the blockquote tag immediately', () => {
const startTime = Date.now()

mrkdwn(
<blockquote>
{[...Array(30)].map((_, i) => (
<b>{i}</b>
))}
</blockquote>
)

const processTime = Date.now() - startTime
expect(processTime).toBeLessThan(1000)
})

it('ignores invalid double markup', () =>
expect(
mrkdwn(
Expand Down

3 comments on commit 36e4a10

@Ronaltor

This comment was marked as spam.

@Ronaltor

This comment was marked as spam.

@Ronaltor

This comment was marked as spam.

Please sign in to comment.