mojibake in autocompletion via `dotnet completions script pwsh`
- Dominant language
- C#
- Stars
- 3.2k
- Forks
- 1.3k
- PR merge metrics
- PR metrics pending
Description
### Describe the bug
The follwoing command creates an autocompletion with mojibake in the description (e.g. for german language)
```pwsh
dotnet completions script pwsh | Out-String | Invoke-Expression -ErrorAction SilentlyContinue
```
This procedure is described here:
https://learn.microsoft.com/en-us/dotnet/core/tools/enable-tab-autocomplete
### Steps to reproduce
1. **don't** enable [beta UTF-8 support in `intl.cpl`](https://learn.microsoft.com/en-us/windows/apps/design/globalizing/use-utf8-code-page)
2. Open PowerShell (Version 7.6.4)
3. set locale to german `$Env:DOTNET_CLI_UI_LANGUAGE = "de"`
4. run `dotnet completions script pwsh | Out-String | Invoke-Expression`
5. type `dotnet package search --s` and press `ctrl + space`
### Expected behavior
Accoding to the translations (https://github.com/dotnet/sdk/blob/v10.0.5/src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf#L2132 and https://github.com/dotnet/sdk/blob/v10.0.5/src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf#L3046) it should output:
`--skip`: `Anzahl der zu überspringenden Ergebnisse, um Paginierung zuzulassen. Standard 0.`
`--source`: `Die zu durchsuchende Paketquelle. Sie können mehrere „--source“-Optionen übergeben, um mehrere Paketquellen zu durchsuchen. Beispiel: "--source https://api.nuget.org/v3/index.json".`
### Actual behavior
You will see the description for `--skip`: `Anzahl der zu ├╝berspringenden Ergebnisse, um Paginierung zuzulassen. Standard 0.`
Or for `--source`: `Die zu durchsuchende Paketquelle. Sie k├Ânnen mehrere ÔÇ×--sourceÔÇ£-Optionen ├╝bergeben, um mehrere Paketquellen zu durchsuchen. Beispiel: "--source https://api.nuget.org/v3/index.json".`
### Is this a regression?
I don't know, but I don't think so.
### Are there any workarounds?
No working workaround.
### dotnet --info output
```console
.NET SDK:
Version: 10.0.400-preview.0.26322.102
Commit: 0cf89a94a1
Workload version: 10.0.400-manifests.11c77abd
MSBuild version: 18.9.0-preview-26322-102+0cf89a94a
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19045
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\10.0.400-preview.0.26322.102\
.NET workloads installed:
[maccatalyst]
Installation Source: VS 18.9.12023.133
Manifest Version: 26.5.10301/10.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\10.0.100\microsoft.net.sdk.maccatalyst\26.5.10301\WorkloadManifest.json
Install Type: Msi
[maui-windows]
Installation Source: VS 18.9.12023.133
Manifest Version: 10.0.20/10.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\10.0.100\microsoft.net.sdk.maui\10.0.20\WorkloadManifest.json
Install Type: Msi
[ios]
Installation Source: VS 18.9.12023.133
Manifest Version: 26.5.10301/10.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\10.0.100\microsoft.net.sdk.ios\26.5.10301\WorkloadManifest.json
Install Type: Msi
[android]
Installation Source: VS 18.9.12023.133
Manifest Version: 36.1.69/10.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\10.0.100\microsoft.net.sdk.android\36.1.69\WorkloadManifest.json
Install Type: Msi
Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.
Host:
Version: 10.0.9
Architecture: x64
Commit: 901ca94124
.NET SDKs installed:
10.0.400-preview.0.26322.102 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 10.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.28 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 10.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 8.0.28 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 10.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found:
arm64 [C:\Program Files\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\arm64\InstallLocation]
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Environment variables:
DOTNET_CLI_UI_LANGUAGE [en]
global.json file:
Not found
Learn more:
https://aka.ms/dotnet/info
Download .NET:
https://aka.ms/dotnet/download
```
### IDE version
_No response_
### Other details
As far as I can tell, combining it with `Out-String` breaks the encoding.
If I just type `dotnet completions script pwsh` into powershell, I the output is "normal".
However, if I type `dotnet completions script pwsh | Out-String`, I see mojibrake. (With the mentioned beta UTF-8 support it's fine, too.)
So if you enable UTF-8 support in `intl.cpl` or omit `Out-String |`, it should work in theory.
In practice, however, this doesn't work either, because the string contains characters (`„` in `mehrere „--source“`) that PowerShell interprets as the end of the string, resulting in the following error:
```
Invoke-Expression: Cannot bind argument to parameter 'Command' because it is an empty string.
Invoke-Expression: Missing closing '}' in statement block or type definition.
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the `dotnet completions script pwsh` entry point and the referenced `CliCommandStrings.de.xlf` entries; compare direct output with the reported `Out-String` pipeline using the German strings. Done means the generated PowerShell completion survives `Out-String | Invoke-Expression` without mojibake or the reported quoting errors, while preserving the expected translations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, powershell
- Domain
- cli, localization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100