From 175fae695ce52f72f805e3861a8751eb631316c4 Mon Sep 17 00:00:00 2001
From: Anders Kaseorg
Date: Wed, 3 Apr 2019 15:08:57 -0700
Subject: [PATCH] Improve worst-case performance of inline.text regex
The old regex may take quadratic time to scan for potential email
addresses starting at every point. Fix it to avoid scanning from
points that would have been in the middle of a previous scan.
Signed-off-by: Anders Kaseorg
---
lib/marked.js | 5 +----
test/specs/gfm/gfm.0.28.json | 3 +--
2 files changed, 2 insertions(+), 6 deletions(-)
diff --git a/lib/marked.js b/lib/marked.js
index 9d7c1555f3..a7cbe20097 100644
--- a/lib/marked.js
+++ b/lib/marked.js
@@ -615,10 +615,7 @@ inline.gfm = merge({}, inline.normal, {
url: /^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,
_backpedal: /(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,
del: /^~+(?=\S)([\s\S]*?\S)~+/,
- text: edit(inline.text)
- .replace(']|', '~]|')
- .replace('|$', '|https?://|ftp://|www\\.|[a-zA-Z0-9.!#$%&\'*+/=?^_`{\\|}~-]+@|$')
- .getRegex()
+ text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\a.b-c_d@a.b
\na.b-c_d@a.b.
\na.b-c_d@a.b-
\na.b-c_d@a.b_
",
"markdown": "a.b-c_d@a.b\n\na.b-c_d@a.b.\n\na.b-c_d@a.b-\n\na.b-c_d@a.b_",
- "example": 607,
- "shouldFail": true
+ "example": 607
},
{
"section": "Disallowed Raw HTML",