Skip to content

Cleanup using StringComparison.CurrentCulture #8064

Closed

Description

@iSazonov

We need review using StringComparison.CurrentCulture in all code base.

Best Practices for Using Strings in .NET

For stable behavior InvariantCulture looks right for date and time formats but Unicode standard Simple Case Folding is better for comparison and sorting.

Activity

  1. iSazonov commented on Feb 2, 2019

    @iSazonov
    CollaboratorAuthor

    Michael Klement (@mklement0) I invite you based on your #8180 (comment)

    Choosing a consistent default across cmdlets and operators (#8064) is a great idea, but I wonder if that's considered an acceptable breaking change; while that #8566 was indeed a breaking change, this was driven by unacceptable behavior having surfaced on Unix.

    It seems is a huge work but I believe that we could investigate till next LTS version when we could accept possible breaking changes.

  2. adamedx commented on Feb 3, 2019

    @adamedx

    Adding what may be a related issue encountered in 6.1.2 where sort-object behaves differently on the same input on Windows vs. Linux:

    PS> $PSVersionTable.Platform;('a', 'ab', 'aC' | Sort-Object ) -join ','
    Win32NT
    a,ab,aC
    PS> $PSVersionTable.Platform;('a', 'ab', 'aC' | Sort-Object ) -join ','
    Unix
    a,aC,ab

    In my case, tests caught this, but the impact is actually a real defect.

  3. iSazonov commented on Feb 4, 2019

    @iSazonov
    CollaboratorAuthor

    Adam Edwards (@adamedx) Can you confirm that you still see that in 6.2.0 Preview4? If so please open new issue.

  4. mklement0 commented on Feb 4, 2019

    @mklement0
    Contributor

    Adam Edwards (@adamedx): I think what you're seeing is a manifestation of CoreFx bug https://github.com/dotnet/corefx/issues/28611
    (even though the CoreFx team doesn't view it as a bug and has, regrettably, chosen to simply document the issue).

    That is, your locale is probably set to C or POSIX (possibly followed by .UTF-8).

    Run the following commands from bash (or a similar POSIX-like shell):

    $ LC_ALL=C pwsh -noprofile -c "('a', 'ab', 'aC' | Sort-Object ) -join ','"
    a,aC,ab  # !! BROKEN

    With a specific locale (culture), the problem does not occur:

    $ LC_ALL=en_US.UTF-8 pwsh -noprofile -c "('a', 'ab', 'aC' | Sort-Object ) -join ','"
    a,ab,aC # OK

    Note that using the standard sort utility does not exhibit the problem with the C / POSIX locale:

    $ LC_ALL=C printf '%s,' a ab aC | sort -f
    a,ab,aC,   # OK
  5. adamedx commented on Feb 4, 2019

    @adamedx

    Thank you Michael Klement (@mklement0) and Ilya (@iSazonov) , I've opened #8824 to track this explicitly then. I hope we can get the same behavior cross-platform consistency for sort and related functionality on PowerShell Core that Ruby, JavaScript, Python, et. al. exhibit. And certainly the default behavior on Linux (or at least Ubuntu 18.04) is different than PowerShell Desktop, which besides being the source of 99.999% of PowerShell scripts, has set the most usable standard here, where comparisons are case insensitive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Code Cleanupthe issue is for cleaning up the code with no impact on functionality

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions