Skip to content

Commit ccf9a01

Browse files
Bind YAML file properties as literal paths
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 7795f14 commit ccf9a01

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

src/functions/public/Import-Yaml.ps1

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,13 @@ function Import-Yaml {
8585
[OutputType([object])]
8686
[CmdletBinding(DefaultParameterSetName = 'Path')]
8787
param (
88-
# Expands wildcard paths and accepts path values or FullName properties.
88+
# Expands wildcard paths and accepts string pipeline values.
8989
[Parameter(
9090
Mandatory,
9191
Position = 0,
9292
ValueFromPipeline,
93-
ValueFromPipelineByPropertyName,
9493
ParameterSetName = 'Path'
9594
)]
96-
[Alias('FullName')]
9795
[string[]] $Path,
9896

9997
# Resolves exact paths from LiteralPath, PSPath, or FullName properties.
@@ -102,7 +100,7 @@ function Import-Yaml {
102100
ValueFromPipelineByPropertyName,
103101
ParameterSetName = 'LiteralPath'
104102
)]
105-
[Alias('PSPath')]
103+
[Alias('PSPath', 'FullName')]
106104
[string[]] $LiteralPath,
107105

108106
# Selects the fallback decoder when a file has no byte order mark.

tests/Import-Yaml.Tests.ps1

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ Describe 'Import-Yaml' {
3030
$pathParameter.IsMandatory | Should -BeTrue
3131
$pathParameter.Position | Should -Be 0
3232
$pathParameter.ValueFromPipeline | Should -BeTrue
33-
$pathParameter.ValueFromPipelineByPropertyName | Should -BeTrue
33+
$pathParameter.ValueFromPipelineByPropertyName | Should -BeFalse
3434
$literalPathParameter.IsMandatory | Should -BeTrue
3535
$literalPathParameter.ValueFromPipeline | Should -BeFalse
3636
$literalPathParameter.ValueFromPipelineByPropertyName | Should -BeTrue
37-
$command.Parameters['Path'].Aliases | Should -Contain 'FullName'
37+
$command.Parameters['Path'].Aliases | Should -Not -Contain 'FullName'
3838
$command.Parameters['LiteralPath'].Aliases | Should -Contain 'PSPath'
39+
$command.Parameters['LiteralPath'].Aliases | Should -Contain 'FullName'
3940
$command.OutputType.Type | Should -Contain ([object])
4041
}
4142

@@ -262,15 +263,24 @@ Describe 'Import-Yaml' {
262263
(Import-Yaml -LiteralPath $path).value | Should -Be 'literal'
263264
}
264265

265-
It 'accepts FileInfo pipeline input through Path' {
266-
$path = Join-Path $TestDrive 'pipeline.yaml'
266+
It 'resolves FileInfo pipeline input literally' {
267+
$path = Join-Path $TestDrive 'config[production].yaml'
267268
[System.IO.File]::WriteAllText($path, 'value: pipeline')
268269

269270
$result = Get-Item -LiteralPath $path | Import-Yaml
270271

271272
$result.value | Should -Be 'pipeline'
272273
}
273274

275+
It 'resolves FullName pipeline properties literally' {
276+
$path = Join-Path $TestDrive 'full[name].yaml'
277+
[System.IO.File]::WriteAllText($path, 'value: fullname')
278+
279+
$result = [pscustomobject]@{ FullName = $path } | Import-Yaml
280+
281+
$result.value | Should -Be 'fullname'
282+
}
283+
274284
It 'accepts PSPath pipeline properties through LiteralPath' {
275285
$path = Join-Path $TestDrive 'literal[2].yaml'
276286
[System.IO.File]::WriteAllText($path, 'value: property')

0 commit comments

Comments
 (0)