microsoft / microsoft/winget-cli

Settings File Encoding Matters??

Open
#2,084 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area-Settings Issue-Bug
Dominant language
C++
Stars
26.4k
Forks
1.8k
Avg merge
1d 11h
Merged PRs (30d)
15

Description

Brief description of your issue

I tried to create the settings file using PowerShell, and found that I got an error if -Encoding ASCII wasn't used

Steps to reproduce
  1. Run this in PowerShell -
Remove-Item (Join-Path $env:LOCALAPPDATA 'Packages\WinGetDevCLI_8wekyb3d8bbwe\LocalState\settings.json.backup') #Removes backup settings for consistent reproduction
$settingsContent = @'
 {
     "$schema": "https://aka.ms/winget-settings.schema.json",
     "logging": {
         "level": "verbose"
     },
     "experimentalFeatures": {
         "dependencies": true,
         "portableInstall": true
 }
'@
$settingsContent | Out-File (Join-Path $env:LOCALAPPDATA 'Packages\WinGetDevCLI_8wekyb3d8bbwe\LocalState\settings.json')
  1. Run wingetdev - note the warning at the top Unexpected error while loading settings. Please verify your settings by running the 'settings' command.

  2. Run wingetdev settings - note the warning and also that the valid json appears in the file

Unexpected error while loading settings. Please verify your settings by running the 'settings' command.
The following failures were found validating the settings:
Error parsing file: settings.json
* Line 1, Column 1
  Syntax error: value, object or array expected.
  1. Run this in the same PowerShell instance from step 1 -
$settingsContent | Out-File (Join-Path $env:LOCALAPPDATA 'Packages\WinGetDevCLI_8wekyb3d8bbwe\LocalState\settings.json') -Encoding ASCII
  1. Repeat steps 2 and 3, but note that there is no error
Expected behavior

Winget should be able to load settings

Actual behavior

Winget won't load settings if in certain encodings.

Tested with -

  • unicode
  • bigendianunicode
  • string
  • unknown
Environment

Tested using development build created off of https://github.com/microsoft/winget-cli/commit/cf85374d37cc9391e22bff62aac9b62b524d4398

Also tested using v1.3.431-preview

Contributor guide

Open the contributing guide

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.

Research direction

Start by reproducing the settings.json loading failure with PowerShell Out-File using its default encoding, then compare it with the -Encoding ASCII case. Trace the wingetdev settings command and the settings-file parsing path; done means valid files produced by the tested PowerShell encodings load without the warning while malformed files still report validation errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, powershell
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.