Skip to content

Group-Object - Use Case-Sensitive Hashtable for -CaseSensitive -AsHashtable - #11030

Merged
Ilya (iSazonov) merged 4 commits into
PowerShell:masterfrom
vexx32:GroupObjectCaseSensitiveHashtable
Nov 13, 2019
Merged

Ilya (iSazonov) merged 4 commits into
PowerShell:masterfrom
vexx32:GroupObjectCaseSensitiveHashtable

Conversation

@vexx32

@vexx32 Rain Sallow (/u/ta11ow) (vexx32) commented Nov 10, 2019 •

Copy link
Copy Markdown
Collaborator

PR Summary

Prior to this change, Group-Object -AsHashtable -CaseSensitive would give a key duplication error when given entries that only differ by casing. This was due to always using a case-insensitive hashtable, despite the request for -CaseSensitive behaviour.

This change allows Group-Object -CaseSensitive -AsHashtable to create and return a case-sensitive hashtable to enable this use case.

PR Context

Resolves #10441

PR Checklist

- Group-Object -AsHashtable -CaseSensitive returns a case-sensitive hash
instead of erroring out when given keys differing only by case.

- Added tests
@vexx32 Rain Sallow (/u/ta11ow) (vexx32) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Nov 10, 2019

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can simplify the code and this helps us to add Culture parameter later #9348:

var comparer = CaseSensitive.IsPresent ? StringComparer.CurrentCulture : StringComparer.CurrentCultureIgnoreCase;
hashtable = Hashtable(comparer);

@vexx32 Rain Sallow (/u/ta11ow) (vexx32) Nov 10, 2019 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do! I'm not sure if these methods use currentculture or ordinal though. I'll check :)

EDIT: It's CurrentCulture. 😄

Fixed in next commit. 🙂

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move style fixes in another PR. Below too.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VS code's autoformat strikes again. It is in a separate commit at least, but if you'd prefer to do a whole separate PR I can manage. 🙂

@iSazonov Ilya (iSazonov) added this to the 7.0.0-preview.6 milestone Nov 10, 2019
@iSazonov Ilya (iSazonov) self-assigned this Nov 10, 2019
- Consolidate hashtable creation

- Better consistency of handling switches in conditionals
@vexx32

Copy link
Copy Markdown
Collaborator Author

Ilya (@iSazonov) I think that should address all your concerns. I'll look at doing a style pass over the tests and possible the cmdlet after this PR is completed. 😊

@iSazonov

Copy link
Copy Markdown
Collaborator

Rain Sallow (/u/ta11ow) (@vexx32) I don't know should we document this in docs repo?

@vexx32

Rain Sallow (/u/ta11ow) (vexx32) commented Nov 11, 2019 •

Copy link
Copy Markdown
Collaborator Author

🤔 I suppose it should be documented since we're changing established behaviour. I'll open an issue. EDIT: Done!

@ghost ghost added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Nov 11, 2019
…ect.Tests.ps1

Co-Authored-By: Steve Lee <slee@microsoft.com>
@ghost ghost removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Nov 11, 2019
@iSazonov Ilya (iSazonov) added the AutoMerge informs the bot to automerge the PR label Nov 12, 2019
@ghost

Copy link
Copy Markdown

Hello Ilya (@iSazonov)!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@vexx32

Rain Sallow (/u/ta11ow) (vexx32) commented Nov 13, 2019 •

Copy link
Copy Markdown
Collaborator Author

Steve Lee (@SteveL-MSFT) 🤔 do you know if the bot ignores non-required checks? Pretty sure it's waiting on the CodeFactor issue (which is just "complex method" on EndProcessing() here).

I'm happy to refactor it out into helper methods if you feel that's necessary. 🙂

@iSazonov
Ilya (iSazonov) merged commit 57a4d4c into PowerShell:master Nov 13, 2019
@vexx32
Rain Sallow (/u/ta11ow) (vexx32) deleted the GroupObjectCaseSensitiveHashtable branch November 13, 2019 04:34
@ghost

Copy link
Copy Markdown

🎉v7.0.0-preview.6 has been released which incorporates this pull request.:tada:

Handy links:

Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
…htable (PowerShell#11030)

Prior to this change, Group-Object -AsHashtable -CaseSensitive would give a key duplication error when given entries that only differ by casing. This was due to always using a case-insensitive hashtable, despite the request for -CaseSensitive behaviour.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AutoMerge informs the bot to automerge the PR CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Return casesensitive hashtable with Group-Object

3 participants