diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2024-05-16 15:24:48 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-16 13:24:48 -0600 |
| commit | ad827b14e2ce3057a5c9e03d1dab50470d0d0eb1 (patch) | |
| tree | c27bc8180e38f045836ae145ba70bd0e17627088 | |
| parent | 1b2f7c7c9f631ab2a7a4b7210987a571e7a09524 (diff) | |
resolves #4573 log error when incomplete row is detected at end of table (PR #4590)
| -rw-r--r-- | CHANGELOG.adoc | 1 | ||||
| -rw-r--r-- | lib/asciidoctor/parser.rb | 1 | ||||
| -rw-r--r-- | lib/asciidoctor/table.rb | 6 | ||||
| -rw-r--r-- | test/tables_test.rb | 17 |
4 files changed, 25 insertions, 0 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index d08f75ff..bb5dafd9 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -66,6 +66,7 @@ Improvements:: * Remove empty line at top of table cells in manpage output (#4482) (*@strager*) * Return `nil` if name passed to `Asciidoctor::SafeMode.value_for_name` is not recognized (#3526) * Modify default stylesheet to honor text-* roles on quote blocks + * Log error when an incomplete row is detected at the end of a table (#4573) Bug Fixes:: diff --git a/lib/asciidoctor/parser.rb b/lib/asciidoctor/parser.rb index 39439bee..f57a9cde 100644 --- a/lib/asciidoctor/parser.rb +++ b/lib/asciidoctor/parser.rb @@ -2417,6 +2417,7 @@ class Parser 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 diff --git a/lib/asciidoctor/table.rb b/lib/asciidoctor/table.rb index 76bfc7fa..f8979ea8 100644 --- a/lib/asciidoctor/table.rb +++ b/lib/asciidoctor/table.rb @@ -684,6 +684,12 @@ class Table::ParserContext 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 diff --git a/test/tables_test.rb b/test/tables_test.rb index ef878535..f55ad748 100644 --- a/test/tables_test.rb +++ b/test/tables_test.rb @@ -1262,6 +1262,23 @@ context 'Tables' do 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"] |
