`Out-String -Stream` unexpectedly does not split multi-line input strings into individual lines too
See original GitHub issueNote: Originally submitted as a suggestion, now reclassified as as bug and rewritten accordingly.
Due to a presumed oversight, input objects to Out-String -Stream
that happen to be multi-line strings are not split into individual lines, even though doing so is the purpose of the -Stream
switch - see this Stack Overflow answer for background information.
Steps to reproduce
# Pass a single 3-line string, whose lines should be emitted individually.
"a`nb`nc" | Out-String -Stream | Should -Be a, b, c
Note: As with Get-Content
, CR, CRLF, and LF newlines should be recognized interchangeably.
Expected behavior
The test should succeed.
Actual behavior
The test fails:
Expected @('a', 'b', 'c'), but got 'a b c'
That is, the multi-line input string is passed through as-is (Pester converts it to a single-line representation for the sake of a concise error message).
Environment data
PowerShell Core 7.2.0-preview.2
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Read and split multiple lines into individual strings
Read each line and put into a List<String> and as soon as a - occurs, copy it to the instance of List<List<String>> and...
Read more >Sliting multiple lines - Power Platform Community - Microsoft
Solved: Intialize a variable named "A" of type string and enter a couple of lines of text. Then use Compose to split it....
Read more >JavaScript Multiline String – How to Create Multi Line ...
In this article, you will learn three different ways to create multiline strings in JavaScript. I will first explain the basics of strings...
Read more >Manage multiline messages | Filebeat Reference [8.9]
After the specified timeout, Filebeat sends the multiline event even if no new pattern is found to start a new event. The default...
Read more >Batch files: Build a string across multiple lines WITHOUT ...
The answer is explaining how to generate an actual multi-line string from a single-line parameter. I am wanting to do sort of the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks, @iSazonov.
Yes, the behavior is consistent with Windows PowerShell, but all that means is that the bug is present there too. While there is buggy / questionable legacy behavior that users indeed either (a) have taken advantage of or (b) have employed workarounds for that a fix would break, neither applies in this case:
Therefore, I think a fix for 7.2 is perfectly appropriate.
To save others having to follow the link in my previous comment about the intent behind and current behavior of
-Stream
:Out-String
by default emits a single multi-line string that is the formatted string representation of all of its input, as you would see it in the console, including a trailing newline (which arguably shouldn’t be added, but that’s a separate discussion - see https://github.com/PowerShell/PowerShell/issues/14444).If you add
-Stream
, the lines of this string are output one by one - except if multi-line strings happen to be among the input objects, which are not split into their lines (they are output as is); this is the bug at hand.That is, even the lines that make up the formatting-system’s string representation of a single object are output individually; e.g.:
Good point, @iSazonov - can you please relabel the issue?