summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dallen@redhat.com>2013-04-21 00:10:29 -0600
committerDan Allen <dallen@redhat.com>2013-04-21 00:10:29 -0600
commite87b8adbd4e14e32bacf24bd0fbd73a798e0be94 (patch)
treeec4b50a91ef847d76efe5ccce824e5e4db2b8f8a
parent98133fbb6b4981a7b07ff71bdb7b943c1ff435b9 (diff)
resolves #262 warn if file in include macro doesn't exist
-rw-r--r--lib/asciidoctor/reader.rb9
-rw-r--r--test/reader_test.rb13
2 files changed, 20 insertions, 2 deletions
diff --git a/lib/asciidoctor/reader.rb b/lib/asciidoctor/reader.rb
index 7302bd02..31e353bf 100644
--- a/lib/asciidoctor/reader.rb
+++ b/lib/asciidoctor/reader.rb
@@ -441,6 +441,13 @@ class Reader
# FIXME currently we're not checking the upper bound of the include depth
elsif @document.attributes.fetch('include-depth', 0).to_i > 0
advance
+ # FIXME this borks line numbers
+ include_file = @document.normalize_asset_path(target, 'include file')
+ if !File.file?(include_file)
+ puts "asciidoctor: WARNING: line #{@lineno}: include file not found: #{include_file}"
+ return true
+ end
+
lines = nil
tags = nil
if !raw_attributes.empty?
@@ -466,8 +473,6 @@ class Reader
tags = attributes['tags'].split(/[,;]/).uniq
end
end
- # FIXME this borks line numbers
- include_file = @document.normalize_asset_path(target, 'include file')
if !lines.nil?
if !lines.empty?
selected = []
diff --git a/test/reader_test.rb b/test/reader_test.rb
index 0d7f1418..0372096f 100644
--- a/test/reader_test.rb
+++ b/test/reader_test.rb
@@ -173,6 +173,19 @@ include::fixtures/include-file.asciidoc[]
assert_match(/included content/, output)
end
+ test 'missing file referenced by include macro does not crash processor' do
+ input = <<-EOS
+include::fixtures/no-such-file.ad[]
+ EOS
+
+ begin
+ doc = document_from_string input, :safe => Asciidoctor::SafeMode::SAFE, :attributes => {'docdir' => File.dirname(__FILE__)}
+ assert_equal 0, doc.blocks.size
+ rescue => e
+ flunk('include macro should not raise exception on missing file')
+ end
+ end
+
test 'include macro supports line selection' do
input = <<-EOS
include::fixtures/include-file.asciidoc[lines=1;3..4;6..-1]