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

Escape parenthesis in link URLs. Fix #459. #460

Merged
merged 1 commit into from
Apr 8, 2024

Conversation

pavelhoral
Copy link
Collaborator

@pavelhoral pavelhoral commented Apr 3, 2024

This adds escaping parenthesis according to Common Mark spec - https://spec.commonmark.org/0.31.2/#link-destination.

Alternative solution would be to detect presence of parenthesis and enclosing the link in pointy brackets [text](<link>).

@pavelhoral
Copy link
Collaborator Author

pavelhoral commented Apr 3, 2024

I have specifically changed only the link destination escaping, however a quick glance on the link title specification reveals that this is also not correctly handled / escaped. So maybe this PR should cover that as well?

diff --git a/src/commonmark-rules.js b/src/commonmark-rules.js
index 8aa1617..f32a893 100644
--- a/src/commonmark-rules.js
+++ b/src/commonmark-rules.js
@@ -155,7 +155,7 @@ rules.inlineLink = {
     var href = node.getAttribute('href')
     if (href) href = href.replace(/([()])/g, '\\$1')
     var title = cleanAttribute(node.getAttribute('title'))
-    if (title) title = ' "' + title + '"'
+    if (title) title = ' "' + title.replace(/"/g, '\\"') + '"'
     return '[' + content + '](' + href + title + ')'
   }
 }

@pavelhoral
Copy link
Collaborator Author

I have added title escaping as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants