Skip to content

Commit

Permalink
resolves asciidoctor#4468 treat bare URL enclosed in angle brackets a…
Browse files Browse the repository at this point in the history
…s unconstrained syntax
  • Loading branch information
mojavelinux committed Feb 19, 2024
1 parent 31af659 commit d373b48
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Bug Fixes::
* Move abstract inside info tag in DocBook output (#3602)
* Honor secondary and tertiary terms on `indexterm` macro when primary term is quoted and contains an equals sign (#3652)
* Remove extra border below doctitle when sidebar toc is collapsed into main content area (#4523)
* Treat bare URL enclosed in angle brackets as unconstrained syntax (#4468)

== 2.0.20 (2023-05-18) - @mojavelinux

Expand Down
24 changes: 17 additions & 7 deletions lib/asciidoctor/substitutors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -545,19 +545,29 @@ def sub_macros text
prefix = '' if prefix == 'link:'
link_text = nil if (link_text = $4).empty?
else
tail = $6
case prefix
# invalid macro syntax (link: prefix w/o trailing square brackets or enclosed in double quotes)
# FIXME we probably shouldn't even get here when the link: prefix is present; the regex is doing too much
case prefix
when 'link:', ?", ?'
next $&
when '<'
if tail == ';' ? (target.end_with? '>') : (gt_idx = target.index '>')
# drop surrounding <> from URL
prefix = ''
tail = nil
if gt_idx
suffix = target.slice (gt_idx + 4)
target = target.slice 0, gt_idx
else
target = target.slice 0, target.length - 4
end
next $& if target.end_with? '://'
end
end
case $6
case tail
when ';'
if prefix == '&lt;' && (target.end_with? '&gt;')
# move surrounding <> out of URL
prefix = ''
target = target.slice 0, target.length - 4
elsif (target = target.chop).end_with? ')'
if (target = target.chop).end_with? ')'
# move trailing ); out of URL
target = target.chop
suffix = ');'
Expand Down
4 changes: 4 additions & 0 deletions test/links_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@
assert_xpath '//a[@href="http://asciidoc.org"][text()="http://asciidoc.org"]', convert_string('<http://asciidoc.org> is the project page for AsciiDoc.'), 1
end

test 'qualified url surrounded by angled brackets in unconstrained context' do
assert_xpath '//a[@href="http://asciidoc.org"][text()="http://asciidoc.org"]', convert_string('URLは<http://asciidoc.org>。'), 1
end

test 'qualified url surrounded by round brackets' do
assert_xpath '//a[@href="http://asciidoc.org"][text()="http://asciidoc.org"]', convert_string('(http://asciidoc.org) is the project page for AsciiDoc.'), 1
end
Expand Down

0 comments on commit d373b48

Please sign in to comment.