Skip to content

Commit

Permalink
Escape parenthesis in link URLs. Fix #459.
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelhoral committed Apr 3, 2024
1 parent 89ef473 commit ebefa8c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/commonmark-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ rules.inlineLink = {

replacement: function (content, node) {
var href = node.getAttribute('href')
if (href) href = href.replace(/([()])/g, '\\$1')
var title = cleanAttribute(node.getAttribute('title'))
if (title) title = ' "' + title + '"'
return '[' + content + '](' + href + title + ')'
Expand Down
5 changes: 5 additions & 0 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@
link")</pre>
</div>

<div class="case" data-name="a with parenthesis in a query">
<div class="input"><a href="http://example.com?(query)">An anchor</a></div>
<pre class="expected">[An anchor](http://example.com?\(query\))</pre>
</div>

<div class="case" data-name="a without a src">
<div class="input"><a id="about-anchor">Anchor without a title</a></div>
<pre class="expected">Anchor without a title</pre>
Expand Down

0 comments on commit ebefa8c

Please sign in to comment.