Fix detection of orphaned emStrong delimiters#2203
Conversation
|
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/markedjs/markedjs/7DUkk3e967QRWWFt8FxsXq3WLJNm |
UziTech
left a comment
There was a problem hiding this comment.
Can you add a test for *__foo__* __bar__ as well to make sure that is also fixed
davisjam
left a comment
There was a problem hiding this comment.
No REDOS issues added here.
|
@calculuschild does this make this while loop irrelevant since Line 587 in 784ba5f |
No. The The other matches need to keep looping through until we find a valid end delimiter run. |
|
Hmm. Hold up. I just realized this case will still be broken when a false orphan occurs later in the line:
Needs a bit more work. Edit: This is actually fine. False alarm; Typo in the test file. |
|
Ah, nevermind. Seems to work just fine. Updated the tests to include those cases though for future reference. |
|
This seems to break Edit: actually it looks like it is already broken but still after this pr |
I've got a fix for that too. |
|
@UziTech Using a lookahead so the orphan checker doesn't actually consume that last set of asterisks/underscores (similar to the way the rest of the regex works) which was preventing detection of the ending delimiter. Added tests for both the asterisk and underscore case. |
|
It looks like I'm ok with calling that unspecified behavior (since it is not good markdown) but we probably shouldn't have a test for it. |
|
Huh. That's really odd. Ok, I have removed that test. |
|
🎉 This PR is included in version 3.0.4 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Marked version:
3.0.3
Markdown flavor: CommonMark
Description
The check for orphaned delimiters (i.e., to skip over the
_in**em_strong**) looks for an isolated delimiter between two pairs of the opposite delimiter symbol (inside astrongof the other symbol). However, this was inadvertently including matches for at any point in the string, leading to the second_here being counted as an orphan between the middle two asterisk pairs:_**foo**_ **bar**This PR makes the orphan checker start from the beginning of the string to keep it from over-eagerly finding orphans.
Contributor
Committer
In most cases, this should be a different person than the contributor.