Skip to content

Read registry backups as UTF8 - #28

Merged
BiosSystem merged 1 commit into
masterfrom
feature/backup-read-encoding
Sep 7, 2026
Merged

Read registry backups as UTF8#28
BiosSystem merged 1 commit into
masterfrom
feature/backup-read-encoding

Conversation

@BiosSystem

Copy link
Copy Markdown
Owner

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 merely failing.

Latent, not active

SaveToFile writes 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:

SaveToFile writes a BOM : True
BOM file reads correctly with no -Encoding                PASS
no-BOM file reads correctly with no -Encoding             FAIL
   got: C:\Users\José\AppData\Señor
no-BOM file reads correctly WITH -Encoding UTF8           PASS

The .reg reader is deliberately untouched

Get-RegFileOperations also reads with no -Encoding, and it must stay that way. Regedit writes .reg as UTF-16LE with a BOM - verified, the repo's files start FF FE - which Get-Content already detects. Forcing UTF8 there would corrupt all 100-plus registry files. A test pins that so nobody applies the same fix twice.

Verified

WinSwift-written backup keeps accents                     PASS
BOM-less backup keeps accents (was corrupting)            PASS
   got: C:\Users\José\AppData\Señor
missing file still throws                                 PASS
invalid JSON still throws                                 PASS
reg file still parses (Add_All_Folders_Under_This_PC.reg) PASS
   operations parsed: 13

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 reading Apps.json, which is pure ASCII today. Lower risk than the restore path and left for a separate change.

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.
@BiosSystem
BiosSystem merged commit 6d25568 into master Sep 7, 2026
1 check passed
@BiosSystem
BiosSystem deleted the feature/backup-read-encoding branch September 7, 2026 18:25
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.

1 participant