Uh oh!
There was an error while loading. Please reload this page.
Improve worst-case performance of inline.text regex - #1460
Conversation
actual diff of gfm inline.text - /^(`+|[^`])[\s\S]*?(?=[\\<!\[`*~]|\b_| {2,}\n|https?:\/\/|ftp:\/\/|www\.|[a-zA-Z0-9.!#$%&'*+\/=?^_`{\|}~-]+@|$)/+ /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\<!\[`*~]|\b_| {2,}\n|https?:\/\/|ftp:\/\/|www\.|$)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))/ |
UziTech
left a comment
There was a problem hiding this comment.
Could you add a redos test in /test/redos/ that will fail before this change and pass after?
175fae6 to
18dbc0bCompareandersk
commented
Apr 3, 2019
(Updated to address a separate quadratic slowdown in the same regex.) @UziTech Do you want me to literally drop in a gigantic |
UziTech
commented
Apr 3, 2019
Tests that take longer than 1 second are marked as failed. maybe slim it down to a test taking 2 seconds before this fix. |
18dbc0b to
bd789b3Compareandersk
commented
Apr 4, 2019
@UziTech Done. |
Uh oh!
There was an error while loading. Please reload this page.
The old regex may take quadratic time to scan for potential line breaks or 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 <andersk@mit.edu>
830413b to
be27472CompareUziTech
commented
Apr 4, 2019
@davisjam do you want to look at this and make sure no redos vectors are added? |
| br: /^( {2,}|\\)\n(?!\s*$)/, | ||
| del: noop, | ||
| text: /^(`+|[^`])[\s\S]*?(?=[\\<!\[`*]|\b_|{2,}\n|$)/ | ||
| text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\<!\[`*]|\b_|$)|[^ ](?= {2,}\n))|(?= {2,}\n))/ |
| .replace(']|', '~]|') | ||
| .replace('|$', '|https?://|ftp://|www\\.|[a-zA-Z0-9.!#$%&\'*+/=?^_`{\\|}~-]+@|$') | ||
| .getRegex() | ||
| text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\<!\[`*~]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))|(?= {2,}\n|[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))/ |
UziTech
commented
Apr 5, 2019
This will be released in v0.6.2 🎉 #1441 |
Cannot use **(WhiteSpace)(WhiteSpace)(Return)** to break line while only one characher before it. And if use special character, it will reset the character count brought by [#1460](markedjs/marked#1460)
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.
Marked version:
0.1.3 and later (problem introduced by commit 00f1f7a)
Markdown flavor: GitHub Flavored Markdown
Description
Contributor
Committer
In most cases, this should be a different person than the contributor.