Skip to content

Git Sync: editing a script in PSU writes UTF-8 BOM that breaks raw Invoke-WebRequest | Invoke-Expression execution, and rename does not update repository filename #5607

@RubenT91

Description

@RubenT91

Description of Issue

When using PowerShell Universal with TwoWay Git Sync, editing and saving a script from the PSU UI can rewrite the script with a UTF-8 BOM (EF BB BF). After that sync completes, the script may still run correctly inside PSU, but external execution of the raw script content via Invoke-WebRequest | Invoke-Expression fails because the BOM contaminates the first token.

A second issue was also reproduced in the same workflow: renaming a script in PSU updates the display name in PSU, but the physical filename in the synchronized repository is not renamed.

Both behaviors were reproduced in an internal lab using the affected version listed below.

List of steps, sample code, failing test, or link to a project that reproduces the behavior.

Repro 1: BOM introduced after editing in PSU

  1. Configure PSU with Git Sync:

    • Mode: TwoWay
    • Branch: master
    • Edit mode: Automatic
    • Sync interval: 1 minute
  2. In the Git remote, create a script file such as SampleScript.ps1 with simple content like:

    Get-Date
    Write-Output "OK"
  3. Allow PSU to sync and import the script.

  4. Confirm the script runs:

    • Inside PSU
    • Externally by downloading the raw script content and piping it to Invoke-Expression
  5. Edit the script in PSU and save any small change, for example:

    Get-Date
    Write-Output "OK2"
  6. Allow the change to sync back to the Git remote.

  7. Check the script bytes in the synchronized repository copy. The file now begins with:

    EF BB BF
    
  8. Run the raw script content externally again:

    Invoke-WebRequest <raw-script-url> | Invoke-Expression
  9. The script now fails because the first token is interpreted with leading unexpected characters.

Observed behavior

  • PSU execution: succeeds
  • External raw-content execution via Invoke-WebRequest | Invoke-Expression: fails after PSU save/sync
  • File content after PSU save includes UTF-8 BOM (EF BB BF)

Expected behavior

  • Editing and saving a script in PSU should not introduce an encoding change that breaks downstream execution scenarios.
  • PSU should either preserve the existing encoding or provide a way to save without BOM when appropriate.

Repro 2: Rename does not rename physical repository file

  1. Create or sync a script named SampleScript.ps1.
  2. In PSU, rename it to RenamedSampleScript.ps1.
  3. Allow Git Sync to complete.

Observed behavior

  • The script name shown in PSU changes.
  • The physical file in the synchronized repository remains with the original filename.

Expected behavior

  • Renaming a script in PSU should also rename the physical file in the synchronized repository.

Version

5.6.13

Severity

High

Hosting Method

MSI (Windows Service)

Operating System

Windows

Database

SQLite

Licensed

Yes

Features

Git Sync

Additional Environment data

Internal reproduction also validated on:

Windows 11 Pro 10.0.26200
Windows PowerShell 5.1.26100.7705
PowerShell 7.5.4

Screenshots/Animations

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    requires triageIssue has not yet been verified by the development team.v5Version 5 issue.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions