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
Validate the value for using namespace
during semantic checks to prevent declaring invalid namespaces
#21162
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
1 similar comment
This comment was marked as outdated.
This comment was marked as outdated.
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.
LGTM.
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) |
📣 Hey @daxian-dbw, how did we do? We would love to hear your feedback with the link below! 🗣️ 🔗 https://aka.ms/PSRepoFeedback |
…event declaring invalid namespaces (PowerShell#21162)
…event declaring invalid namespaces (PowerShell#21162)
PR Summary
Fixes #17113
Validate the value for
using namespace
during semantic checks to prevent declaring invalid namespaces.This PR is to supersede #19134. Thanks @MartinGC94 and @iSazonov for the initial investigation of the regular expression used to validate the namespace values!
I think the right place for doing the check should be in
SemanticChecks
, so that the AST generated fromusing
statement is unchanged, so there is no need to make changes to tab completion code.Parsing error thrown at the semantic check stage
AST is unchanged from the parsing
About @JamesWTruher's concern expressed in #19134 (comment), the relevant code is as follows.
The variable
typeName
is of the typeTypeName
, sotypeName.Name
must be a valid type name. Therefore, as long asns
, the namespace value, is valid, thenewTypeNameToSearch
should be valid. By preventing the declaration of any invalid namespace names, we can guaranteenew TypeName(...)
won't throw here, so I think we don't need to make any changes here.PowerShell/src/System.Management.Automation/engine/parser/TypeResolver.cs
Lines 396 to 399 in 4f02a89
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.