fix: decode _xHHHH_ escapes when reading inline string cells - #991
Open
nkuprins wants to merge 3 commits into
Open
fix: decode _xHHHH_ escapes when reading inline string cells#991nkuprins wants to merge 3 commits into
nkuprins wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes XLSX string decoding so OOXML _xHHHH_ escape sequences are consistently decoded for both shared-strings and inline/direct string cells (t="inlineStr" / t="str"), restoring correct read-after-write behavior (notably for values written with EscapeHexCellWriteHandler).
Changes:
- Introduces
XlsxEscapeUtils.utfDecode(...)and reuses it across both shared-string and inline/direct-string read paths. - Updates
CellTagHandlerto correctly handleDIRECT_STRINGcells by decoding escapes (instead of effectively treating them as error strings). - Adds a regression test covering inline-string decoding and the literal-escape round-trip behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| fesod-sheet/src/test/java/org/apache/fesod/sheet/analysis/v07/handlers/InlineStringUtfDecodeTest.java | Adds regression coverage for inline/direct string escape decoding and literal-escape round-trips. |
| fesod-sheet/src/main/java/org/apache/fesod/sheet/util/XlsxEscapeUtils.java | Centralizes OOXML _xHHHH_ decoding logic for reuse across read paths. |
| fesod-sheet/src/main/java/org/apache/fesod/sheet/analysis/v07/handlers/sax/SharedStringsTableHandler.java | Switches shared-strings decoding to the new shared utility. |
| fesod-sheet/src/main/java/org/apache/fesod/sheet/analysis/v07/handlers/CellTagHandler.java | Decodes escapes for DIRECT_STRING cells and normalizes the resulting type to STRING. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
6 tasks
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.
Related: #696
Purpose of the pull request
Characters that XML 1.0 forbids are stored in a cell as
_xHHHH_escapes. Fesod undid them only for cells backed bysharedStrings.xml, sot="inlineStr"andt="str"reached the caller with the raw escape. A value written by Fesod did not survive being read back by Fesod. The clearest case is a value escaped withEscapeHexCellWriteHandler, which stores the literal_xB9f0_as_x005F_xB9f0_precisely so a decoding reader restores it:Product_x005F_xB9f0_CodeProduct_xB9f0_CodeProduct_x005F_xB9f0_Code/Product_xB9f0_CodeWhy this is a defect and not intended behaviour:
CompatibilityTest#readXlsxWithEscapeSequencepins it forsharedStrings.xml.XSSFCelland the streamingXSSFSheetXMLHandler, each viaXSSFRichTextString#getString().What's changed?
XlsxEscapeUtils(new) -utfDecodemoved here fromSharedStringsTableHandlerunchanged, and both read paths now call it. The smaller change would have been to make the existing methodpublicand call it fromCellTagHandler, but that leaves a cell parser depending on thesharedStrings.xmlparser for decoding that has nothing to do with shared strings, and the next caller inherits the same detour. The escape convention belongs to neither handler, so it moved toutil/. Happy to switch to the two-line version if you prefer the smaller diff.CellTagHandler- theDIRECT_STRINGbranch now decodes instead of falling through to theERRORbranch; it sets the sameSTRINGtype as before.InlineStringUtfDecodeTest(new) - two round-trips, one plain_x0002_escape and one literal_x…_viaEscapeHexCellWriteHandler. Both verified to fail against the unfixed code.Checklist