-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Fix non append encoding to UTF8 No BOM in Start Transcript #13899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix non append encoding to UTF8 No BOM in Start Transcript #13899
Conversation
When the -Append file has not been set by the user, the file is emptied using WriteAllText. This method seems to keep the encoding of the file if it existed prior. We don't want this behavior and want to be sure that the UTF8NoBom is used. It calls the override with the encoding set.
|
@Gimly I am ok with the change but I want ask - have you an interest to make more cleanups in follow PR? We could remove TranscriptionOption.Encoding and Utils.GetEncoding(), instead we could use standard StreamReader() to detect encoding in TranscriptionOption.FlushContentToDisk(). |
|
Formally it is a breaking change (bracket 3) so I ask PowerShell Committee to review. |
|
@iSazonov Sure, I will take a go at it. |
|
@PowerShell/powershell-committee reviewed this, we are ok with the change. There should be a test added to this PR however. |
|
@Gimly Please add tests. I guess it will be 3 tests (without Append, with Append and file in UTF16 exists, with Append and file doesn't exist) |
| Get-Date | Out-Null | ||
| Stop-Transcript | ||
|
|
||
| GetFileEncoding $transcriptFilePath | Should -Be 'utf-16' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use BeExactly for strings here and below:
| GetFileEncoding $transcriptFilePath | Should -Be 'utf-16' | |
| GetFileEncoding $transcriptFilePath | Should -BeExactly 'utf-16' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
@iSazonov I'm not sure why the CI has failed, it looks like powershellget has failed. Maybe you need to restart the builds? |
|
Reopen to restart CIs. |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
test/powershell/Modules/Microsoft.Powershell.Host/Start-Transcript.Tests.ps1
Outdated
Show resolved
Hide resolved
test/powershell/Modules/Microsoft.Powershell.Host/Start-Transcript.Tests.ps1
Outdated
Show resolved
Hide resolved
| Receive-Job $job | Should -Be $null | ||
| } | ||
| It "Should keep the existing file's encoding if the 'Append' parameter is used"{ | ||
| $transcriptFilePath = Join-Path $TestDrive ([System.IO.Path]::GetRandomFileName()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better to put this in BeforeAll{} since it's reused?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've used the $transcriptFilePath that already existed in the BeforeAll instead of creating a new one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Gimly Please look CI fails.
SteveL-MSFT
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few minor suggestions
Co-authored-by: Steve Lee <slee@microsoft.com>
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
SteveL-MSFT
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay on this
|
/rebase |
|
Started rebase: https://github.com/PowerShell/PowerShell/actions/runs/2333666772
|
|
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
|
@Gimly Please look test failures. |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 15 days. It will be closed if no further activity occurs within 10 days of this comment. |
PR Summary
When the -Append file has not been set by the user, the file is emptied using WriteAllText.
This method seems to keep the encoding of the file if it existed prior, which as discussed in #13677 shouldn't be the case. Instead, it should simply use the default encoding which should be UTF8 Without BOM.
The fix is to call the override with the encoding set in the part of the code that clears the file content.
PR Context
Fixes #13677
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.