Don't panic on quoted text around a number placeholder - #376
Merged
Merged
Conversation
`to_formatted_string` treated any section that starts and ends with a
quote as a quoted number and called `parse::<f64>().unwrap()` on it.
Formats such as `"Qty "0" pcs"` or `"Total: "#,##0.00" EUR"` start and
end with a quote but are text around a placeholder, so
`Cell::formatted_value()` panicked with `ParseFloatError` on any cell
that used one.
Take that branch only when the quoted text really is a number, and let
everything else go through the number formatter, which already renders
these as Excel does ("Qty 5 pcs", "Total: 1,234.50 EUR").
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019hXzkiuCwk5QQRsyU9wT9h
Owner
|
@keithadler |
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
Cell::formatted_value()panics on any numeric cell whose number format starts and ends with a quote but has a placeholder in between, such as"Qty "0" pcs"or"Total: "#,##0.00" EUR":to_formatted_stringtreats every format that starts and ends with"as a quoted number and callsformat.trim_matches('"').parse::<f64>().unwrap(). For these formats the trimmed text isQty "0" pcs, which is not a number. (Formats that are only quoted text, like" Excellent"in Apache POI'sConditionalFormattingSamples.xlsx, are already handled byliteral_only_sectionon master; they panicked in 3.1.0.)Change
Take that branch only when the quoted text really parses as a number. Everything else falls through to the number formatter, which already renders these the way Excel does:
Qty 5 pcs,Total: 1,234.50 EUR.Tests
test_to_formatted_string_quoted_text_around_a_placeholderinhelper/number_format.rs; it panics without the change.cargo +nightly fmt --all --check,cargo clippy -- -D warningsandcargo testpass.Found by differential testing with xlsx-lean and Apache POI's test files.
🤖 Generated with Claude Code
https://claude.ai/code/session_019hXzkiuCwk5QQRsyU9wT9h