Skip to content

Commit 1f5d117

Browse files
Compare YAML removal keys ordinally
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 5e50aaf commit 1f5d117

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

src/functions/private/Resolve-YamlRemovalTarget.ps1

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,19 @@ function Resolve-YamlRemovalTarget {
6767

6868
$resolvedKey = (Resolve-YamlScalar -Node $keyNode).Value
6969
$effectiveTag = Get-YamlEffectiveTag -Node $keyNode -Value $resolvedKey
70-
if ($effectiveTag -cne 'tag:yaml.org,2002:str') {
70+
if (-not [string]::Equals(
71+
$effectiveTag,
72+
'tag:yaml.org,2002:str',
73+
[System.StringComparison]::Ordinal
74+
)) {
7175
$hasUnaddressableKey = $true
7276
continue
7377
}
74-
if ([string] $keyNode.Value -ceq $token) {
78+
if ([string]::Equals(
79+
[string] $keyNode.Value,
80+
$token,
81+
[System.StringComparison]::Ordinal
82+
)) {
7583
$matchingIndexes.Add($entryIndex)
7684
}
7785
}

tests/Remove-YamlEntry.Tests.ps1

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,27 @@ keep: true
223223
$actual | Should -BeExactly ("name: lower`nkeep: true" | Format-Yaml)
224224
}
225225

226+
It 'matches mapping key code points ordinally' {
227+
$composed = [string] [char] 0x00E9
228+
$decomposed = 'e' + [char] 0x0301
229+
$yaml = '"' + $decomposed + '": value' + "`nkeep: true"
230+
231+
Remove-YamlEntry $yaml ('/' + $composed) -IgnoreMissing |
232+
Should -BeExactly ($yaml | Format-Yaml)
233+
234+
$result = Remove-YamlEntry $yaml ('/' + $decomposed) |
235+
ConvertFrom-Yaml -AsHashtable
236+
$result.Contains($decomposed) | Should -BeFalse
237+
$result['keep'] | Should -BeTrue
238+
}
239+
240+
It 'does not treat a linguistically equal unknown tag as a string tag' {
241+
$yaml = "!<tag:yaml.org,2002:st%C2%ADr> key: tagged`nkeep: true"
242+
243+
Remove-YamlEntry $yaml '/key' -IgnoreMissing |
244+
Should -BeExactly ($yaml | Format-Yaml)
245+
}
246+
226247
It 'treats explicit string keys as strings and plain numeric keys as numbers' {
227248
$yaml = @'
228249
1: numeric

0 commit comments

Comments
 (0)