summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2019-03-02 00:17:27 -0700
committerGitHub <noreply@github.com>2019-03-02 00:17:27 -0700
commitbd2a36ed52e86de481ce75ea0fb7b8d2266cf93f (patch)
tree5c3e3fc5c83a5e9b5b605af28f33a21be82a0e1f
parentfeaa28a5b170ec303ca9b31955acdd8cd2caef43 (diff)
resolves #3118 fix crash if stem block is empty (PR #3119)
-rw-r--r--CHANGELOG.adoc1
-rw-r--r--lib/asciidoctor/converter/docbook5.rb4
-rw-r--r--lib/asciidoctor/converter/html5.rb20
-rw-r--r--test/blocks_test.rb18
4 files changed, 31 insertions, 12 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index f4487f3a..e135961d 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -103,6 +103,7 @@ Bug Fixes::
* apply header subs to doctitle value when assigning it back to the doctitle document attribute (#3106)
* don't fail if value of pygments-style attribute is not recognized; gracefully fallback to default style (#2106)
* do not alter the $LOAD_PATH (#2764)
+ * fix crash if stem block is empty (#3118)
* remove conditional comment for IE in output of built-in HTML converter; fixes sidebar table of contents (#2983)
* fix styling of source blocks with linenums enabled when using prettify as syntax highlighter (#640)
* update default stylesheet to support prettify themes (#3020)
diff --git a/lib/asciidoctor/converter/docbook5.rb b/lib/asciidoctor/converter/docbook5.rb
index c07a423e..a87e1ca5 100644
--- a/lib/asciidoctor/converter/docbook5.rb
+++ b/lib/asciidoctor/converter/docbook5.rb
@@ -256,10 +256,10 @@ class Converter::DocBook5Converter < Converter::Base
def stem node
if (idx = node.subs.index :specialcharacters)
node.subs.delete_at idx
- equation = node.content
+ equation = node.content || ''
idx > 0 ? (node.subs.insert idx, :specialcharacters) : (node.subs.unshift :specialcharacters)
else
- equation = node.content
+ equation = node.content || ''
end
if node.style == 'asciimath'
# NOTE fop requires jeuclid to process mathml markup
diff --git a/lib/asciidoctor/converter/html5.rb b/lib/asciidoctor/converter/html5.rb
index f32c4567..e3d0467d 100644
--- a/lib/asciidoctor/converter/html5.rb
+++ b/lib/asciidoctor/converter/html5.rb
@@ -620,17 +620,17 @@ Your browser does not support the audio tag.
id_attribute = node.id ? %( id="#{node.id}") : ''
title_element = node.title? ? %(<div class="title">#{node.title}</div>\n) : ''
open, close = BLOCK_MATH_DELIMITERS[style = node.style.to_sym]
- equation = node.content
-
- if style == :asciimath && (equation.include? LF)
- br = %(<br#{@void_element_slash}>#{LF})
- equation = equation.gsub(StemBreakRx) { %(#{close}#{br * ($&.count LF)}#{open}) }
- end
-
- unless (equation.start_with? open) && (equation.end_with? close)
- equation = %(#{open}#{equation}#{close})
+ if (equation = node.content)
+ if style == :asciimath && (equation.include? LF)
+ br = %(<br#{@void_element_slash}>#{LF})
+ equation = equation.gsub(StemBreakRx) { %(#{close}#{br * ($&.count LF)}#{open}) }
+ end
+ unless (equation.start_with? open) && (equation.end_with? close)
+ equation = %(#{open}#{equation}#{close})
+ end
+ else
+ equation = ''
end
-
%(<div#{id_attribute} class="stemblock#{(role = node.role) ? " #{role}" : ''}">
#{title_element}<div class="content">
#{equation}
diff --git a/test/blocks_test.rb b/test/blocks_test.rb
index aab7341d..f1906a37 100644
--- a/test/blocks_test.rb
+++ b/test/blocks_test.rb
@@ -1561,6 +1561,17 @@ context 'Blocks' do
end
context 'Math blocks' do
+ test 'should not crash when converting to HTML if stem block is empty' do
+ input = <<~'EOS'
+ [stem]
+ ++++
+ ++++
+ EOS
+
+ output = convert_string_to_embedded input
+ assert_css '.stemblock', output, 1
+ end
+
test 'should add LaTeX math delimiters around latexmath block content' do
input = <<~'EOS'
[latexmath]
@@ -1725,12 +1736,19 @@ context 'Blocks' do
++++
x+b/(2a)<+-sqrt((b^2)/(4a^2)-c/a)
++++
+
+ [asciimath]
+ ++++
+ ++++
EOS
expect = <<~'EOS'.chop
<informalequation>
<mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mi>x</mml:mi><mml:mo>+</mml:mo><mml:mfrac><mml:mi>b</mml:mi><mml:mrow><mml:mn>2</mml:mn><mml:mi>a</mml:mi></mml:mrow></mml:mfrac><mml:mo>&lt;</mml:mo><mml:mo>&#xB1;</mml:mo><mml:msqrt><mml:mrow><mml:mfrac><mml:msup><mml:mi>b</mml:mi><mml:mn>2</mml:mn></mml:msup><mml:mrow><mml:mn>4</mml:mn><mml:msup><mml:mi>a</mml:mi><mml:mn>2</mml:mn></mml:msup></mml:mrow></mml:mfrac><mml:mo>&#x2212;</mml:mo><mml:mfrac><mml:mi>c</mml:mi><mml:mi>a</mml:mi></mml:mfrac></mml:mrow></mml:msqrt></mml:math>
</informalequation>
+ <informalequation>
+ <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML"></mml:math>
+ </informalequation>
EOS
using_memory_logger do |logger|