-
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
GFM strikethrough compatibility #1258
Conversation
I don't think this is catastrophically backtracking 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.
🥇
@@ -588,7 +588,7 @@ inline.gfm = merge({}, inline.normal, { | |||
.replace('email', inline._email) | |||
.getRegex(), | |||
_backpedal: /(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/, | |||
del: /^~~(?=\S)([\s\S]*?\S)~~/, | |||
del: /^~+(?=\S)([\s\S]*?\S)~+/, |
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.
- Could this be simplified (no look-ahead) to
/^~+([^\s~][\s\S]*?\S)~+/
? - Why not
~~ leading/trailing spaces ~~
? Seems like the spec permits this.
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.
- The spec might allow it but github doesn't
without space:
asdf
with space:
~ asdf ~
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.
Interesting. Would this work? /^~+([^~]+)~+/
.
(This regex will accept the "with space" version which I think is appropriate despite GitHub's treatment of it).
The spec says "No nesting" which I think means that the first ~
should terminate the strike-through.
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.
I think we should act like GitHub when the spec is ambiguous
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.
To answer my own question, /^~+([^\s~][\s\S]*?\S)~+/
won't work -- it requires a minimum of two characters between the ~
s.
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.
I'm a little concerned that this regex (old and new versions) will match ~~~
. How about
/^~+(?=[^\s~])([^~]*[^\s~])~+/
which will:
- Ensure that the "text" neither begins nor ends with whitespace or a
~
; and - Explicitly prevent nesting without needing to rely on the non-greedy
*?
behavior.
Thoughts?
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.
Is there any particular reason to avoid the non-greedy modifier?
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.
I'm nervous about the structure /~+...[\s\S]*?...~+/
. I do not believe that as written the regex is vulnerable, but a slight modification would make it so. If the middle group excludes a ~
character then the risk is removed.
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 If this is not vulnerable as written then I think we should merge it because it brings us into compliance. Adding @joshbruce to take a look.
Thanks Tom! 🎉 |
GFM strikethrough compatibility
Marked version: 0.3.19
Markdown flavor: GitHub Flavored Markdown
Description
This pull request brings GFM strikethrough compatibility.
Contributor
Committer
In most cases, this should be a different person than the contributor.