Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -729,11 +729,12 @@ export class _Tokenizer<ParserOutput = string, RendererOutput = string> {
emStrong(src: string, maskedSrc: string, prevChar = ''): Tokens.Em | Tokens.Strong | undefined {
let match = this.rules.inline.emStrongLDelim.exec(src);
if (!match) return;
if (!match[1] && !match[2] && !match[3] && !match[4]) return;

// _ can't be between two alphanumerics. \p{L}\p{N} includes non-english alphabet/numbers as well
if (match[3] && prevChar.match(this.rules.other.unicodeAlphaNumeric)) return;
if (match[4] && prevChar.match(this.rules.other.unicodeAlphaNumeric)) return;

const nextChar = match[1] || match[2] || '';
const nextChar = match[1] || match[3] || '';

if (!nextChar || !prevChar || this.rules.inline.punctuation.exec(prevChar)) {
// unicode Regex counts emoji as 1 char; spread into array for proper count (used multiple times below)
Expand Down
2 changes: 1 addition & 1 deletion src/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ const blockSkip = edit(/link|precode-code|html/, 'g')
.replace('html', /<(?! )[^<>]*?>/)
.getRegex();

const emStrongLDelimCore = /^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/;
const emStrongLDelimCore = /^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/;

const emStrongLDelim = edit(emStrongLDelimCore, 'u')
.replace(/punct/g, _punctuation)
Expand Down
4 changes: 4 additions & 0 deletions test/specs/redos/quadratic_emstrong_delim.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
markdown: '_'.repeat(10000) + ' a',
html: `<p>${'_'.repeat(10000)} a</p>\n`,
};