Skip to content

Fix: Honor CompareOptions and Culture in RangeSortOptions#2345

Merged
swmal merged 1 commit intoEPPlusSoftware:develop8from
lievendf:fix/sort-case-sensitivity
May 7, 2026
Merged

Fix: Honor CompareOptions and Culture in RangeSortOptions#2345
swmal merged 1 commit intoEPPlusSoftware:develop8from
lievendf:fix/sort-case-sensitivity

Conversation

@lievendf
Copy link
Copy Markdown
Contributor

@lievendf lievendf commented May 6, 2026

Description

This PR fixes an issue where range sorting in EPPlus 8 failed to respect the CompareOptions set in RangeSortOptions. The internal comparison logic was hard-coded to use StringComparison.CurrentCulture, which prevented users from performing true case-sensitive (Ordinal/Binary) sorts or using specific linguistic rules.

Changes

  • Modified OfficeOpenXml.Sorting.Internal.EPPlusSortComparerBase to use the Culture and CompOptions properties during string comparisons instead of a hard-coded value.
  • Updated the comparison logic to fallback to CultureInfo.CurrentCulture only if no specific culture is provided.

Verification

Added a new test class EPPlusTest.Sorting.SortCaseSensitivityTests with the following test cases:

  • ShouldRespectCaseSensitivity: Verifies that linguistic case-sensitive sorting (a < A) works as expected.
  • ShouldRespectOrdinalCaseSensitivity: Verifies that binary/ordinal sorting (A < a) correctly positions uppercase letters first.

All tests passed for both .NET 8.0 and .NET 4.8.1 targets.

Fixed a bug where the internal string comparer in EPPlus sorting
hard-coded StringComparison.CurrentCulture, effectively ignoring
the CompareOptions (like Ordinal or IgnoreCase) provided by the user.

- Updated EPPlusSortComparerBase to use Culture and CompOptions properties.
- Added unit tests to verify linguistic and ordinal case-sensitivity.
@swmal swmal merged commit 5eb64da into EPPlusSoftware:develop8 May 7, 2026
3 checks passed
@swmal
Copy link
Copy Markdown
Contributor

swmal commented May 7, 2026

@lievendf - thank you for this PR. It will be included in the next version of EPPlus.

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.

3 participants