Skip to content

Read @if numeric literals with the invariant culture - #1054

Merged
michelebastione merged 1 commit into
mini-software:masterfrom
menes97:fix/if-statement-invariant-culture
Nov 18, 2026
Merged

michelebastione merged 1 commit into
mini-software:masterfrom
menes97:fix/if-statement-invariant-culture

Conversation

@menes97

@menes97 menes97 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1053.

EvaluateStatement parsed the literal of an @if(...) condition with double.TryParse(value, out ...) and int.TryParse(value, out ...), which use the current culture. On de-DE or tr-TR, where . is the group separator, 3.5 became 35, so @if(score == 3.5) was false for score = 3.5. Numeric literals are now parsed with CultureInfo.InvariantCulture (NumberStyles.Float for doubles, NumberStyles.Integer for ints). Date literals are unchanged, since a template may write them in a local format.

Test: MiniExcelTemplateTests.IfStatementComparesNumbersIndependentlyOfCurrentCulture builds a one-row template with @if(score == 3.5) / high / @else / low / @endif, fills it under de-DE with score = 3.5, and expects high. On master it gets low; with this change it passes. The test uses == because a >/< operator currently reaches EvaluateStatement XML-encoded (&gt;=); 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 is TestParametrizedSheet, which fails on master on 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

  • Bug Fixes
    • Numeric values in template conditions are now evaluated consistently across regional settings. Decimal comparisons such as 3.5 work even when the system uses a comma as its decimal separator.

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>
@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Template condition parsing now reads double and integer literals with invariant culture. A test checks that a decimal comparison returns the expected result when the current culture is de-DE.

Changes: Template numeric comparison

Layer / File(s) Summary
Parse and verify numeric literals
src/MiniExcel.OpenXml/Templates/OpenXmlTemplate.Impl.cs, tests/MiniExcel.OpenXml.Tests/Templates/MiniExcelTemplateTests.cs
The double and integer comparison branches parse values with invariant culture. A test evaluates score == 3.5 under de-DE and checks that the resulting grade is high.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • mini-software/MiniExcel#1050: Changes template numeric detection to invariant-culture parsing; it addresses culture-dependent parsing in a different template value path.

Suggested reviewers: michelebastione, gdols

Merge Risk: Minimal · up to f0d84

Numeric literals in template @if conditions now mean the same thing in every culture, so 3.5 is no longer read as 35 under de-DE or tr-TR. No merge-blocking risk is identified. The CI failure is in reviewer-assignment automation and is unrelated to the code change.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: numeric literals in @if conditions are now read with the invariant culture. The raw summary confirms EvaluateStatement now parses doubles with NumberStyles.Float and i…
Linked Issues check Passed [#1053] Requires numeric literals in @if conditions to mean the same under any culture, so @if(score == 3.5) selects high for score = 3.5 under de-DE/tr-TR. The reviewed diff for src/MiniExcel.OpenXml…
Out of Scope Changes check Passed The implementation diff touches only the two numeric TryParse calls in EvaluateStatement, plus a one-line comment explaining the culture choice. Both changes implement the numeric-literal objective of…
Full details: Title check

Explanation

The title names the main change: numeric literals in @if conditions are now read with the invariant culture. The raw summary confirms EvaluateStatement now parses doubles with NumberStyles.Float and integers with NumberStyles.Integer under invariant culture, and the added test covers the de-DE case. The title is specific and matches the changeset and the linked issue's scope.

Full details: Linked Issues check

Explanation

[#1053] Requires numeric literals in @if conditions to mean the same under any culture, so @if(score == 3.5) selects high for score = 3.5 under de-DE/tr-TR. The reviewed diff for src/MiniExcel.OpenXml/Templates/OpenXmlTemplate.Impl.cs changes EvaluateStatement so the double branch uses double.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, ...) and the int branch uses int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, ...). This removes the culture-dependent parsing that turned 3.5 into 35. Date literals are untouched, as the issue allows. The regression test MiniExcelTemplateTests.IfStatementComparesNumbersIndependentlyOfCurrentCulture is described in the PR summary and description, and the author reports it passes with this change. The test file diff could not be read in this review, so the test is supported by the author's report only. The code change alone satisfies the behavioral requirement. The XML-encoded comparison operator problem is excluded by the issue and is not required here.

Full details: Out of Scope Changes check

Explanation

The implementation diff touches only the two numeric TryParse calls in EvaluateStatement, plus a one-line comment explaining the culture choice. Both changes implement the numeric-literal objective of [#1053]. The test added in MiniExcelTemplateTests.cs (per the PR summary) supports that objective. No changes to date-literal parsing, comparison operators, or unrelated template logic appear in the reviewed evidence. The PR description's note about the XML-encoded operator problem is informational and does not add code in this PR.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 770d0847-0024-497e-a9ad-cb7e41b67388
Commits

Reviewing files that changed from the base of the PR and between f390584 and f0d8496.

Files selected for processing: 2

  • src/MiniExcel.OpenXml/Templates/OpenXmlTemplate.Impl.cs
  • tests/MiniExcel.OpenXml.Tests/Templates/MiniExcelTemplateTests.cs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@michelebastione
michelebastione merged commit 3f7bb81 into mini-software:master Nov 18, 2026
8 of 10 checks passed
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.

[BUG] - @if conditions read numeric literals with the current culture (3.5 is 35 on de-DE/tr-TR)

2 participants