Read registry backups as UTF8 - #28
Merged
Merged
Conversation
Load-RegistryBackupFromFile read with no -Encoding, so Windows PowerShell 5.1 fell back to the ANSI codepage for a file with no BOM. Registry data holds non-ASCII, an accented user profile path being the obvious case, and this is the restore path, so a corrupted read writes mangled values back to the system rather than just failing. Latent rather than active. SaveToFile writes with -Encoding UTF8, which in 5.1 emits a BOM, so WinSwift's own backups happened to read correctly. Anything produced elsewhere has no BOM: PowerShell 7 writes UTF8 without one by default, and the restore dialog invites users to supply their own files. Confirmed the failure before fixing it, a BOM-less backup came back as C:\Users\JosA\AppData\SeAor. Left Get-RegFileOperations alone deliberately. Regedit writes .reg as UTF-16LE with a BOM, which Get-Content already detects, and forcing UTF8 there would corrupt every registry file in the repository. A test pins that so nobody applies the same fix twice. Verified the loader keeps accents from both a WinSwift backup and a BOM-less one, still throws for a missing file and for invalid JSON, and that a real .reg file still parses to its 13 operations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Load-RegistryBackupFromFileread with no-Encoding, so Windows PowerShell 5.1 fell back to the ANSI codepage for a file with no BOM. Registry data holds non-ASCII - an accented user profile path being the obvious case - and this is the restore path, so a corrupted read writes mangled values back to the system rather than merely failing.Latent, not active
SaveToFilewrites with-Encoding UTF8, which in 5.1 emits a BOM, so WinSwift's own backups happened to read correctly. The read was working by accident.Anything produced elsewhere has no BOM: PowerShell 7 writes UTF8 without one by default, and the restore dialog explicitly invites users to supply files ("Only use backup files generated by WinSwift" is a warning, not an enforcement). Confirmed the failure before fixing it:
The .reg reader is deliberately untouched
Get-RegFileOperationsalso reads with no-Encoding, and it must stay that way. Regedit writes.regas UTF-16LE with a BOM - verified, the repo's files startFF FE- whichGet-Contentalready detects. Forcing UTF8 there would corrupt all 100-plus registry files. A test pins that so nobody applies the same fix twice.Verified
Error handling is unchanged: a missing file and invalid JSON still throw as before.
Static validation passes (112 files), standalone rebuilt and parse-checked.
Four other reads still lack
-Encoding-RemoveApps,LoadAppPresetsFromJson,LoadAppsDetailsFromJson,LoadAppsFromFile- all readingApps.json, which is pure ASCII today. Lower risk than the restore path and left for a separate change.