Problems with encoding UTF-8 in Powershell

Open
#170 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
powershell
Domain
tooling

Research direction

Start with PowershellSyntax.sublime-settings and reproduce the UTF-8 and UTF-8 with BOM behavior on Windows with the UTF-8 beta feature disabled. Check the related build-panel behavior and the effect of running chcp.exe; done means an agreed encoding behavior is validated for the affected PowerShell and build workflows, including the compatibility concern for Linux and PowerShell Core users.

Written by the indexing model from the issue text.

Description

build system

Per default Windows 10 and Windows 11 do not use UTF-8 unless you manually enable as a Beta feature under Region Settings in intl.cpl

Capture3

Without that setting enabled both Sublime and Powershell are having problems reading and displaying special characters such as "åäö".

Here is an example below on a machine without UTF-8 enabled running files from the Powershell console.

File encoding: UTF-8
Capture

File encoding: UTF-8 with BOM
Capture2

As you can see Powershell is unable read the string when the file encoding is "UTF-8" and everything works fine when the encoding is set to "UTF-8 with BOM".

Here is another example with the Build Panel is Sublime Text
File encoding: UTF-8
Capture4

File encoding: UTF-8 with BOM
Capture5

As you can see the output is still wrong in the Build Panel even when the encoding is set to "UTF-8 with BOM". But it can be fixed by running chcp.exe in cmd

image

And then changing the encoding settings in the build job.

image

As stated before this is only an issue when the UTF-8 Beta feature in Windows is disabled. If you enable UTF-8 support the Sublime Text build panel and powershell console works without any issues.

I am not sure how to handle the build panel problem but at least changing the default encoding format for Powershell files to "UTF-8 with BOM" would prevent scripts processing special characters from causing unwanted bugs. This could probably be done by updating PowershellSyntax.sublime-settings with "default_encoding": "UTF-8 with BOM". But I am not sure how that would affect Linux or Powershell Core users.

Dominant language
PowerShell
Stars
335
Forks
80
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from SublimeText/PowerShell

All issues in SublimeText/PowerShell

Similar issues

More DevTools issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.