-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
area-aboutArea - About_ topicsArea - About_ topicsissue-doc-bugIssue - error in documentationIssue - error in documentation
Description
Prerequisites
- Existing Issue: Search the existing issues for this repository. If there is an issue that fits your needs do not file a new one. Subscribe, react, or comment on that issue instead.
- Descriptive Title: Write the title for this issue as a short synopsis. If possible, provide context. For example, "Typo in
Get-Foocmdlet" instead of "Typo." - Verify Version: If there is a mismatch between documentation and the behavior on your system, ensure that the version you are using is the same as the documentation. Check this box if they match or the issue you are reporting is not version specific.
Links
Summary
about_Case-Sensitivity lacks detail in a lot of areas.
The purpose of this issue is to document areas of PowerShell which are case-sensitive by default or handle case inconsistently/conditionally.
Details
Areas of PowerShell which are either case-sensitive by default or handle case inconsistently/conditionally:
- PS providers:
- EDIT: The
FileSystemandEnvironmentproviders are case-sensitive oncase-sensitive file systemsnon-Windows systems. Generally, operations involving paths or environment variables are case-sensitive on such systems. - However, wildcard matching by provider cmdlets is case-insensitive, irrespective of the system.
[void] (New-Item -Path Temp:foo.txt -Force) (Get-Item -Path Temp:FOO.txt).Name # Get-Item: Cannot find path 'Temp:/FOO.txt' because it does not exist. (Get-Item -Path Temp:F[O]*.txt).Name # foo.txt (Get-Item -Path Env:hOME).Name # Get-Item: Cannot find path 'Env:/hOME' because it does not exist. (Get-Item -Path Env:hOM[E]).Name # HOME
- EDIT: The
- Parameter set names:
DefaultParameterSetNamecase must be identical toParameterSetName.- Parameter set names are unexpectedly case-sensitive PowerShell/PowerShell#11183
- New Rule Suggestion: ParameterSetName mismatch. PowerShell/PSScriptAnalyzer#396
- .NET methods often exhibit case-sensitive behavior by default. E.g.,
- Equivalent .NET methods (without explicit opt-in) for common PowerShell operators.
- E.g.,
Array.Contains(),String.Contains(),String.Replace(),Regex.Match(),Regex.Replace(), etc.
- E.g.,
- Reflection (member names must use the correct case).
- Non-literal dictionary instantiation.
- E.g.,
[hashtable]::new()has case-sensitive keys, whereas a hash table literal@{}has case-insensitive keys. Likewise with[ordered] @{}vs[ordered]::new()([ordered]is only a type accelerator in PS v7+).
- E.g.,
- Explicitly calling
Enum.Parse()is case-sensitive by default, whereas PowerShell typically handles enums in a case-insensitive manner.
- Equivalent .NET methods (without explicit opt-in) for common PowerShell operators.
-Uniquecmdlets:Select-Object -UniqueandGet-Uniqueare case-sensitive by default (-CaseInsensitiveswitch added in PS v7.4).Sort-Object -Uniqueis case-insensitive by default (has always had-CaseSensitiveswitch).
Compare-Object:- Case-insensitive by default, but does have a
-CaseSensitiveswitch. - Input of type
[char]is unexpectedly case-sensitive by default; string input is case-insensitive by default. - Compare-Object with [char] instances is unexpectedly case-sensitive by default PowerShell/PowerShell#17758
Compare-object -ReferenceObject a -DifferenceObject A # Equal (no output) Compare-object -ReferenceObject ([char] 'a') -DifferenceObject ([char] 'A') # Different (output)
- Case-insensitive by default, but does have a
ConvertFrom-Json -AsHashtable:-AsHashtablewas added in PS v6. In PS v7.3, a change was made to treat JSON keys as case-sensitive when this parameter is specified.- With the parameter, an object of type
Management.Automation.OrderedHashtableis emitted, which has case-sensitive keys. - Without the parameter, JSON keys are treated as case-insensitive. Output is a custom object; last case-insensitive key wins.
- With the parameter, an object of type
- Case insensitive ConvertFrom-Json -AsHashtable PowerShell/PowerShell#19928
Group-Object:- Case-insensitive by default, but does have a
-CaseSensitiveswitch.- In Windows PowerShell v5.1,
-CaseSensitiveand-AsHashtableproduces a case-insensitive hash table. Duplicate keys result in an error. - In PowerShell v7+,
-CaseSensitiveand-AsHashtableproduces a case-sensitive hash table. No error occurs with duplicate keys. - Group-Object - Use Case-Sensitive Hashtable for -CaseSensitive -AsHashtable PowerShell/PowerShell#11030
[pscustomobject] @{ Foo = 'Bar' }, [pscustomobject] @{ Foo = 'bar' } | Group-Object -Property Foo -CaseSensitive -AsHashtable # Win PS: The objects grouped by this property cannot be expanded because there is a key duplication. # PS 7+: OK.
- In Windows PowerShell v5.1,
- Case-insensitive by default, but does have a
Select-String:- Case-insensitive by default, but does have a
-CaseSensitiveswitch.
- Case-insensitive by default, but does have a
Get-Commandand command discovery/invocation:- On case-sensitive file systems,
ExternalScriptandApplicationcommand type discovery/invocation is case-sensitive. Get-Commandwildcard matching with these types is also case-sensitive.- All other
CommandTypesare case-insensitive (functions, cmdlets, etc).
- On case-sensitive file systems,
- Comparison operators:
- By default, operators are case-insensitive.
-c*operators are case-sensitive.-i*operators are case-insensitive.-replace/-ireplaceis case-insensitive by default, except with named capture groups, which are case-sensitive.'Bar' -replace '(?<a>a)', '${a}${a}' # Baar 'Bar' -replace '(?<a>a)', '${A}${A}' # B${A}${A}r
-splitoperator:-splitand-isplitare case-insensitive.-csplitis case-sensitive, unless theIgnoreCaseoption is specified.'Bar' -csplit 'A', 0 # Bar 'Bar' -csplit 'A', 0, 'IgnoreCase' # B # r
- Tab completion:
- On case-sensitive file systems, tab completion and globbing are both case-insensitive.
- E.g.,
TabExpansion2 -inputScript ./foowill complete to./Foo.txton Linux. - Enable case-insensitive tab completion for files and folders on case-sensitive filesystem PowerShell/PowerShell#8128
usingstatement:- On case-sensitive file systems,
using moduleandusing assemblyare case-sensitive when a path is specified. using modulewith just a module name is case-insensitive.using namespaceis always case-insensitive.
- On case-sensitive file systems,
- Special characters:
- Escape sequences like
`nare case-sensitive.
- Escape sequences like
Areas of PowerShell which are guaranteed to be case-insensitive on all systems:
- Non-dictionary member-access
- Operator names
- Non-
ExternalScript/Applicationcommand discovery - Parameter names
- Variable names/
Get-Variable/Variable: - Keywords
using namespacestatements- Type literals
#Requires- Comment-based help
- PS provider names
- PS drive names
- Scope modifiers
Suggested Fix
- Be explicitly clear that on systems with a case-sensitive file system, the
FileSystemandEnvironmentPS providers are case-sensitive, except with wildcard matching/globbing. - Call out areas of PowerShell which are either case-sensitive by default on all systems or are inconsistent/conditional with case handling. See details above.
- Add additional examples in which case-insensitivity is guaranteed on all systems.
- Perhaps document exactly how case-sensitivity is handled in all of the main serialization/deserialization formats (CSV, JSON, XML, CLIXML) and potential workarounds with problematic input.
Metadata
Metadata
Assignees
Labels
area-aboutArea - About_ topicsArea - About_ topicsissue-doc-bugIssue - error in documentationIssue - error in documentation