Fix rich-text bold/italic/underline parsing per ECMA-376 - #448
Open
dev-aliawan wants to merge 1 commit into
Open
dev-aliawan wants to merge 1 commit into
dev-aliawan wants to merge 1 commit into
Conversation
The previous implementation of getBool in SharedString.textSpan used
bool.tryParse, which only accepts the literal strings 'true' and 'false'
per the Dart core library. Excel writes <b val="0"/> to mean explicitly
off (W3C XSD boolean lexical space allows 1/0 in addition to true/false;
see ECMA-376 §18.8.2), so bool.tryParse('0') returned null and the
?? true fallback misread every explicit-off run as bold on. Same for
italic.
Fix getBool to match the spec + openpyxl's shipping implementation:
- val absent → true (spec default)
- val in {false, f, 0, off} (case-insensitive) → false
- everything else → true
Also fix the sibling underline bug: <u val="none"/> was previously
misread as single underline because the switch only tested for 'double'.
Per ECMA-376 §18.4.13, ST_UnderlineValues includes 'none' as an explicit
off state — honor it.
dev-aliawan
added a commit
to dev-aliawan/excel_community
that referenced
this pull request
Apr 18, 2026
The previous implementation of getBool in SharedString.textSpan used
bool.tryParse, which only accepts the literal strings 'true' and 'false'
per the Dart core library. Excel writes <b val="0"/> to mean explicitly
off (W3C XSD boolean lexical space allows 1/0 in addition to true/false;
see ECMA-376 §18.8.2), so bool.tryParse('0') returned null and the
?? true fallback misread every explicit-off run as bold on. Same for
italic.
Fix getBool to match the spec + openpyxl's shipping implementation:
- val absent → true (spec default)
- val in {false, f, 0, off} (case-insensitive) → false
- everything else → true
Also fix the sibling underline bug: <u val="none"/> was previously
misread as single underline because the switch only tested for 'double'.
Per ECMA-376 §18.4.13, ST_UnderlineValues includes 'none' as an explicit
off state — honor it.
Inherited from justkawal/excel as of the community fork's creation; same
fix filed upstream as justkawal/excel#448.
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
SharedString.textSpaninlib/src/sharedStrings/shared_strings.dartmisparses three explicit-off OOXML boolean markers in rich-text runs:<b val="0"/>imported as bold=true<i val="0"/>imported as italic=true<u val="none"/>imported as Underline.SingleRoot cause
The
getBoolhelper used insidetextSpan:Per the Dart SDK,
bool.tryParseonly accepts the literal strings"true"/"false"(https://api.dart.dev/dart-core/bool/tryParse.html). Excel writes<b val="0"/>to mean explicitly-off — XSD boolean's lexical space allows"1"and"0"in addition to"true"/"false"— sobool.tryParse("0")returnsnull, the?? truedefault fires, and the run is misread as bold on.The underline switch-case has a sibling bug: any non-
"double"value is mapped toUnderline.Single, which forces explicit<u val="none"/>runs to import underlined.Spec reference
b (Bold)—valis W3C XSDboolean, defaulttruewhen omitted. See Microsoft Learn's ISO/IEC 29500-1 excerpt.u (Underline)—ST_UnderlineValuesincludesnoneas an explicit off state.{true, false, 1, 0}.Reference implementation
openpyxl handles this correctly in
descriptors/base.py:This PR mirrors that behavior.
Impact
Downstream users importing xlsx files authored with Excel's "bold default + un-bold specific runs" pattern currently see every un-bolded run rendered as bold. Verified against a real 23-question content file (50+
<b val="0"/>runs) — flags now match openpyxl ground truth exactly.Testing
Fix was verified end-to-end against real content. Happy to add unit tests matching the project's preferred style if you'd like — I didn't see existing coverage for the rich-text parsing path.