diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f40ac1..9902b30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `Get-PSModulePath` - Was using the wrong path separator on Linux and macOS. +- `Get-LocalizedData` + - Wrongly returned one or more boolean values in addition to + the localized string array. This was becuase the return value + was not handled when calling `Add()` and `Remove()` methods of + `$PSBoundParameters` so it was returned to the pipeline. ## [0.17.0] - 2024-01-23 diff --git a/source/Public/Get-LocalizedData.ps1 b/source/Public/Get-LocalizedData.ps1 index e186e02..76514c6 100644 --- a/source/Public/Get-LocalizedData.ps1 +++ b/source/Public/Get-LocalizedData.ps1 @@ -255,7 +255,7 @@ function Get-LocalizedData $FileName = $file.BaseName - $PSBoundParameters.Add('FileName', $file.Name) + $null = $PSBoundParameters.Add('FileName', $file.Name) Write-Debug -Message ('Looking for resolved file with base name: ''{0}''.' -f $FileName) } @@ -268,7 +268,7 @@ function Get-LocalizedData { $callingScriptRoot = $MyInvocation.PSScriptRoot - $PSBoundParameters.Add('BaseDirectory', $callingScriptRoot) + $null = $PSBoundParameters.Add('BaseDirectory', $callingScriptRoot) } # If UICulture wasn't specified use the OS configured one, otherwise use the one specified. @@ -423,7 +423,7 @@ function Get-LocalizedData $PSBoundParameters.Keys.ForEach({ if ($_ -notin $getLocalizedDataForInvariantCultureParameters.Parameters.Keys) { - $PSBoundParameters.Remove($_) + $null = $PSBoundParameters.Remove($_) } }) @@ -437,7 +437,7 @@ function Get-LocalizedData Write-Debug ('Calling Microsoft.PowerShell.Utility\Import-LocalizedData using parameters: {0}' -f ($PSBoundParameters | Out-String)) # Removes the parameter DefaultUICulture so that isn't used when calling Import-LocalizedData. - $PSBoundParameters.Remove('DefaultUICulture') + $null = $PSBoundParameters.Remove('DefaultUICulture') $localizedData = Microsoft.PowerShell.Utility\Import-LocalizedData @PSBoundParameters } diff --git a/tests/Unit/Public/Get-LocalizedData.Tests.ps1 b/tests/Unit/Public/Get-LocalizedData.Tests.ps1 index d123d95..02fb7b1 100644 --- a/tests/Unit/Public/Get-LocalizedData.Tests.ps1 +++ b/tests/Unit/Public/Get-LocalizedData.Tests.ps1 @@ -46,6 +46,13 @@ AfterAll { } Describe 'Get-LocalizedData' -Tag 'GetLocalizedData' { + Context 'When returning localized data from a file' { + It 'Should return an hashtable' { + $result = Get-LocalizedData -FileName 'DscResource.Common.strings.psd1' -BaseDirectory "$PSScriptRoot/../../../output/builtModule/DscResource.Common/**/en-US" -DefaultUICulture 'en-US' -ErrorAction 'Stop' + $result | Should -BeOfType 'Hashtable' + } + } + Context 'When specifying a specific filename' { BeforeAll { New-Item -Force -Path 'TestDrive:\ar-SA' -ItemType Directory