Skip to content
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

Link redos #1426

Merged
merged 2 commits into from Feb 21, 2019
Merged

Link redos #1426

merged 2 commits into from Feb 21, 2019

Conversation

@UziTech
Copy link
Member

@UziTech UziTech commented Feb 20, 2019

Marked version: master

Description

Fixes redos when code blocks are in square brackets that are not links.

Contributor

  • Test(s) exist to ensure functionality and minimize regression (if no tests added, list tests covering this PR)

Committer

In most cases, this should be a different person than the contributor.

  • Draft GitHub release notes have been updated.
  • CI is green (no forced merge required).
  • Merge PR
@UziTech
Copy link
Member Author

@UziTech UziTech commented Feb 20, 2019

/cc @Feder1co5oave @davisjam

I'm not sure this is a great fix. The test still takes a few hundred milliseconds.

@UziTech UziTech requested review from davisjam, joshbruce and styfle Feb 20, 2019
@UziTech UziTech marked this pull request as ready for review Feb 20, 2019
@Feder1co5oave
Copy link
Contributor

@Feder1co5oave Feder1co5oave commented Feb 20, 2019

I tried a different approach but this seems better! It's far from perfect though. I think this issue is inherent in the way links and code spans bind.

So, for example:

[foo`](url)` <-- this is not a link

[`foo]`](url) <-- neither is this

[foo`](url) <-- but this is

[foo`](url)`` code `` <-- and this too.

[foo`](url)``code` <-- these are just two code spans sitting back-to-back

Whenever we try to match a link, if we find a ` inside the text part, we cannot know if it is a lonely backtick, the start of a codespan contained within the link text, or the start of a codespan which invalidates the link-like part we matched up at that point.
Also, code spans by themselves are hard to parse!:

code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,

I think we should consider trying to resemble the codespan matching regex to avoid backtracking too much. Something along the lines of (`+) ... \2...

If you want to merge this fix in the mean time, that's fine too!

styfle
styfle approved these changes Feb 21, 2019
Copy link
Member

@styfle styfle left a comment

Looks good, besides adding butt to the repo 😆

@joshbruce joshbruce merged commit 1f5b9a1 into markedjs:master Feb 21, 2019
1 check passed
@UziTech UziTech deleted the link-code branch Mar 12, 2019
@styfle styfle mentioned this pull request Mar 25, 2019
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants