From 7d902dc15eff9b5e9b57af818b3e84f47ef778b4 Mon Sep 17 00:00:00 2001 From: "Kim J. Nordmo" Date: Tue, 12 Dec 2017 16:51:14 +0100 Subject: [PATCH] (GH-11) Fixed an issue where nupkg files aren't correctly encoded fixes #11 --- Wormies-AU-Helpers/public/Update-Metadata.ps1 | 3 +- chocolatey/legal/VERIFICATION.txt | 4 +- tests/public/Update-Metadata.Tests.ps1 | 49 +++++++++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/Wormies-AU-Helpers/public/Update-Metadata.ps1 b/Wormies-AU-Helpers/public/Update-Metadata.ps1 index 85023e3..5419f46 100644 --- a/Wormies-AU-Helpers/public/Update-Metadata.ps1 +++ b/Wormies-AU-Helpers/public/Update-Metadata.ps1 @@ -58,5 +58,6 @@ function Update-Metadata { } } - $nu.Save($NuspecFile) + $utf8NoBom = New-Object System.Text.UTF8Encoding($false) + [System.IO.File]::WriteAllText($NuspecFile, $nu.InnerXml, $utf8NoBom) } diff --git a/chocolatey/legal/VERIFICATION.txt b/chocolatey/legal/VERIFICATION.txt index a3b1aad..f415eeb 100644 --- a/chocolatey/legal/VERIFICATION.txt +++ b/chocolatey/legal/VERIFICATION.txt @@ -5,10 +5,10 @@ in verifying that this package's contents are trustworthy. This package is being officially supplied by the software author of these scripts (Kim J. Nordmo) The included binary file can be downloaded from our releases page located at - + and should match the following -sha256 checksum: F08FB87D483230891D401E55FAEB1B942BCFAA490707F95F1350026E8415F695 +sha256 checksum: 37449AFF73DC9E68269813E100F449AF042C2FEB953D073AECE724CEFB752715 The file 'License.txt' is also available in the repository at diff --git a/tests/public/Update-Metadata.Tests.ps1 b/tests/public/Update-Metadata.Tests.ps1 index a4d2633..a243698 100644 --- a/tests/public/Update-Metadata.Tests.ps1 +++ b/tests/public/Update-Metadata.Tests.ps1 @@ -1,6 +1,47 @@ Remove-Module wormies-au-helpers -ea ignore Import-Module "$PSScriptRoot/../../Wormies-AU-Helpers" +function Get-FileEncoding { + # + [CmdletBinding()] + param ( + [Alias("PSPath")] + [Parameter(Mandatory = $True, ValueFromPipelineByPropertyName = $True)] + [String]$Path + , + [Parameter(Mandatory = $False)] + [System.Text.Encoding]$DefaultEncoding = [System.Text.Encoding]::ASCII + ) + + process { + [Byte[]]$bom = Get-Content -Encoding Byte -ReadCount 4 -TotalCount 4 -Path $Path + + $encoding_found = $false + + foreach ($encoding in [System.Text.Encoding]::GetEncodings().GetEncoding()) { + if ($encoding_found) { break } + $preamble = $encoding.GetPreamble() + if ($preamble) { + foreach ($i in 0..$preamble.Length) { + if ($preamble[$i] -ne $bom[$i]) { + break + } + elseif ($i -eq $preable.Length) { + $encoding_found = $encoding + break + } + } + } + } + + if (!$encoding_found) { + $encoding_found = $DefaultEncoding + } + + $encoding_found + } +} + Describe "Update-Metadata" { $nuspecFile = "$PSScriptRoot\test.nuspec" BeforeEach { @@ -52,4 +93,12 @@ Describe "Update-Metadata" { $nuspecFile | Should -FileContentMatchExactly "\0\.5\.3\<\/version\>" $nuspecFile | Should -FileContentMatchExactly "\yuppie\<\/id\>" } + + It "Should create file without UTF8 BOM encoding" { + Update-Metadata -key "title" -value "NO BOM TEST" -NuspecFile $nuspecFile + + $expectedEncoding = New-Object System.Text.UTF8Encoding($false) + + Get-FileEncoding -Path $nuspecFile -DefaultEncoding $expectedEncoding | Should Be $expectedEncoding + } }