diff options
| author | 孙茂胤 (Sun, Maoyin) <simonmysun@gmail.com> | 2023-04-18 09:42:15 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-18 01:42:15 -0600 |
| commit | 768f0aabc1279e7fbcacc01efcab8c38915f7215 (patch) | |
| tree | 83900b29c32410cb508e510ea3bbad14dbdb33ca | |
| parent | aeebabc689eb5d526f643a9e99db68b39bbb150a (diff) | |
resolves #4393 avoid matching numeric character references when searching for # in xref target (PR #4394)
| -rw-r--r-- | CHANGELOG.adoc | 1 | ||||
| -rw-r--r-- | lib/asciidoctor/substitutors.rb | 2 | ||||
| -rw-r--r-- | test/links_test.rb | 19 |
3 files changed, 21 insertions, 1 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index a77f7867..2d73cdb5 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -62,6 +62,7 @@ Improvements:: * Set linenums option on source block when line numbering is enabled (#3313) * Warn if include target is remote and `allow-uri-read` attribute is not set (#2284) * Return empty string instead of nil if raw or verbatim block has no lines + * Avoid numeric character reference when looking for fragment in target of xref (#4393) * Don't split value of `-r` CLI option; treat as single path (#4425) Bug Fixes:: diff --git a/lib/asciidoctor/substitutors.rb b/lib/asciidoctor/substitutors.rb index 42fda33c..5dc4cc59 100644 --- a/lib/asciidoctor/substitutors.rb +++ b/lib/asciidoctor/substitutors.rb @@ -756,7 +756,7 @@ module Substitutors if doc.compat_mode fragment = refid - elsif (hash_idx = refid.index '#') + elsif (hash_idx = refid.index '#') && refid[hash_idx - 1] != '&' if hash_idx > 0 if (fragment_len = refid.length - 1 - hash_idx) > 0 path, fragment = (refid.slice 0, hash_idx), (refid.slice hash_idx + 1, fragment_len) diff --git a/test/links_test.rb b/test/links_test.rb index 426d0142..6bd7e0e5 100644 --- a/test/links_test.rb +++ b/test/links_test.rb @@ -1212,6 +1212,25 @@ context 'Links' do assert_xpath '//a[@href="#s1"][text()="Section Title"]', output, 1 end + test 'should not match numeric character references while searching for fragment in xref target' do + input = <<~'EOS' + see <<Cub => Tiger>> + + == Cub => Tiger + EOS + output = convert_string_to_embedded input + assert_xpath '//a[@href="#_cub_tiger"]', output, 1 + assert_xpath %(//a[@href="#_cub_tiger"][text()="Cub #{decode_char 8658} Tiger"]), output, 1 + end + + test 'should not match numeric character references in path of interdocument xref' do + input = <<~'EOS' + see xref:{cpp}[{cpp}]. + EOS + output = convert_string_to_embedded input + assert_includes output, '<a href="#C++">C++</a>' + end + test 'anchor creates reference' do doc = document_from_string '[[tigers]]Tigers roam here.' ref = doc.catalog[:refs]['tigers'] |
