Skip to content

Commit

Permalink
resolves #607 don't crash if table is empty and warn (PR #1538)
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux authored Feb 4, 2020
1 parent a0def6a commit 078ddef
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/master[
* if path of missing font is absolute, don't suggest that it was not found in the fontsdir
* allow use of style "regular" as alias for "normal" when defining font
* emit warning in verbose mode if glyph cannot be found in fallback font (#1529)
* don't crash if table is empty and warn (#607)
* only emit warning when non-WINANSI character is used with AFM font if verbose mode is enabled
* do not emit warning when non-WINANSI character is used with AFM font inside scratch document
* do not emit log messages from scratch document
Expand Down
5 changes: 4 additions & 1 deletion lib/asciidoctor/pdf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2039,7 +2039,10 @@ def convert_table node
end

# NOTE: Prawn aborts if table data is empty, so ensure there's at least one row
table_data = ::Array.new(node.columns.size) { { 'content' => '' } } if table_data.empty?
if table_data.empty?
logger.warn message_with_context 'no rows found in table', source_location: node.source_location
table_data << ::Array.new([node.columns.size, 1].max) { { content: '' } }
end

border_width = {}
table_border_color = theme.table_border_color || theme.table_grid_color || theme.base_border_color
Expand Down
4 changes: 4 additions & 0 deletions lib/asciidoctor/pdf/ext/asciidoctor/logging_shim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@ module Logging
def logger
StubLogger
end

def message_with_context text, _context = {}
text
end
end
end
9 changes: 6 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -613,11 +613,14 @@ def compute_image_differences reference, actual, difference = nil
result = false
if (messages = logger.messages).size == 1
if (message = messages[0])[:severity] == expected[:severity]
if Hash === (message_text = message[:message])
message_text = message_text[:text]
end
if Regexp === (expected_message = expected[:message])
result = true if expected_message.match? message[:message]
result = true if expected_message.match? message_text
elsif expected_message.start_with? '~'
result = true if message[:message].include? expected_message[1..-1]
elsif message[:message] === expected_message
result = true if message_text.include? expected_message[1..-1]
elsif message_text === expected_message
result = true
end
end
Expand Down
24 changes: 24 additions & 0 deletions spec/table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,30 @@
require_relative 'spec_helper'

describe 'Asciidoctor::PDF::Converter - Table' do
it 'should not crash if table has no rows' do
(expect do
pdf = to_pdf <<~'EOS', analyze: :line
|===
|===
EOS

(expect pdf.lines).to have_size 4
end).to not_raise_exception & (log_message severity: :WARN, message: 'no rows found in table')
end

it 'should not crash if cols and table cells are mismatched' do
(expect do
pdf = to_pdf <<~'EOS', analyze: :line
[cols="1,"]
|===
| cell
|===
EOS

(expect pdf.lines).to have_size 8
end).to not_raise_exception & (log_message severity: :WARN, message: 'no rows found in table')
end

context 'Decoration' do
it 'should apply frame all and grid all by default' do
pdf = to_pdf <<~'EOS', analyze: :line
Expand Down

0 comments on commit 078ddef

Please sign in to comment.