Skip to content

Conversation

@Gimly
Copy link
Contributor

@Gimly Gimly commented Oct 26, 2020

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

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.
@ghost ghost assigned iSazonov Oct 26, 2020
@iSazonov iSazonov added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Oct 27, 2020
@iSazonov
Copy link
Collaborator

@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().

@iSazonov iSazonov added CL-BreakingChange Indicates that a PR should be marked as a breaking change in the Change Log Review - Committee The PR/Issue needs a review from the PowerShell Committee labels Oct 27, 2020
@iSazonov
Copy link
Collaborator

Formally it is a breaking change (bracket 3) so I ask PowerShell Committee to review.

/cc @SteveL-MSFT @daxian-dbw

@Gimly
Copy link
Contributor Author

Gimly commented Oct 27, 2020

@iSazonov Sure, I will take a go at it.

@SteveL-MSFT
Copy link
Member

@PowerShell/powershell-committee reviewed this, we are ok with the change. There should be a test added to this PR however.

@SteveL-MSFT SteveL-MSFT added Committee-Reviewed PS-Committee has reviewed this and made a decision and removed Review - Committee The PR/Issue needs a review from the PowerShell Committee labels Oct 28, 2020
@iSazonov
Copy link
Collaborator

@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'
Copy link
Collaborator

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:

Suggested change
GetFileEncoding $transcriptFilePath | Should -Be 'utf-16'
GetFileEncoding $transcriptFilePath | Should -BeExactly 'utf-16'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@iSazonov iSazonov requested a review from JamesWTruher October 30, 2020 06:09
@Gimly
Copy link
Contributor Author

Gimly commented Nov 3, 2020

@iSazonov I'm not sure why the CI has failed, it looks like powershellget has failed. Maybe you need to restart the builds?

@iSazonov iSazonov closed this Nov 3, 2020
@iSazonov iSazonov reopened this Nov 3, 2020
@iSazonov
Copy link
Collaborator

iSazonov commented Nov 3, 2020

Reopen to restart CIs.

@ghost ghost added the Review - Needed The PR is being reviewed label Nov 10, 2020
@ghost
Copy link

ghost commented Nov 10, 2020

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

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())
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Collaborator

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.

Copy link
Member

@SteveL-MSFT SteveL-MSFT left a 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

@ghost ghost added Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept and removed Review - Needed The PR is being reviewed labels Dec 15, 2020
Co-authored-by: Steve Lee <slee@microsoft.com>
@ghost ghost removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Dec 15, 2020
@ghost ghost added the Review - Needed The PR is being reviewed label Dec 25, 2020
@ghost
Copy link

ghost commented Dec 25, 2020

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

@ghost ghost removed the Review - Needed The PR is being reviewed label Sep 15, 2021
@ghost ghost added the Review - Needed The PR is being reviewed label Sep 23, 2021
@ghost
Copy link

ghost commented Sep 23, 2021

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

Copy link
Member

@SteveL-MSFT SteveL-MSFT left a 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

@iSazonov
Copy link
Collaborator

/rebase

@ghost ghost removed the Review - Needed The PR is being reviewed label May 16, 2022
@github-actions
Copy link
Contributor

github-actions bot commented May 16, 2022

Started rebase: https://github.com/PowerShell/PowerShell/actions/runs/2333666772

GitHub
PowerShell for every system! Contribute to PowerShell/PowerShell development by creating an account on GitHub.

@pull-request-quantifier-deprecated

This PR has 27 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Extra Small
Size       : +26 -1
Percentile : 10.8%

Total files changed: 2

Change summary by file extension:
.cs : +1 -1
.ps1 : +25 -0

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detetcted.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

@iSazonov
Copy link
Collaborator

@Gimly Please look test failures.

@ghost ghost added the Review - Needed The PR is being reviewed label May 25, 2022
@ghost
Copy link

ghost commented May 25, 2022

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

@iSazonov iSazonov added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Oct 29, 2022
@ghost ghost added the Stale label Nov 13, 2022
@ghost
Copy link

ghost commented Nov 13, 2022

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.

@ghost ghost closed this Nov 23, 2022
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-BreakingChange Indicates that a PR should be marked as a breaking change in the Change Log CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log Committee-Reviewed PS-Committee has reviewed this and made a decision Extra Small Review - Needed The PR is being reviewed Stale Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Start-Transcript uses lossy ASCII character encoding instead of BOM-less UTF-8 if the target file happens to exist

4 participants