Skip to content

Commit

Permalink
resolves #4461 wrap target of link used in place of include directive…
Browse files Browse the repository at this point in the history
… in inline passthrough when it contains spaces (PR #4463)
  • Loading branch information
mojavelinux committed Jun 5, 2023
1 parent ca47ad7 commit 25f6b7c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ Improvements::
* Add single and double role hint to `<quote>` tag in DocBook output (#2947)
* Use safe navigation to avoid crashing when querying for extensions

Bug Fixes::

* Escape spaces in include target (using inline passthrough) when generating link from include directive (#4461)

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

Bug Fixes::
Expand Down
2 changes: 2 additions & 0 deletions lib/asciidoctor/reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,7 @@ def preprocess_include_directive target, attrlist
# if running in SafeMode::SECURE or greater, don't process this directive
# however, be friendly and at least make it a link to the source document
elsif doc.safe >= SafeMode::SECURE
expanded_target = %(pass:c[#{expanded_target}]) if expanded_target.include? ' '
# FIXME we don't want to use a link macro if we are in a verbatim context
replace_next_line %(link:#{expanded_target}[role=include#{attrlist ? ',' + attrlist : ''}])
elsif @maxdepth
Expand Down Expand Up @@ -1227,6 +1228,7 @@ def resolve_include_path target, attrlist, attributes
if (Helpers.uriish? target) || (::String === @dir ? nil : (target = %(#{@dir}/#{target})))
unless doc.attr? 'allow-uri-read'
logger.warn message_with_context %(cannot include contents of URI: #{target} (allow-uri-read attribute not enabled)), source_location: cursor
target = %(pass:c[#{target}]) if target.include? ' '
return replace_next_line %(link:#{target}[role=include#{attrlist ? ',' + attrlist : ''}])
end
if doc.attr? 'cache-uri'
Expand Down
17 changes: 17 additions & 0 deletions test/reader_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,13 @@ class ReaderTest < Minitest::Test
assert_equal 'link:include-file.adoc[role=include]', reader.read_line
end

test 'should escape spaces in target when generating link from include directive' do
input = 'include::foo bar baz.adoc[]'
doc = Asciidoctor::Document.new input
reader = doc.reader
assert_equal 'link:pass:c[foo bar baz.adoc][role=include]', reader.read_line
end

test 'should preserve attrlist when replacing include directive with link macro' do
input = 'include::include-file.adoc[leveloffset=+1]'
doc = Asciidoctor::Document.new input
Expand All @@ -694,6 +701,16 @@ class ReaderTest < Minitest::Test
end
end

test 'should escape spaces in target when generating link from remote include directive' do
using_memory_logger do |logger|
input = 'include::https://example.org/no such file.adoc[]'
doc = Asciidoctor::Document.new input, safe: :safe
reader = doc.reader
assert_equal 'link:pass:c[https://example.org/no such file.adoc][role=include]', reader.read_line
assert_message logger, :WARN, '<stdin>: line 1: cannot include contents of URI: https://example.org/no such file.adoc (allow-uri-read attribute not enabled)', Hash
end
end

test 'should preserve attrlist when replacing remove include directive with link macro' do
using_memory_logger do |logger|
input = 'include::https://example.org/dist/info.adoc[leveloffset=+1]'
Expand Down

0 comments on commit 25f6b7c

Please sign in to comment.