Skip to content

Fix 'Get-Content -Delimiter' to not include the delimiter in the returned lines - #3808

Merged
Dongbo Wang (daxian-dbw) merged 2 commits into
PowerShell:masterfrom
mklement0:get-content-delimiter-fix
Sep 1, 2017
Merged

Dongbo Wang (daxian-dbw) merged 2 commits into
PowerShell:masterfrom
mklement0:get-content-delimiter-fix

Conversation

@mklement0

@mklement0 Michael Klement (mklement0) commented May 18, 2017 •

Copy link
Copy Markdown
Contributor

Fix #3706

@msftclas

Michael Klement (@mklement0),
Thanks for having already signed the Contribution License Agreement. Your agreement was validated by Microsoft. We will now review your pull request.
Thanks,
Microsoft Pull Request Bot

@iSazonov Ilya (iSazonov) left a comment

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.

Michael Klement (@mklement0) It seems you don't fix "tail".

/cc jeffbi Could you please review?

@iSazonov
Ilya (iSazonov) requested a review from jeffbi May 18, 2017 11:03
@mklement0

Copy link
Copy Markdown
Contributor Author

Ilya (@iSazonov) Thanks for catching the -tail issue - oddly, the tests pass on macOS (which is where I ran them before submitting the PR). I'll look into it.

@iSazonov

Copy link
Copy Markdown
Collaborator

I believe the problem is in platform difference of Newline.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can this be converted to use the -TestCase parameter for It? That would make the test much more readable.

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.

I didn't write these tests (and the only modification I made was to resolve aliases to their full cmdlet names), but I can look into it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Rather than change it here, I suggest we open a new issue to refactor these test cases to use -TestCase

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I filed Issue #3945 to cover this comment.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Any reason to skip on Linux or OSX?

@mklement0 Michael Klement (mklement0) May 24, 2017 •

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.

Again, I can't speak to these tests, but perhaps BugId(BugDatabase.WindowsOutOfBandReleases, 906022) holds the key?

Separately, if you have any pointers as to why the PR doesn't work on Windows (have yet to dig into it), that would be helpful.

Ilya (@iSazonov) thinks that it may be the difference in newline sequences, though that's not immediately obvious to me.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

unfortunately, I don't know if that bug database even exists anymore. that comment is basically worthless now.

@mirichmo

Copy link
Copy Markdown
Member

Aditya Patwardhan (@adityapatwardhan) I don't see any more outstanding comments. Do you have any additional concerns?

@mirichmo

Copy link
Copy Markdown
Member

Michael Klement (@mklement0) Please address the failing test:

[-] should Get-Content with a variety of -Tail and -ReadCount values 68ms
Expected: {2}
But was: {3}
at line: 104 in C:\projects\powershell\test\powershell\Modules\Microsoft.PowerShell.Management\Get-Content.Tests.ps1
104: $result.Length | Should Be 2

@mklement0

Copy link
Copy Markdown
Contributor Author

Mike Richmond (@mirichmo): I'll take a look soon. In the meantime, if you have a high-level pointer as to how the platform-specific newline sequence might come into play here (it works in the Unix world, but not on Windows), please let me know.

@iSazonov

Ilya (iSazonov) commented Aug 24, 2017 •

Copy link
Copy Markdown
Collaborator

Michael Klement (@mklement0) Test failed for -Tail parameter. If we use the parameter we call ReadDelimited() twice - (1) to seek start position - backward read, (2) read forward from the start position and parse the file. In the case we can not simply remove the delimiter character from the stream because we use it in SeekItemsBackward() to correct start position. It seems there is still problem places - leave the research to you 😄 Please continue the PR.

Also I see the code is not optimal and we should refactor this in another PR.

@mklement0

Copy link
Copy Markdown
Contributor Author

Thanks for the tips, Ilya (@iSazonov).
I hope to get to this soon (I know, deja vu).

@mklement0

Copy link
Copy Markdown
Contributor Author

Note that the only changes to Get-Content.Tests.ps1 since the original commit were whitespace normalization (conversion to all-spaces, though I now realize that there are some inconsistencies).

Thanks to Ilya (@iSazonov) for pointing me to what I hope is the right fix, which turned out to be simple in the end.

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.

Here we evaluate content.ToString() twice - maybe do this one before block.Add().

@iSazonov

Copy link
Copy Markdown
Collaborator

Michael Klement (@mklement0) Could you please split functional and formatting changes to two commits? This will help us avoid error skipping.
Use soft reset, then git add -p.

@mklement0

Copy link
Copy Markdown
Contributor Author

Ilya (@iSazonov): I've made the changes and split them into 2 commits (functional vs. formatting) that replaced the earlier ones.

I think the Travis CI failure is a transient one, unrelated to my changes (it got stuck while setting up the environment).

Is there a way to re-initiate the test?

@SteveL-MSFT

Copy link
Copy Markdown
Member

Michael Klement (@mklement0) I restarted that job for you

@iSazonov

Ilya (iSazonov) commented Sep 1, 2017 •

Copy link
Copy Markdown
Collaborator

Michael Klement (@mklement0) Tip: You can "rename" last commit to restart CI jobs.

@mklement0

Copy link
Copy Markdown
Contributor Author

Thanks, Ilya (@iSazonov), but how do you rename a commit? Amend the commit message and push again?

@daxian-dbw

Copy link
Copy Markdown
Member

Thanks all! Since we got 2 approvals and Ilya (@iSazonov)'s comments are also addressed, I will rebase and merge this PR soon (in about one hour). Please let me know if there are any concerns.

@daxian-dbw Dongbo Wang (daxian-dbw) added the Breaking-Change breaking change that may affect users label Sep 1, 2017
@daxian-dbw Dongbo Wang (daxian-dbw) changed the title Fix for Get-Content -Delimiter including the delimiter in the array … Fix 'Get-Content -Delimiter' to not include the delimiter in the returned lines Sep 1, 2017
@daxian-dbw
Dongbo Wang (daxian-dbw) merged commit 803395b into PowerShell:master Sep 1, 2017
@mklement0
Michael Klement (mklement0) deleted the get-content-delimiter-fix branch September 1, 2017 20:30
@iSazonov

Copy link
Copy Markdown
Collaborator

Michael Klement (@mklement0) Yes, you can amend or rebase+reword.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking-Change breaking change that may affect users

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants