Repository navigation
Read @if numeric literals with the invariant culture - #1054
michelebastione merged 1 commit into
Conversation
EvaluateStatement parsed the right-hand literal of an @if condition with double.TryParse/int.TryParse in the current culture, so on de-DE or tr-TR "3.5" was 35 and @if(score == 3.5) took the wrong branch. Parse numbers with CultureInfo.InvariantCulture. Fixes mini-software#1053. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Fixes #1053.
EvaluateStatementparsed the literal of an@if(...)condition withdouble.TryParse(value, out ...)andint.TryParse(value, out ...), which use the current culture. On de-DE or tr-TR, where.is the group separator,3.5became35, so@if(score == 3.5)was false forscore = 3.5. Numeric literals are now parsed withCultureInfo.InvariantCulture(NumberStyles.Floatfor doubles,NumberStyles.Integerfor ints). Date literals are unchanged, since a template may write them in a local format.Test:
MiniExcelTemplateTests.IfStatementComparesNumbersIndependentlyOfCurrentCulturebuilds a one-row template with@if(score == 3.5)/high/@else/low/@endif, fills it under de-DE withscore = 3.5, and expectshigh. Onmasterit getslow; with this change it passes. The test uses==because a>/<operator currently reachesEvaluateStatementXML-encoded (>=); I mentioned that in the issue as a separate problem.What I ran (Windows, tr-TR, .NET 10):
dotnet test tests/MiniExcel.OpenXml.Tests -f net10.0: 547 passed, 1 failed. The failure isTestParametrizedSheet, which fails onmasteron this machine for the template culture bug fixed in #1050; it's unrelated to this change. I didn't run net8.0, net9.0 or net11.0 locally.Written with Claude Code (AI, for a bug fix and its test as CONTRIBUTING allows); I reviewed the change and ran the tests above.
🤖 Generated with Claude Code
Summary by CodeRabbit
3.5work even when the system uses a comma as its decimal separator.