@@ -270,6 +270,63 @@ float: .nan
270270 }
271271
272272 Context ' Validation and parser limits' {
273+ It ' keeps exact effective tag-length boundaries idempotent' - ForEach @ (
274+ @ {
275+ Name = ' local'
276+ Yaml = ' !abc value'
277+ TooLong = ' !abcd value'
278+ Limit = 4
279+ }
280+ @ {
281+ Name = ' verbatim'
282+ Yaml = ' !<a%20b> value'
283+ TooLong = ' !<a%20bc> value'
284+ Limit = 3
285+ }
286+ @ {
287+ Name = ' expanded handle'
288+ Yaml = " %TAG !e! tag:x%2C`n ---`n !e!a value"
289+ TooLong = " %TAG !e! tag:x%2C`n ---`n !e!ab value"
290+ Limit = 7
291+ }
292+ ) {
293+ $first = $Yaml | Format-Yaml - MaxTagLength $Limit
294+ $second = $first | Format-Yaml - MaxTagLength $Limit
295+ $failure = Get-TestYamlFailure {
296+ $TooLong | Format-Yaml - MaxTagLength $Limit
297+ }
298+
299+ $second | Should - BeExactly $first
300+ $failure.Exception.Data [' YamlErrorId' ] |
301+ Should - BeExactly ' YamlTagLimitExceeded'
302+ }
303+
304+ It ' keeps the default tag-length boundary idempotent' {
305+ $accepted = ' !' + (' a' * 1023 ) + ' value'
306+ $rejected = ' !' + (' a' * 1024 ) + ' value'
307+
308+ $first = $accepted | Format-Yaml
309+ ($first | Format-Yaml ) | Should - BeExactly $first
310+ $failure = Get-TestYamlFailure {
311+ $rejected | Format-Yaml
312+ }
313+ $failure.Exception.Data [' YamlErrorId' ] |
314+ Should - BeExactly ' YamlTagLimitExceeded'
315+ }
316+
317+ It ' keeps cumulative effective tag budgets idempotent' {
318+ $yaml = " !abc one`n ---`n !def two"
319+ $first = $yaml | Format-Yaml - MaxTagLength 4 - MaxTotalTagLength 8
320+
321+ ($first | Format-Yaml - MaxTagLength 4 - MaxTotalTagLength 8 ) |
322+ Should - BeExactly $first
323+ $failure = Get-TestYamlFailure {
324+ $yaml | Format-Yaml - MaxTagLength 4 - MaxTotalTagLength 7
325+ }
326+ $failure.Exception.Data [' YamlErrorId' ] |
327+ Should - BeExactly ' YamlTagLimitExceeded'
328+ }
329+
273330 It ' classifies every parser resource limit like ConvertFrom-Yaml' - ForEach @ (
274331 @ { Name = ' depth' ; Yaml = " a:`n b:`n c: value" ; Parameters = @ { Depth = 2 } }
275332 @ { Name = ' nodes' ; Yaml = ' [one, two]' ; Parameters = @ { MaxNodes = 2 } }
0 commit comments