Use of script blocks can result in different output behavior with respect to culture-sensitivity #4558
Labels
Issue-Discussion
the issue may not have a clear classification yet. The issue may generate an RFC or may be reclassif
Resolution-No Activity
Issue has had no activity for 6 months or more
WG-Engine
core PowerShell engine, interpreter, and runtime
Follow-up to #4545.
With expressions, simply wrapping a script block in another script block changes the output behavior with respect to culture-sensitivity, at least with respect to passing a number literal to an unconstrained parameter.
With commands - e.g.,
Write-Host
andWrite-Output
a single script block is enough.@lzybkr's assessment of this problem:
This resetting isn't categorical: as the command below shows, the default output of a literal is still localized, and
[cultureinfo]::currentculture
still reports the specified culture.So the questions is: In what way is the culture reset (if that's what's going on) and what are the implications?
With commands using cmdlets
Write-Host
andWrite-Output
and a single script block:Steps to reproduce
Expected behavior
Actual behavior
As an aside: Moving the
[cultureinfo]::CurrentCulture = 'de-DE'
statement into the script block would make the problem go away.With expressions and nested script blocks:
While the nesting of the script blocks in the example command below is contrived, I actually ran into this problem in a real-world scenario:
I'm using a function called
Use-Culture
(inspired by this oldie-but-goodie blog post by @rkeithhill) that accepts a script block to be executed in the context of a specified culture that is temporarily switched to, with invocations such asUse-Culture de-DE { & { $Args[0] } 1.2 }
, in which script blocks are nested.Steps to reproduce
Expected behavior
Actual behavior
Note that the fact that the non-nested invocation's unconstrained parameter value is output in culture-sensitive format - it uses
,
as the decimal mark - is actually a bug - see #4557.Environment data
The text was updated successfully, but these errors were encountered: