diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 33bad74712..d88823136e 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -69,6 +69,7 @@ Improvements:: Bug Fixes:: + * Catalog inline ref defined using anchor macro even when resolved reftext is empty * Use while loop rather than recursion to locate next line to process; prevents stack limit error (#4368) * Avoid numeric character reference when looking for fragment in target of xref (#4393, #3642) * Use correct selector to collapse margin on first and last child of sidebar diff --git a/lib/asciidoctor/parser.rb b/lib/asciidoctor/parser.rb index 2f901818a4..e62a2324be 100644 --- a/lib/asciidoctor/parser.rb +++ b/lib/asciidoctor/parser.rb @@ -1166,7 +1166,7 @@ def self.catalog_inline_anchors text, block, document, reader reftext = reftext.gsub '\]', ']' reftext = document.sub_attributes reftext if reftext.include? ATTR_REF_HEAD elsif reftext.include? ATTR_REF_HEAD - next if (reftext = document.sub_attributes reftext).empty? + reftext = nil if (reftext = document.sub_attributes reftext).empty? end end end diff --git a/test/links_test.rb b/test/links_test.rb index 745813eb1b..4ef23cbcb4 100644 --- a/test/links_test.rb +++ b/test/links_test.rb @@ -396,6 +396,16 @@ assert_includes output, (input.sub '{empty}', '') end + test 'reftext of macro inline ref can resolve to empty' do + input = 'anchor:id-only[{empty}]text\n\nsee <>' + doc = document_from_string input + assert doc.catalog[:refs].key? 'id-only' + output = doc.convert standalone: false + assert_xpath '//a[@id="id-only"]', output, 1 + assert_xpath '//a[@href="#id-only"]', output, 1 + assert_xpath '//a[@href="#id-only"][text()="[id-only]"]', output, 1 + end + test 'inline ref with reftext' do %w([[tigers,Tigers]] anchor:tigers[Tigers]).each do |anchor| doc = document_from_string %(Here you can read about tigers.#{anchor})