Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(config): Allow scoop config use Unicode characters #4631

Merged
merged 2 commits into from
Jan 7, 2022
Merged

Conversation

niheaven
Copy link
Member

@niheaven niheaven commented Jan 7, 2022

Description

Save config file with Default encoding.

Motivation and Context

Relates to #4629

If users use Unicode characters in scoop config command, these characters will not be saved to config file

How Has This Been Tested?

Before:
image

After:
image

Checklist:

  • I have read the Contributing Guide.
  • I have updated the documentation accordingly.
  • I have updated the tests accordingly.

@niheaven niheaven merged commit 4f5ecd0 into develop Jan 7, 2022
@niheaven niheaven deleted the fix-config branch January 7, 2022 16:23
chawyehsu added a commit to chawyehsu/scoop that referenced this pull request Jan 11, 2022
This patch forces Scoop's config.json and aria2's input-file
are saved and used with the UTF8 encoding to support non-ASCII
characters like CJK. A previous patch ScoopInstaller#4631 was applied to fix
the encoding of Scoop's config file. But it does not work well,
it replaced the 'ASCII' encoding of function `Set-Content` with
the 'Default' encoding. This does not work in PowerShell 5 since
the default encoding under PowerShell 5 [1] corresponds to the
system's active code page (usually ANSI).

This patch introduces a `Set-ContentUTF8NoBOM` function. It's a
wrapper of the `Out-File` function using the 'UTF8NoBOM' encoding
and .NET's `WriteAllText` function which saves file in a BOMless
UTF8 encoding [2]. When Scoop is executed under PowerShell 6+, the
native PowerShell `Out-File` function will be used, otherwise the
.NET's one will be used.

Also with this patch, now aria2 reads the correct `cachedir` from
Scoop's config file, and consumes the input-file which is also utf8
encoded. By changing console's encoding to utf8 temporarily, aria2's
output can display correctly even it contains non-ASCII.

Fixes ScoopInstaller#4629

[1]: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/set-content?view=powershell-5.1
[2]: https://docs.microsoft.com/en-us/dotnet/api/system.io.file.writealltext

Signed-off-by: Chawye Hsu <chawyehsu@hotmail.com>
se35710 pushed a commit to se35710/scoop that referenced this pull request Mar 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants