Repository navigation
Conversation
…text
split_compact_header_row and split_merged_key_value_text rebuilt byte
offsets as the sum of `word.len() + 1` over `split_whitespace()` words.
That assumes exactly one 1-byte space between words. A run of spaces, a
tab or a U+00A0 makes the offset fall short, so `split_at` can land
inside a multi-byte char and panic ("end byte index ... is not a char
boundary"), which reaches Python as a PanicException.
Take each word's byte offset from the slice itself and split at the
start of the word. Both halves are trimmed afterwards, so output for
single-space text is unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Problem
edgeparse.convert(path, format="markdown")(0.3.2, alsomainat 8d706e0) panics on a born-digital (text-layer) PDF we cannot share:In
crates/edgeparse-core/src/pipeline/stages/cluster_table_detector.rs,split_compact_header_rowandsplit_merged_key_value_textrebuild byte offsets as the sum ofword.len() + 1oversplit_whitespace()words:That assumes exactly one 1-byte space between words. A run of spaces, a tab or a U+00A0 makes
cursorfall short of the real offset, sosplit_atcan land inside a multi-byte char such as’and panic.Change
word_byte_offsetsyields(byte_offset, word), with the offset taken from thesplit_whitespaceslice itself, so it is always a char boundary.’forsplit_compact_header_row, double space forsplit_merged_key_value_text. Onmainall three panic withend byte index 10 is not a char boundary; it is inside '’' (bytes 8..11 of string); with this change they pass.Testing
cargo test(workspace): all pass,edgeparse-corelib 554 passed, 0 failed.cargo fmt --all --checkandcargo clippy -- -A clippy::all -D clippy::correctness -D clippy::suspicious(the CI flags): clean.benchmark/pdfs: converted to Markdown with release builds ofmainand of this branch. 198 outputs are byte-identical. The other two (01030000000071,01030000000191) vary between runs onmainas well; over 6 runs each, both builds produce the same two alternative outputs. So that is existing nondeterminism, not a change from this PR. I did not run./scripts/bench.sh, since the outputs are identical.Separately, a panic anywhere in the pipeline reaches Python as
PanicException. Wrapping theedgeparse_core::convert(...)call incrates/edgeparse-python/src/lib.rswithstd::panic::catch_unwindand mapping it toPyRuntimeErrorwould let callers handle a bad document like any other error. I left that out to keep this PR small. I'm happy to add it here or in a follow-up.🤖 Generated with Claude Code