mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2026-11-25 23:16:15 +01:00
fix: read JSON as UTF-8 so BOM-less packs load correctly (#844)
This commit is contained in:
@@ -187,6 +187,14 @@ Describe 'Get-AppRemovalMethod' {
|
||||
Get-AppRemovalMethod -appId 'Unknown.App' | Should -Be 'Appx'
|
||||
}
|
||||
|
||||
It 'resolves WinGet removal for non-ASCII IDs from BOM-less UTF-8 JSON' {
|
||||
$appId = 'Test.' + [char]0x00E9 + [char]0x4E2D + [char]0x0416
|
||||
$json = @{ Apps = @(@{ AppId = $appId; RemovalMethod = 'WinGet' }) } | ConvertTo-Json -Depth 4
|
||||
[System.IO.File]::WriteAllText($script:AppsListFilePath, $json, [System.Text.UTF8Encoding]::new($false))
|
||||
|
||||
Get-AppRemovalMethod -appId $appId | Should -Be 'WinGet'
|
||||
}
|
||||
|
||||
It 'warns and defaults to Appx when the catalog is malformed' {
|
||||
'not json' | Set-Content -LiteralPath $script:AppsListFilePath
|
||||
Mock Write-Warning {}
|
||||
|
||||
@@ -117,6 +117,15 @@ Describe 'Save-Settings' {
|
||||
}
|
||||
|
||||
Describe 'Import-AppsFromFile' {
|
||||
It 'preserves selected non-ASCII IDs from BOM-less UTF-8 JSON' {
|
||||
$path = Join-Path $TestDrive 'apps-utf8.json'
|
||||
$appId = 'Test.' + [char]0x00E9 + [char]0x4E2D + [char]0x0416
|
||||
$json = @{ Apps = @(@{ AppId = $appId; SelectedByDefault = $true }) } | ConvertTo-Json -Depth 4
|
||||
[System.IO.File]::WriteAllText($path, $json, [System.Text.UTF8Encoding]::new($false))
|
||||
|
||||
@(Import-AppsFromFile -appsFilePath $path) | Should -Be @($appId)
|
||||
}
|
||||
|
||||
It 'returns selected IDs, trims whitespace, and supports scalar and array AppId values' {
|
||||
$path = Join-Path $TestDrive 'apps.json'
|
||||
'{"Apps":[{"AppId":" One.App ","SelectedByDefault":true},{"AppId":["Two.App"," "],"SelectedByDefault":true},{"AppId":"Ignored.App","SelectedByDefault":false}]}' |
|
||||
@@ -215,6 +224,32 @@ Describe 'Import-AppDetailsFromJson' {
|
||||
$presets[0].AppIds | Should -Be 'One.App'
|
||||
}
|
||||
|
||||
It 'preserves non-ASCII app IDs and fallback names from BOM-less UTF-8 JSON' {
|
||||
$appId = 'Test.' + [char]0x00E9 + [char]0x4E2D + [char]0x0416
|
||||
$json = @{ Apps = @(@{ AppId = $appId }) } | ConvertTo-Json -Depth 4
|
||||
[System.IO.File]::WriteAllText($script:AppsListFilePath, $json, [System.Text.UTF8Encoding]::new($false))
|
||||
|
||||
$apps = @(Import-AppDetailsFromJson)
|
||||
|
||||
$apps | Should -HaveCount 1
|
||||
$apps[0].AppId | Should -Be @($appId)
|
||||
$apps[0].FriendlyName | Should -Be $appId
|
||||
$apps[0].DisplayName | Should -Be "$appId ($appId)"
|
||||
}
|
||||
|
||||
It 'preserves non-ASCII preset names and IDs from BOM-less UTF-8 JSON' {
|
||||
$presetName = 'Preset ' + [char]0x00E9 + [char]0x4E2D + [char]0x0416
|
||||
$appId = 'Test.' + [char]0x4E2D
|
||||
$json = @{ Presets = @(@{ Name = $presetName; AppIds = @($appId) }) } | ConvertTo-Json -Depth 4
|
||||
[System.IO.File]::WriteAllText($script:AppsListFilePath, $json, [System.Text.UTF8Encoding]::new($false))
|
||||
|
||||
$presets = @(Import-AppPresetsFromJson)
|
||||
|
||||
$presets | Should -HaveCount 1
|
||||
$presets[0].Name | Should -Be $presetName
|
||||
$presets[0].AppIds | Should -Be @($appId)
|
||||
}
|
||||
|
||||
It 'returns empty collections and reports malformed JSON' {
|
||||
'not json' | Set-Content -LiteralPath $script:AppsListFilePath
|
||||
Mock Write-Error {}
|
||||
|
||||
Reference in New Issue
Block a user