-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Fix data validation issues #975
Conversation
This patch included a XML entity mapping table instead of xml.EscapeText() to be fully compatible with Microsoft Excel.
Other thoughts about these issues:
len("<formula1></formula1>")
const choices = "Alpha,Beta,Gamma"
...
dv.SetDropList([]string{choices})
... |
This patch changed the string length calculation unit of data validation formulas from UTF-8 bytes to UTF-16 code units.
17 decimal significant digits should be more than enough to represent every IEEE-754 double-precision float number without losing precision, and numbers in this form will never reach the Excel limitation of 255 UTF-16 code units.
Thanks for your PR. I have fixed it by commit |
Note that the value of |
@xuri While your patch looks much cleaner, the XML encoder in the standard library is NOT compatible with Microsoft Excel. |
Codecov Report
@@ Coverage Diff @@
## master #975 +/- ##
==========================================
- Coverage 97.44% 97.44% -0.01%
==========================================
Files 31 31
Lines 11023 11021 -2
==========================================
- Hits 10741 10739 -2
Misses 157 157
Partials 125 125
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Yeah, thanks for your PR, I have added error messages and minimum range checking base on this branch. |
* Fix `SetDropList` to allow XML special characters * This closes qax-os#971, allow quotation marks in SetDropList() This patch included a XML entity mapping table instead of xml.EscapeText() to be fully compatible with Microsoft Excel. * This closes qax-os#972, allow more than 255 bytes of validation formulas This patch changed the string length calculation unit of data validation formulas from UTF-8 bytes to UTF-16 code units. * Add unit tests for SetDropList() * Fix: allow MaxFloat64 to be used in validation range 17 decimal significant digits should be more than enough to represent every IEEE-754 double-precision float number without losing precision, and numbers in this form will never reach the Excel limitation of 255 UTF-16 code units.
PR Details
Description
This patch escapes the drop-down list items, and changes the way to calculate the formula length.
Related Issue
Fixes #971 and #972.
Motivation and Context
Changes for #971
This patch included a XML entity mapping table, instead of simply reusing
xml.EscapeText()
in the standard library. This was on purpose. Disassembly of an OOXML file produced by Microsoft Excel indicated that, it implemented a different escaping rule which was more or less incompatible withxml.EscapeText()
. Consider the following example:Microsoft Excel escaped it into:
And my initial attempt to fix #971 in commit b1faede, which employed
xml.EscapeText()
, produced:The latter was unfortunately still incompatible with Microsoft Excel, not to mention it was longer:
Changes for #972
This patch calculated the string length in UTF-16 code units instead of UTF-8 bytes.
Tests indicated that Microsoft Excel's limitation of data validation formula always worked in this way, even on UTF-8 dominated platforms like macOS. The following snippet was developed to help identification of the upper bound:
The snippet would print ...
... and produce a corrupt file (or panic if the original length validation was not removed from excelize codebase).
Change the constant
55
to54
, and then the snippet would print ...... and produce a valid Excel workbook:
How Has This Been Tested
The patches was tested against:
Types of changes
Checklist