Skip to content

Fix: Honor CompareOptions and Culture in RangeSortOptions#2345

Open
lievendf wants to merge 1 commit intoEPPlusSoftware:develop8from
lievendf:fix/sort-case-sensitivity
Open

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

Conversation

@lievendf
Copy link
Copy Markdown

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

2 participants