-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix image links with escaped brackets #1683
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/markedjs/markedjs/qpzfg7jxn |
src/rules.js
Outdated
inline._label = /(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/; | ||
inline._label = /(?:\[(?:\\.|[^\[\]])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@davisjam is this regex safe from ReDOS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly, it has moved from linear to exponential.
Visualization -- The problem is in the top group. The OR can be satisfied on the top or the bottom using \\a
, and if the subsequent ]
is missing then you get exponential backtracking.
Example misbehavior:
/\[(?:\\.|[^\[\]])*\]/.exec("[" + "\\a".repeat(300));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about removing \\
from the second path (/\[(?:\\.|[^\\\[\]])*\]/
)? that way the only path it can take is determined by whether it sees a \\
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@davisjam thanks for your help on this. Your regex experience is invaluable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introduces an exponential regex
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New regex is back to linear time.
Marked version: 1.1.0
Description
Fix image link with
\[
or\]
in alt textdemo
Contributor
Committer
In most cases, this should be a different person than the contributor.