Skip to content

Commit

Permalink
backport fix for #4573 log error when incomplete row is detected at e…
Browse files Browse the repository at this point in the history
…nd of table
  • Loading branch information
mojavelinux committed May 16, 2024
1 parent 40e5a7e commit 76f99ee
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ Compliance::

* Encode spaces in mailto links as %20, in accordance with RFC 3986, instead of using + (#4576)

Improvements::

* Log error when an incomplete row is detected at the end of a table (#4573)

Bug Fixes::

* Don't leave behind empty line inside skipped preprocessor conditional (#4580)
Expand Down
1 change: 1 addition & 0 deletions lib/asciidoctor/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2414,6 +2414,7 @@ def self.parse_table(table_reader, parent, attributes)
end
end

parser_ctx.close_table
table.assign_column_widths unless (table.attributes['colcount'] ||= table.columns.size) == 0 || explicit_colspecs
table.has_header_option = true if implicit_header
table.partition_header_footer attributes
Expand Down
6 changes: 6 additions & 0 deletions lib/asciidoctor/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,12 @@ def close_cell(eol = false)
nil
end

def close_table
return if @column_visits == 0
logger.error message_with_context 'dropping cells from incomplete row detected end of table', source_location: @reader.cursor_before_mark
nil
end

private

# Internal: Close the row by adding it to the Table and resetting the row
Expand Down
17 changes: 17 additions & 0 deletions test/tables_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,23 @@
end
end

test 'should drop incomplete row at end of table and log an error' do
input = <<~'EOS'
[cols=2*]
|===
|a |b
|c |d
|e
|===
EOS
using_memory_logger do |logger|
output = convert_string_to_embedded input
assert_css 'table', output, 1
assert_css 'table tr', output, 2
assert_message logger, :ERROR, '<stdin>: line 5: dropping cells from incomplete row detected end of table', Hash
end
end

test 'should apply cell style for column to repeated content' do
input = <<~'EOS'
[cols=",^l"]
Expand Down

0 comments on commit 76f99ee

Please sign in to comment.