Skip to content

Get-Content -Raw should not neglects to read the last character - #5076

Merged
Ilya (iSazonov) merged 2 commits into
PowerShell:masterfrom
chunqingchen:bugfix0
Oct 13, 2017
Merged

Ilya (iSazonov) merged 2 commits into
PowerShell:masterfrom
chunqingchen:bugfix0

Conversation

@chunqingchen

@chunqingchen Chunqing Chen (chunqingchen) commented Oct 10, 2017 •

Copy link
Copy Markdown
Contributor

resolve #4980

once the -raw parameter is set, we should force the contentString not to substring under any circumstance

Before the fix:
get-content -raw will ignore \n

After the fix:
get-content -raw will get all the contents include \n

@iSazonov

Copy link
Copy Markdown
Collaborator

Michael Klement (@mklement0) Could you please review?

string contentString = content.ToString();
blocks.Add(
!readBackward && contentString.EndsWith(actualDelimiter, StringComparison.Ordinal)
!readBackward && contentString.EndsWith(actualDelimiter, StringComparison.Ordinal) && !_isRawStream

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good;
but original issue says that "Note that Windows Powershell is not affected".
Any ideas why this does not repro in Windows PS?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because the code is introduced by core ps code change.

}
}

Describe "Get-Content -Raw test" -Tags "CI" {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test code is a good candidate to be rewritten using -testcases construct, as per testing guidelines.

@iSazonov Ilya (iSazonov) self-assigned this Oct 11, 2017
@chunqingchen

Copy link
Copy Markdown
Contributor Author

Andrew (@anmenaga) your comments are resolved. thanks

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move to It block:

It "Reads - <testname> in full" -TestCases @(
    @{character = "a`nb`n"; testname = "LF-terminated files"; filename = "lf.txt"} 
    ....
) {
    ....
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your comment. But I would rather not change it as it is just format preference and the submitted format is following the testing guidelines example.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is new code not formatting. We should place it in a right place. The right place is either It block (sample) or BeforeAll block. We use the set only one time so It block is best place. This does not contradict the testing guidelines.

@iSazonov
Ilya (iSazonov) merged commit 07d3b18 into PowerShell:master Oct 13, 2017
@iSazonov

Copy link
Copy Markdown
Collaborator

Chunqing Chen (@chunqingchen) Thanks for the fix!

Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Get-Content -Raw neglects to read the last character, if it is a LF

3 participants