fix: consecutive partial numbers wrongly merged + ipynb string source loses title#2113
Open
Sahilalgo8 wants to merge 1 commit into
Conversation
Author
|
@microsoft-github-policy-service agree |
ericsondea-collab
left a comment
There was a problem hiding this comment.
ericson de almeirda teixeira
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two unreported bugs found by code audit — neither appears in any existing issue or PR.
Bug 1:
_merge_partial_numbering_lines()merges consecutive partial numbers togetherFile:
packages/markitdown/src/markitdown/converters/_pdf_converter.pyWhen a PDF has two partial numbers on consecutive lines (e.g.
.1immediately followed by.2), the function merges.1with.2, producing the nonsense token.1 .2and assigning all subsequent text to the wrong numbered items.Example — input:
.1 .2 Contractor shall furnish all materials. .3 Work shall comply with local codes.Buggy output:
.1 .2 Contractor shall furnish all materials. .3 Work shall comply with local codes.Root cause: Line 47 merges the current partial number with the next non-empty line, but never checks if that next line is itself a partial number.
Fix: One guard added — skip merging when the next non-empty line also matches
PARTIAL_NUMBERING_PATTERN.Bug 2:
IpynbConvertersilently loses document title when cellsourceis a stringFile:
packages/markitdown/src/markitdown/converters/_ipynb_converter.pyThe nbformat spec allows cell
sourceto be either a list of strings or a plain string. Whensourceis a string,for line in source_linesiterates character-by-character, soline.startswith('# ')never matches andresult.titleis alwaysNone— silently, with no error raised.Example:
`python
source as list → title = 'My Report' ✓
'source': ['# My Report\n', '\n', 'Content']
source as string → title = None ✗ (same content, different format)
'source': '# My Report\n\nContent'
`
Fix: Normalise string source to a list via
splitlines(keepends=True)before processing.Tests
9 new tests in
tests/test_bug_fixes.pycovering both fixes and edge cases (consecutive numbers, mixed patterns, string vs list source parity, no-heading case).