-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Add validation to $PSStyle
to reject printable text as ANSI escape sequence
#15825
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
e4cd752
to
253a8a2
Compare
253a8a2
to
5a5c0ee
Compare
src/System.Management.Automation/FormatAndOutput/common/PSStyle.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/FormatAndOutput/common/PSStyle.cs
Outdated
Show resolved
Hide resolved
The static analysis is unrelated to this PR, looks like CI picked up the changelog from preview 8 release bug not the spelling updates |
src/System.Management.Automation/FormatAndOutput/common/PSStyle.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/FormatAndOutput/common/PSStyle.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/FormatAndOutput/common/PSStyle.cs
Outdated
Show resolved
Hide resolved
fa396a2
to
a671e7b
Compare
src/System.Management.Automation/FormatAndOutput/common/PSStyle.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/FormatAndOutput/common/PSStyle.cs
Outdated
Show resolved
Hide resolved
7e1b694
to
8ea054d
Compare
src/System.Management.Automation/FormatAndOutput/common/PSStyle.cs
Outdated
Show resolved
Hide resolved
@@ -516,6 +684,17 @@ private PSStyle() | |||
FileInfo = new FileInfoFormatting(); | |||
} | |||
|
|||
private static string ValidateNoContent(string text) |
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.
"Validate" assumes a return true/false. Perhaps NormalizeContent is better name. The same for ValidateExtension.
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.
Normalize doesn't indicate it'll throw if the data isn't right.
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.
It is not strong rule. If it is important we could name the method as NormalizeContentOrThrow.
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 think previously where I added the period if it was missing, then Normalize
would make sense but since it's only checking if the period is there, it seems to me validate is more accurate than normalize. Perhaps we need another opinion here, @rjmholt ?
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.
Validate
sounds more like an assertion that throws than a boolean to me — I think it fits here.
If it returned a boolean, I'd expect a predicate phrase like IsContentFree()
or ContainsNoContent()
.
src/System.Management.Automation/FormatAndOutput/common/PSStyle.cs
Outdated
Show resolved
Hide resolved
/azp run |
Azure Pipelines successfully started running 5 pipeline(s). |
🎉 Handy links: |
🎉 Handy links: |
PR Summary
Currently, if you set custom formatting like
$PSStyle.Formatting.Error
and include printable characters (that is text other than an ANSI escape sequence), this can mess up the formatting which expects the formatting string to not take up any buffercells. The change is to add validation that the set text is only decoration and does not include characters that would print on screen as plain text.Also added validation to
Add()
andRemove()
to require period prefix which is used during formatting.Also fixed an error in the formatting which incorrectly prefixed
Verbose
asFormatting.Verbose
in the output.PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.(which runs in a different PS Host).