Skip to content

Commit 60583eb

Browse files
Fix cross-platform file command validation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent a3c9207 commit 60583eb

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

src/functions/public/Export-Yaml.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function Export-Yaml {
8888
Only FileSystem provider destinations are supported.
8989
9090
.LINK
91-
ConvertTo-Yaml
91+
https://psmodule.io/Yaml/Functions/ConvertTo-Yaml/
9292
#>
9393
[OutputType([System.IO.FileInfo])]
9494
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')]

src/functions/public/Import-Yaml.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function Import-Yaml {
8080
Only FileSystem provider paths are supported.
8181
8282
.LINK
83-
ConvertFrom-Yaml
83+
https://psmodule.io/Yaml/Functions/ConvertFrom-Yaml/
8484
#>
8585
[OutputType([object])]
8686
[CmdletBinding(DefaultParameterSetName = 'Path')]

tests/Import-Yaml.Tests.ps1

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,17 @@ Describe 'Import-Yaml' {
104104
It 'suppresses path case variants on case-insensitive filesystems' {
105105
$path = Join-Path $TestDrive 'CaseVariant.yaml'
106106
[System.IO.File]::WriteAllText($path, 'value: once')
107-
$caseVariantPath = $path.ToLowerInvariant()
107+
$caseVariantPath = Join-Path (
108+
Split-Path -Parent $path
109+
) ([System.IO.Path]::GetFileName($path).ToLowerInvariant())
108110
try {
109111
$null = [System.IO.File]::GetAttributes($caseVariantPath)
110112
} catch [System.IO.FileNotFoundException] {
111113
Set-ItResult -Skipped -Because 'the test filesystem is case-sensitive'
112114
return
115+
} catch [System.IO.DirectoryNotFoundException] {
116+
Set-ItResult -Skipped -Because 'the test filesystem is case-sensitive'
117+
return
113118
}
114119

115120
$result = @(Import-Yaml -Path @($path, $caseVariantPath))
@@ -156,14 +161,19 @@ Describe 'Import-Yaml' {
156161
It 'sorts by canonical identity regardless of duplicate path spelling' {
157162
$firstPath = Join-Path $TestDrive 'canonical-a.yaml'
158163
$secondPath = Join-Path $TestDrive 'canonical-b.yaml'
159-
$secondAlias = $secondPath.ToUpperInvariant()
164+
$secondAlias = Join-Path (
165+
Split-Path -Parent $secondPath
166+
) ([System.IO.Path]::GetFileName($secondPath).ToUpperInvariant())
160167
[System.IO.File]::WriteAllText($firstPath, 'value: first')
161168
[System.IO.File]::WriteAllText($secondPath, 'value: second')
162169
try {
163170
$null = [System.IO.File]::GetAttributes($secondAlias)
164171
} catch [System.IO.FileNotFoundException] {
165172
Set-ItResult -Skipped -Because 'the test filesystem is case-sensitive'
166173
return
174+
} catch [System.IO.DirectoryNotFoundException] {
175+
Set-ItResult -Skipped -Because 'the test filesystem is case-sensitive'
176+
return
167177
}
168178

169179
$result = @(Import-Yaml -Path @($secondAlias, $firstPath, $secondPath))

0 commit comments

Comments
 (0)