Skip to content

Preserve carriage returns in XLSX string values - #252

Open
levvs-one wants to merge 1 commit into
MarkPflug:mainfrom
levvs-one:fix/xlsx-carriage-returns
Open

Preserve carriage returns in XLSX string values#252
levvs-one wants to merge 1 commit into
MarkPflug:mainfrom
levvs-one:fix/xlsx-carriage-returns

Conversation

@levvs-one

Copy link
Copy Markdown

Summary

The XLSX string encoder does not currently escape CR (U+000D). The XML writer's newline handling then changes CR and CRLF to LF, so writing and reading a string such as "a\rb" does not preserve the original value.

This change adds CR to the existing OpenXmlCodec escape regex, producing _x000d_ before XML serialization. It keeps the current codec, literal-escape protection and public APIs unchanged.

Tests

  • Added encode/decode and real XLSX writer/reader regressions for CR, CRLF, LF, a leading CR, and literal/nested escape sequences.
  • With the new tests but before the fix: 22 passed, 6 failed.
  • With the fix: the same filter passes all 28 tests.
  • Full test project on Windows x64, net8.0 using SDK 10.0.400: 363 passed, 0 failed, 3 existing skipped tests (366 total). SylvanExcelTestData was unset, so the optional external corpus was not exercised.
  • A separate .NET 10 consumer verified exact string roundtrips and inspected the generated XLSX with Open XML SDK and BCL ZIP/XML APIs. Desktop Excel and Linux/AOT were not tested.

The patch only changes CR escaping in the existing XLSX path; it does not change reader whitespace policy or add a different string codec.

Co-authored-by: OpenAI Codex <noreply@openai.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant