Skip to content

Commit

Permalink
fix: fix quadratic execution in em mask (#2818)
Browse files Browse the repository at this point in the history
* fix: fix redos in em mask

* also remove (
  • Loading branch information
UziTech authored May 26, 2023
1 parent 46f4e5c commit a37fe8e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ inline._punctuation = '!"#$%&\'()+\\-.,/:;<=>?@\\[\\]`^{|}~';
inline.punctuation = edit(inline.punctuation).replace(/punctuation/g, inline._punctuation).getRegex();

// sequences em should skip over [title](link), `code`, <html>
inline.blockSkip = /\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g;
inline.blockSkip = /\[[^[\]]*?\]\([^\(\)]*?\)|`[^`]*?`|<[^<>]*?>/g;
// lookbehind is not available on Safari as of version 16
// inline.escapedEmSt = /(?<=(?:^|[^\\)(?:\\[^])*)\\[*_]/g;
inline.escapedEmSt = /(?:^|[^\\])(?:\\\\)*\\[*_]/g;
Expand Down
5 changes: 3 additions & 2 deletions test/helpers/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ export function loadFiles(dir) {
return obj;
}

for (const spec of specs) {
for (let i = 0; i < specs.length; i++) {
const spec = specs[i];
if (!spec.section) {
spec.section = name;
spec.section = `${name}[${i}]`;
}
if (!obj[spec.section]) {
obj[spec.section] = {
Expand Down
18 changes: 18 additions & 0 deletions test/specs/redos/quadratic_em_mask.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = [
{
markdown: '['.repeat(100000),
html: `<p>${'['.repeat(100000)}</p>`
},
{
markdown: '[.'.repeat(50000),
html: `<p>${'[.'.repeat(50000)}</p>`
},
{
markdown: '<'.repeat(100000),
html: `<p>${'<'.repeat(100000)}</p>`
},
{
markdown: '<.'.repeat(50000),
html: `<p>${'<.'.repeat(50000)}</p>`
}
];

1 comment on commit a37fe8e

@vercel
Copy link

@vercel vercel bot commented on a37fe8e May 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.