summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2021-05-06 23:59:42 -0600
committerGitHub <noreply@github.com>2021-05-06 23:59:42 -0600
commitf2a4ab291e116aad00fb94f8ac49c6214e6ea3c9 (patch)
tree6af6db2eeeb28f47041dd5a054ca189ab7f6a8ec
parentbb2b489d965e10e279f7af8758d7e7e8e254d807 (diff)
resolve #4046 change ifeval directive to resolve to false if comparison operation cannot be performed (PR #4047)
-rw-r--r--CHANGELOG.adoc1
-rw-r--r--lib/asciidoctor/reader.rb8
-rw-r--r--test/reader_test.rb32
3 files changed, 37 insertions, 4 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index 47acdedd..a472b3e3 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -20,6 +20,7 @@ This project utilizes semantic versioning.
Bug Fixes::
* Include all lines outside of specified tagged region when tag filter on include directive is a single negated tag (#4048)
+ * Change ifeval directive to resolve to false if comparison operation cannot be performed (#4046)
* Update default stylesheet to indent blocks attached to list item in checklist (#2550)
* Update default stylesheet to reenable styling of implicit lead role on first paragraph of preamble inside AsciiDoc table cell
diff --git a/lib/asciidoctor/reader.rb b/lib/asciidoctor/reader.rb
index 103644f1..3a35ef19 100644
--- a/lib/asciidoctor/reader.rb
+++ b/lib/asciidoctor/reader.rb
@@ -961,11 +961,11 @@ class PreprocessorReader < Reader
if no_target
# the text in brackets must match a conditional expression
if text && EvalExpressionRx =~ text.strip
- lhs = $1
- op = $2
- rhs = $3
+ lhs = resolve_expr_val $1
# regex enforces a restricted set of math-related operations (==, !=, <=, >=, <, >)
- skip = ((resolve_expr_val lhs).send op, (resolve_expr_val rhs)) ? false : true
+ op = $2
+ rhs = resolve_expr_val $3
+ skip = (lhs.send op, rhs) ? false : true rescue true
else
logger.error message_with_context %(malformed preprocessor directive - #{text ? 'invalid expression' : 'missing expression'}: ifeval::[#{text}]), source_location: cursor
return true
diff --git a/test/reader_test.rb b/test/reader_test.rb
index 985a3361..cf566ea1 100644
--- a/test/reader_test.rb
+++ b/test/reader_test.rb
@@ -2267,6 +2267,38 @@ class ReaderTest < Minitest::Test
assert_equal '', (lines * ::Asciidoctor::LF)
end
+ test 'ifeval running unsupported operation on missing attribute drops content' do
+ input = <<~'EOS'
+ ifeval::[{leveloffset} >= 3]
+ I didn't make the cut!
+ endif::[]
+ EOS
+
+ doc = Asciidoctor::Document.new input
+ reader = doc.reader
+ lines = []
+ while reader.has_more_lines?
+ lines << reader.read_line
+ end
+ assert_equal '', (lines * ::Asciidoctor::LF)
+ end
+
+ test 'ifeval running invalid operation drops content' do
+ input = <<~'EOS'
+ ifeval::[{asciidoctor-version} > true]
+ I didn't make the cut!
+ endif::[]
+ EOS
+
+ doc = Asciidoctor::Document.new input
+ reader = doc.reader
+ lines = []
+ while reader.has_more_lines?
+ lines << reader.read_line
+ end
+ assert_equal '', (lines * ::Asciidoctor::LF)
+ end
+
test 'ifeval comparing double-quoted attribute to matching string includes content' do
input = <<~'EOS'
ifeval::["{gem}" == "asciidoctor"]