Skip to content

https://github.com/jackdewinter/pymarkdown/issues/1706 - #1715

Merged
jackdewinter merged 5 commits into
mainfrom
issue-1706
Oct 25, 2026
Merged

jackdewinter merged 5 commits into
mainfrom
issue-1706

Conversation

@jackdewinter

@jackdewinter jackdewinter commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

Summary by Sourcery

Improve Markdown table parsing and make tokenization failures identify the file being processed.

New Features:

  • Add file names to unhandled tokenization error messages during scanning and fixing.
  • Add regression coverage for Issue 1706 and related Markdown parsing scenarios.

Bug Fixes:

  • Improve table rule handling for table rows and delimiter rows, including nested and ambiguous pipe-containing content.
  • Restore clear error reporting for tokenization failures by identifying the affected file.

Build:

  • Update development and documentation dependency pins, including setuptools, filelock, urllib3, and certifi.

Documentation:

  • Update the changelog for Issue 1706 and related parsing coverage.

Tests:

  • Expand exception-handling expectations and add Issue 1706 parsing and scan/fix regression tests.

Chores:

  • Refresh generated dependency, coverage, and test-result metadata.

@sourcery-ai

sourcery-ai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

This PR strengthens table parsing regression coverage and adjusts MD055 end-token handling while making unhandled tokenization errors actionable by including the file being scanned or fixed; associated tests, generated artifacts, and changelog entries are updated.

Sequence diagram for file-specific tokenization error reporting

sequenceDiagram
    participant Scanner
    participant TokenizedMarkdown
    participant FileScanHelper
    participant Caller

    Scanner->>TokenizedMarkdown: transform()
    TokenizedMarkdown-->>FileScanHelper: BadTokenizationError(UNHANDLED_EXCEPTION_TEXT)
    FileScanHelper->>FileScanHelper: __scan_file() or __fix_specific_file_with_error_handling()
    FileScanHelper-->>Caller: BadTokenizationError(file-specific message)
Loading

Flow diagram for MD055 table end-token handling

flowchart TD
    A[MD055 receives EndMarkdownToken] --> B{Table item token?}
    B -->|Yes| C[Store extracted whitespace]
    B -->|No| D{Table header or row token?}
    D -->|Yes| E[Determine trailing pipe]
    E --> F[Check table row]
    F --> G{Table header?}
    G -->|Yes| H[Check separator row]
    G -->|No| I[Finish token handling]
    D -->|No| I
Loading

File-Level Changes

Change Details Files
Add the originating filename to otherwise generic unhandled tokenization failures during scan and fix operations.
  • Centralize the generic tokenization error text as a shared constant.
  • Wrap matching errors at file-scan and file-fix boundaries with file-specific BadTokenizationError messages while preserving exception chaining.
  • Update scan/fix exception expectations and add direct regression coverage.
pymarkdown/general/tokenized_markdown.py
pymarkdown/file_scan_helper.py
test/api/test_api_scan.py
test/test_exception_handling.py
test/test_markdown_extra_issue_1706.py
Refine MD055 table-row end-token handling so table syntax is checked correctly without misclassifying table-like text in other Markdown constructs.
  • Move end-token processing into a dedicated helper.
  • Preserve trailing-pipe detection for over-full rows and item whitespace.
  • Validate delimiter-row leading and trailing pipe style from the table header metadata.
  • Add regression cases covering lists, paragraphs, block quotes, escaped/entity/code-span pipes, and table extension configurations.
pymarkdown/plugins/rule_md_055.py
test/test_markdown_extra_issue_1706.py
Update release documentation and generated test/coverage artifacts for issue 1706.
  • Record the additional parsing coverage and file-specific error reporting in the changelog.
  • Regenerate published coverage and test-result metadata.
  • Remove debug-display arguments from existing Markdown regression tests.
newdocs/src/changelog.md
publish/coverage.json
publish/test-results.json
test/test_markdown_extra.py
test/test_markdown_extra_issue_1482.py
test/test_markdown_extra_issue_1577.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="pymarkdown/file_scan_helper.py" line_range="291" />
<code_context>
+            ):
+                raise BadTokenizationError(
+                    f"An unhandled error occurred processing the '{next_file_name}' file."
+                ) from this_exception
             raise

</code_context>
<issue_to_address>
**Untrusted filenames forge error output**

When an attacker-controlled filename contains newline or terminal control characters and scanning or fixing that file hits an unhandled tokenization error, the filename is interpolated without escaping and reaches raw stderr output, so newlines or terminal control sequences forge log lines or alter terminal display when the error is printed.

Escape control characters in filenames before including them in displayed errors.

Also at `pymarkdown/file_scan_helper.py:372`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

):
raise BadTokenizationError(
f"An unhandled error occurred processing the '{next_file_name}' file."
) from this_exception

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Untrusted filenames forge error output

When an attacker-controlled filename contains newline or terminal control characters and scanning or fixing that file hits an unhandled tokenization error, the filename is interpolated without escaping and reaches raw stderr output, so newlines or terminal control sequences forge log lines or alter terminal display when the error is printed.

Escape control characters in filenames before including them in displayed errors.

Also at pymarkdown/file_scan_helper.py:372.

Prompt for AI agents
In `pymarkdown/file_scan_helper.py` at line 291:

**Untrusted filenames forge error output**

When an attacker-controlled filename contains newline or terminal control characters and scanning or fixing that file hits an unhandled tokenization error, the filename is interpolated without escaping and reaches raw stderr output, so newlines or terminal control sequences forge log lines or alter terminal display when the error is printed.

Escape control characters in filenames before including them in displayed errors.

Also at `pymarkdown/file_scan_helper.py:372`.

@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Coverage

Coverage Report
FileStmtsMissBranchBrPartCoverMissing
__init__.py1000100% 
__main__.py3000100% 
api.py3300600100% 
application_configuration_helper.py21040100% 
application_logging.py850160100% 
file_scan_helper.py53601800100% 
main.py1950340100% 
my_application_properties_facade.py23000100% 
return_code_helper.py65060100% 
version.py3000100% 
block_quotes
   __init__.py0000100% 
   block_quote_count_helper.py2980760100% 
   block_quote_data.py7000100% 
   block_quote_non_fenced_helper.py2410700100% 
   block_quote_processor.py2990600100% 
coalesce
   __init__.py0000100% 
   coalesce_processor.py640240100% 
container_blocks
   __init__.py0000100% 
   container_block_leaf_processor.py62001560100% 
   container_block_nested_processor.py2290560100% 
   container_block_non_leaf_processor.py34501060100% 
   container_block_processor.py1840500100% 
   container_grab_bag.py3650540100% 
   container_helper.py990240100% 
   container_indices.py8000100% 
   parse_block_pass_properties.py28020100% 
extension_manager
   __init__.py0000100% 
   extension_impl.py12000100% 
   extension_manager.py1750340100% 
   extension_manager_constants.py3000100% 
   parser_extension.py10000100% 
extensions
   __init__.py0000100% 
   disallowed_raw_html.py370120100% 
   extended_autolinks.py2600820100% 
   extension_one.py19040100% 
   extension_token_types.py9000100% 
   front_matter_extension.py910180100% 
   front_matter_markdown_token.py60000100% 
   markdown_strikethrough.py10000100% 
   markdown_tables.py10000100% 
   pragma_token.py1820520100% 
   task_list_items.py52040100% 
general
   __init__.py0000100% 
   bad_tokenization_error.py3000100% 
   constants.py38000100% 
   main_presentation.py24060100% 
   parser_helper.py4220980100% 
   parser_logger.py670220100% 
   parser_state.py1790380100% 
   position_marker.py7000100% 
   requeue_line_info.py8000100% 
   source_providers.py500120100% 
   tab_helper.py2820640100% 
   tokenized_markdown.py49501280100% 
html_helpers
   __init__.py0000100% 
   html_helper.py33801220100% 
   html_raw_helper.py1450620100% 
inline
   __init__.py0000100% 
   emphasis_helper.py2140780100% 
   inline_autolink_helper.py710200100% 
   inline_backslash_helper.py490100100% 
   inline_backtick_helper.py2220500100% 
   inline_character_reference_helper.py1190180100% 
   inline_handler_helper.py3340760100% 
   inline_helper.py1200280100% 
   inline_line_end_helper.py1500340100% 
   inline_processor.py2020540100% 
   inline_request.py23000100% 
   inline_response.py15000100% 
   inline_tabified_text_block_helper.py940140100% 
   inline_text_block_helper.py2390640100% 
leaf_blocks
   __init__.py0000100% 
   atx_leaf_block_processor.py1670380100% 
   fenced_leaf_block_processor.py3970820100% 
   indented_leaf_block_processor.py2430480100% 
   leaf_block_helper.py2130580100% 
   leaf_block_processor.py670140100% 
   leaf_block_processor_paragraph.py1900360100% 
   setext_leaf_block_processor.py1000140100% 
   table_block_continuation_helper.py2980640100% 
   table_block_parse_helper.py1670640100% 
   table_block_processor.py1780360100% 
   table_block_tuple.py30000100% 
   thematic_leaf_block_processor.py1310380100% 
links
   __init__.py0000100% 
   link_create_helper.py1220260100% 
   link_helper_properties.py27000100% 
   link_parse_helper.py3870920100% 
   link_reference_definition_continuation_helper.py2340540100% 
   link_reference_definition_helper.py1810360100% 
   link_reference_definition_parse_helper.py810240100% 
   link_reference_info.py10000100% 
   link_reference_titles.py6000100% 
   link_reference_tuple.py9000100% 
   link_search_helper.py2360600100% 
list_blocks
   __init__.py0000100% 
   list_block_can_close_helper.py720180100% 
   list_block_create_new_handler.py3100580100% 
   list_block_pre_list_helper.py1080200100% 
   list_block_processor.py3160580100% 
   list_block_starts_helper.py1550420100% 
plugin_manager
   __init__.py0000100% 
   bad_plugin_error.py390180100% 
   bad_plugin_fix_error.py3000100% 
   fix_line_record.py6000100% 
   fix_token_record.py10000100% 
   found_plugin.py18000100% 
   plugin_details.py36000100% 
   plugin_manager.py56302460100% 
   plugin_modify_context.py6000100% 
   plugin_scan_context.py1370380100% 
   plugin_scan_failure.py18040100% 
   replace_tokens_record.py9000100% 
   rule_plugin.py67040100% 
plugins
   __init__.py0000100% 
   plugin_one.py41060100% 
   rule_md_001.py410160100% 
   rule_md_002.py33080100% 
   rule_md_003.py770220100% 
   rule_md_004.py660260100% 
   rule_md_005.py32201000100% 
   rule_md_006.py530240100% 
   rule_md_007.py1050400100% 
   rule_md_009.py1010360100% 
   rule_md_010.py660180100% 
   rule_md_011.py39080100% 
   rule_md_012.py1290460100% 
   rule_md_013.py790200100% 
   rule_md_014.py25080100% 
   rule_md_018.py1160340100% 
   rule_md_019.py410180100% 
   rule_md_020.py420120100% 
   rule_md_021.py720280100% 
   rule_md_022.py800300100% 
   rule_md_023.py1550660100% 
   rule_md_024.py640180100% 
   rule_md_025.py440160100% 
   rule_md_026.py510180100% 
   rule_md_027.py58102280100% 
   rule_md_028.py400160100% 
   rule_md_029.py1070440100% 
   rule_md_030.py1060400100% 
   rule_md_031.py57801740100% 
   rule_md_032.py790300100% 
   rule_md_033.py700260100% 
   rule_md_034.py480220100% 
   rule_md_035.py570320100% 
   rule_md_036.py640160100% 
   rule_md_037.py1300460100% 
   rule_md_038.py290140100% 
   rule_md_039.py300160100% 
   rule_md_040.py15040100% 
   rule_md_041.py890340100% 
   rule_md_042.py16040100% 
   rule_md_043.py2010860100% 
   rule_md_044.py2230900100% 
   rule_md_045.py15040100% 
   rule_md_046.py960260100% 
   rule_md_047.py26080100% 
   rule_md_048.py420120100% 
   rule_md_049.py430140100% 
   rule_md_050.py430140100% 
   rule_md_051.py1830640100% 
   rule_md_053.py670260100% 
   rule_md_054.py510180100% 
   rule_md_055.py870260100% 
   rule_md_056.py350120100% 
   rule_md_058.py390140100% 
   rule_md_059.py360120100% 
   rule_md_060.py47101480100% 
   rule_pml_100.py1000400100% 
   rule_pml_101.py620180100% 
   rule_pml_102.py670180100% 
plugins/utils
   __init__.py0000100% 
   container_token_manager.py1050420100% 
   leading_space_index_tracker.py1240300100% 
   list_tracker.py1010180100% 
tokens
   __init__.py0000100% 
   atx_heading_markdown_token.py820100100% 
   blank_line_markdown_token.py38040100% 
   block_quote_markdown_token.py1240220100% 
   container_markdown_token.py9000100% 
   email_autolink_markdown_token.py46020100% 
   emphasis_markdown_token.py63080100% 
   end_of_stream_token.py27000100% 
   fenced_code_block_markdown_token.py1480280100% 
   hard_break_markdown_token.py41020100% 
   html_block_markdown_token.py60080100% 
   html_items.py92040100% 
   image_start_markdown_token.py54040100% 
   indented_code_block_markdown_token.py770100100% 
   inline_code_span_markdown_token.py850120100% 
   inline_markdown_token.py9000100% 
   leaf_markdown_token.py17020100% 
   link_reference_definition_markdown_token.py1210160100% 
   link_start_markdown_token.py990180100% 
   list_start_markdown_token.py1070200100% 
   list_start_markdown_token_helper.py46080100% 
   markdown_token.py3490300100% 
   new_list_item_markdown_token.py650100100% 
   ordered_list_start_markdown_token.py15000100% 
   paragraph_markdown_token.py930140100% 
   raw_html_markdown_token.py58060100% 
   reference_markdown_token.py94080100% 
   setext_heading_markdown_token.py1040120100% 
   special_text_markdown_token.py28020100% 
   stack_token.py213000100% 
   table_markdown_tokens.py3850280100% 
   text_markdown_token.py2980680100% 
   thematic_break_markdown_token.py62080100% 
   token_types.py42000100% 
   unordered_list_start_markdown_token.py15000100% 
   uri_autolink_markdown_token.py640100100% 
transform_gfm
   __init__.py0000100% 
   transform_state.py89000100% 
   transform_to_gfm.py870200100% 
   transform_to_gfm_list_looseness.py2090760100% 
   transform_to_gfm_token_handlers.py55080100% 
transform_markdown
   __init__.py0000100% 
   markdown_transform_context.py26000100% 
   transform_block_quote.py1110260100% 
   transform_containers.py75502460100% 
   transform_list_block.py2870440100% 
   transform_new_list_item.py1000160100% 
   transform_to_markdown.py1440360100% 
TOTAL25427064220100% 

Test Execution

Tests Skipped Failures Errors Time
10335 44 💤 0 ❌ 0 🔥 4m 23s ⏱️

@codecov

codecov Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (25eba0f) to head (7b6885c).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1715   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          208       208           
  Lines        25420     25427    +7     
  Branches      3209      3211    +2     
=========================================
+ Hits         25420     25427    +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jackdewinter
jackdewinter merged commit 5b53182 into main Oct 25, 2026
21 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant