Skip to content

Commit

Permalink
Merge branch 'hotfix/force-utf8-no-bom'
Browse files Browse the repository at this point in the history
  • Loading branch information
AdmiringWorm committed Dec 12, 2017
2 parents abb8f53 + 7d902dc commit 1ec4e72
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Wormies-AU-Helpers/public/Update-Metadata.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions chocolatey/legal/VERIFICATION.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
<https://github.com/WormieCorp/Wormies-AU-Helpers/releases/tag/0.1.0-alpha0060>
<https://github.com/WormieCorp/Wormies-AU-Helpers/releases/tag/0.1.0>

and should match the following
sha256 checksum: F08FB87D483230891D401E55FAEB1B942BCFAA490707F95F1350026E8415F695
sha256 checksum: 37449AFF73DC9E68269813E100F449AF042C2FEB953D073AECE724CEFB752715

The file 'License.txt' is also available in the repository at
<https://github.com/WormieCorp/Wormies-AU-Helpers/blob/develop/LICENSE>
49 changes: 49 additions & 0 deletions tests/public/Update-Metadata.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,47 @@
Remove-Module wormies-au-helpers -ea ignore
Import-Module "$PSScriptRoot/../../Wormies-AU-Helpers"

function Get-FileEncoding {
# <https://vertigion.com/2015/02/04/powershell-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 {
Expand Down Expand Up @@ -52,4 +93,12 @@ Describe "Update-Metadata" {
$nuspecFile | Should -FileContentMatchExactly "\<version\>0\.5\.3\<\/version\>"
$nuspecFile | Should -FileContentMatchExactly "\<id\>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
}
}

0 comments on commit 1ec4e72

Please sign in to comment.