Skip to content

Commit

Permalink
resolves #4570 fix crash when parsing xref shorthand when target star…
Browse files Browse the repository at this point in the history
…ts with URL protocol (PR #4585)
  • Loading branch information
mojavelinux committed May 12, 2024
1 parent 45e8c54 commit 8ab3888
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Bug Fixes::

* Don't leave behind empty line inside skipped preprocessor conditional (#4580)
* Don't duplicate block attribute line above detached block that breaks a dlist; fixes duplicate role on detached block (#4565)
* Don't crash when parsing xref shorthand if target starts with URL protocol and text is offset by space (#4570)

== 2.0.22 (2024-03-08) - @mojavelinux

Expand Down
4 changes: 2 additions & 2 deletions lib/asciidoctor/rx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,9 @@ module Rx; end
#
if RUBY_ENGINE == 'opal'
# NOTE In JavaScript, a back reference succeeds if not set; invert the logic to give it a match to refute
InlineLinkRx = %r((^|link:|#{CG_BLANK}|\\?&lt;(?=\\?(?:https?|file|ftp|irc)(:))|[>\(\)\[\];"'])(\\?(?:https?|file|ftp|irc)://)(?:([^\s\[\]]+)\[(|#{CC_ALL}*?[^\\])\]|(?!\2)([^\s]*?)&gt;|([^\s\[\]<]*([^\s,.?!\[\]<\)]))))
InlineLinkRx = %r((^|link:|#{CG_BLANK}|\\?&lt;(?=\\?(?:https?|file|ftp|irc)(:))|[>\(\)\[\];"'])(\\?(?:https?|file|ftp|irc)://)(?:([^\s\[\]]+)\[(|#{CC_ALL}*?[^\\])\]|(?!\2)([^\s]+?)&gt;|([^\s\[\]<]*([^\s,.?!\[\]<\)]))))
else
InlineLinkRx = %r((^|link:|#{CG_BLANK}|\\?&lt;()|[>\(\)\[\];"'])(\\?(?:https?|file|ftp|irc)://)(?:([^\s\[\]]+)\[(|#{CC_ALL}*?[^\\])\]|\2([^\s]*?)&gt;|([^\s\[\]<]*([^\s,.?!\[\]<\)]))))m
InlineLinkRx = %r((^|link:|#{CG_BLANK}|\\?&lt;()|[>\(\)\[\];"'])(\\?(?:https?|file|ftp|irc)://)(?:([^\s\[\]]+)\[(|#{CC_ALL}*?[^\\])\]|\2([^\s]+?)&gt;|([^\s\[\]<]*([^\s,.?!\[\]<\)]))))m
end

# Match a link or e-mail inline macro.
Expand Down
5 changes: 2 additions & 3 deletions lib/asciidoctor/substitutors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -538,9 +538,8 @@ def sub_macros text
# honor the escapes
next $&.slice 1, $&.length if $1.start_with? RS
next %(#{$1}#{$&.slice $1.length + 1, $&.length}) if $3.start_with? RS
target = $3 + $6
next $& if target == $3
doc.register :links, target
next $& unless $6
doc.register :links, (target = $3 + $6)
link_text = (doc_attrs.key? 'hide-uri-scheme') ? (target.sub UriSniffRx, '') : target
(Inline.new self, :anchor, link_text, type: :link, target: target, attributes: { 'role' => 'bare' }).convert
else
Expand Down
5 changes: 5 additions & 0 deletions test/links_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@
assert_xpath '//p[text()="<http://asciidoc.org>"]', convert_string('<\\http://asciidoc.org>'), 1
end

test 'xref shorthand with target that starts with URL protocol and has space after comma should not crash parser' do
output = convert_string_to_embedded '<<https://example.com, Example>>'
assert_include '<a href="#https://example.com">Example</a>', output
end

test 'autolink containing text enclosed in angle brackets' do
output = convert_string_to_embedded 'https://github.com/<org>/'
assert_include '<a href="https://github.com/&lt;org&gt;/" class="bare">https://github.com/&lt;org&gt;/</a>', output
Expand Down

0 comments on commit 8ab3888

Please sign in to comment.