Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The backport of POI Bug 60370 introduces a bug with PromptBox and ErrorBox text encoding #1386

Closed
1 of 5 tasks
yzhoholiev opened this issue Jul 12, 2024 · 1 comment · Fixed by #1387
Closed
1 of 5 tasks

Comments

@yzhoholiev
Copy link
Contributor

yzhoholiev commented Jul 12, 2024

NPOI Version

2.7.1

File Type

  • XLSX
  • XLS
  • DOCX
  • XLSM
  • OTHER

Reproduce Steps

Create a PromptBox or ErrorBox with special characters (new line, for example).

Issue Description

The issue was introduced as part of the backporting of the fix for POI Bug 60370 - XSSFDataValidation, promptBox, \n ignored (no multiline).

image
image

The bug was introduced as part of the translation of the Java implementation of the encodeUtf to C#:
Original code:
https://github.com/apache/poi/blob/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDataValidation.java#L151
C# code:
https://github.com/nissl-lab/npoi/blob/2.7.1-rc1/ooxml/XSSF/UserModel/XSSFDataValidation.cs#L163

The Java implementation of the Integer.toHexString method does not prepend the string with the leading zeros (the spec requires it to be 4 characters long), for that reason they are manually prepended with zeros to get the required length.

The proper implementation in C# will look like:

builder.Append("_x").Append($"{(byte) c:X4}").Append("_");

In case you want to use the HexDump helper it should be something like this:

builder.Append("_x").Append(HexDump.ToHex((short) c)).Append("_");
@yzhoholiev yzhoholiev added the bug label Jul 12, 2024
@tonyqus tonyqus added this to the NPOI 2.7.2 milestone Jul 12, 2024
@tonyqus
Copy link
Member

tonyqus commented Jul 12, 2024

bug introduced by #1354

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants