Repository navigation
Read config files as UTF-8 and keep durable profile backups - #9
Merged
Merged
Conversation
On Windows PowerShell 5.1 a bare Get-Content -Raw decodes with the system ANSI code page, so non-ASCII (e.g. aao) in settings was corrupted and then written back. Profile backups also rotated by time keeping five, so the user's original profile was lost after five installs and Uninstall-Profile restored nothing. - setup.ps1: add -Encoding UTF8 to the Get-Content -Raw reads of user-settings.json, Windows Terminal settings.json, theme.json, terminal-config.json, the OMP theme, and the wizard state file. - setup.ps1: on first install, save a one-time profile.original.ps1 that the oldprofile* rotation never deletes. - Uninstall-Profile: restore profile.original.ps1 instead of just removing the profile. - Update-Profile: back up the current profile before overwriting (rotated, latest five; the immutable original is never matched). - sed: read UTF-8 (BOM-aware) via Get-Utf8FileText and keep a .bak. - README: make the review-first hash flow the recommended default in the install-wizard section; -SkipHashCheck is the unverified fallback.
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.
Draft: install/uninstall paths are Windows-specific and can't be fully exercised here (no winget/elevation/
ssh.exe), so the runtime effect is verified by reasoning + parse/analyzer only.Fix B1 - UTF-8 reads (setup.ps1)
On Windows PowerShell 5.1 a bare
Get-Content -Rawdecodes with the system ANSI code page, so non-ASCII (e.g. the Norwegian letters) in settings got corrupted and then written back. Added-Encoding UTF8to theGet-Content -Rawreads of:user-settings.json(Save-WizardChoices + merge step)settings.json(the read-back before rewrite)theme.json/terminal-config.jsonbundle temp filesWrites already use
[IO.File]::WriteAllText(..., UTF8Encoding(false))(no BOM), so only reads needed fixing. NoSet-Content -Encoding UTF8introduced (that would BOM on PS5.1 and trip CI).Fix B2 - durable backups
profile.original.ps1. The existingoldprofile*.ps1rotation (keep 5) never matches that name, so the user's pre-install profile is no longer lost after 5 installs.profile.original.ps1exists, restore it over the profile (and drop the marker) instead of just deleting; otherwise the previous remove behavior is unchanged (so the-WhatIf"Remove profile file" path is preserved).oldprofile.<stamp>.ps1(keep 5) before overwriting it.Get-Utf8FileText(BOM-aware UTF-8) and write a single.bakof the pre-edit content before rewriting.Fix C - README (install-wizard section)
The "Install Wizard" section recommended
-SkipHashCheckas the "Default trusted-download flow". Reworded it to match the already-review-first Quick Install block at the top: run with no hash flag (prints hashes, stops), then re-run with-ExpectedSha256;-SkipHashCheckis labelled the unverified fallback. Added a one-line note that a signed-release / tag-pinning model is a maintainer follow-up (did not redesign the release model).Verification
Parser::ParseFileclean onsetup.ps1and the profile.Set-Content -Encoding UTF8in the changed.ps1files.sed.bakbehavior is reasoned, not run. No workflows touched.Follow-ups for the owner
tests/test.ps1uninstall sandboxes don't createprofile.original.ps1, so they still exercise the plain-remove path; a case covering original-restore would be worth adding.Get-Utf8FileText; a sweep for any remaining bareGet-Content -Raw | ConvertFrom-Jsonthere could be a small follow-up.