Skip to content

Commit

Permalink
don't allow target of include directive to start or end with a space
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux committed Apr 16, 2023
1 parent c9fce66 commit 7db62f1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Compliance::
Bug Fixes::

* Use correct selector to collapse margin on first and last child of sidebar
* Don't allow target of include directive to start with a space (to distinguish it from a dlist item) or to end with a space

== 2.0.18 (2022-10-15) - @mojavelinux

Expand Down
2 changes: 1 addition & 1 deletion lib/asciidoctor/rx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ module Rx; end
# include::chapter1.ad[]
# include::example.txt[lines=1;2;5..10]
#
IncludeDirectiveRx = /^(\\)?include::([^\[][^\[]*)\[(#{CC_ANY}+)?\]$/
IncludeDirectiveRx = /^(\\)?include::([^\s\[](?:[^\[]*[^\s\[])?)\[(#{CC_ANY}+)?\]$/

# Matches a trailing tag directive in an include file.
#
Expand Down
16 changes: 16 additions & 0 deletions test/lists_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2128,6 +2128,22 @@
assert_css 'dl > dt:empty', output, 1
end

test 'should parse a dlist if term is include and principal text is []' do
input = 'include:: []'
output = convert_string_to_embedded input
assert_css 'dl', output, 1
assert_css 'dl > dt', output, 1
assert_xpath '(//dl/dt)[1]/following-sibling::dd/p[text() = "[]"]', output, 1
end

test 'should parse a dlist if term is include and principal text matches macro form' do
input = 'include:: pass:[${placeholder}]'
output = convert_string_to_embedded input
assert_css 'dl', output, 1
assert_css 'dl > dt', output, 1
assert_xpath '(//dl/dt)[1]/following-sibling::dd/p[text() = "${placeholder}"]', output, 1
end

test "single-line adjacent elements" do
input = <<~'EOS'
term1:: def1
Expand Down
8 changes: 8 additions & 0 deletions test/reader_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,14 @@ class ReaderTest < Minitest::Test
end
end

test 'include directive should not match if target is empty or starts or ends with space' do
['include::[]', 'include:: []', 'include:: not-include[]', 'include::not-include []'].each do |input|
doc = Asciidoctor::Document.new input
reader = doc.reader
assert_equal input, reader.read_line
end
end

test 'include directive should not attempt to resolve target as remote if allow-uri-read is set and URL is not on first line' do
using_memory_logger do |logger|
input = <<~'EOS'
Expand Down

0 comments on commit 7db62f1

Please sign in to comment.