Skip to content

Commit

Permalink
Get-LocalizedData: Fix returning additional (wrong) values to pipeline (
Browse files Browse the repository at this point in the history
  • Loading branch information
johlju authored Apr 23, 2024
1 parent 9471465 commit 6c8c38b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions source/Public/Get-LocalizedData.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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.
Expand Down Expand Up @@ -423,7 +423,7 @@ function Get-LocalizedData
$PSBoundParameters.Keys.ForEach({
if ($_ -notin $getLocalizedDataForInvariantCultureParameters.Parameters.Keys)
{
$PSBoundParameters.Remove($_)
$null = $PSBoundParameters.Remove($_)
}
})

Expand All @@ -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
}
Expand Down
7 changes: 7 additions & 0 deletions tests/Unit/Public/Get-LocalizedData.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6c8c38b

Please sign in to comment.