-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Fix unnecessary trimming of line resulting in incorrect indexi… #11670
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
Conversation
replace `n with [environment]::newline remove extra newline
...stem.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs
Show resolved
Hide resolved
...stem.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs
Show resolved
Hide resolved
...stem.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs
Show resolved
Hide resolved
|
We have many issues with these helper functions. Maybe put them in a temp module? This can simplify debugging and fixing. |
|
@iSazonov which helpers are you referring to? The tests don't really have any helpers? |
|
@SteveL-MSFT I mean the formatting functions like Show-Error and Get-ConciseViewPositionMessage. |
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.
All this code seems pretty fragile and relies on the format of the error message which could change at any time. There's not much we can do about other that to rethink the whole error presentation which is probably not something we should entertain at the moment.
|
@iSazonov In 7.1, we'll have appropriate APIs for coloring/VT100, we can consider some refactoring then vs making a big change now |
|
🎉 Handy links: |
PR Summary
After the switch to use
InvocationInfo.PositionMessageinstead of crafting equivalent, the use ofTrim()caused a mismatch between the line of script with the error and the underlining line so the line of code to insert VT100 color can be out of bounds. The whitespace at the beginning of the line causes this issue becauseTrim()makes the highlight line too short (previously the script line would also be trimmed).Also fixed an issue where it was splitting
PositionMessageby+to get the individual parts, but the message itself can contain a+so using newline instead. This with the trim is what caused the index to be out of bounds as the line is now too short to insert the VT100 code to reset the color back.In addition, switched all use of
`nto[Environment]::Newline.Finally, removed an extra newline in the rendering.
PR Context
Fix #11669
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.