-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Fix parser error for using statements #19134
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
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
What about |
I haven't checked, but I'm fairly certain it's still allowed with this change. While it would certainly be nice if the parser prevented every invalid namespace entry, the main purpose of this change is just to fix the exception thrown when specific characters are used, see: https://github.com/PowerShell/PowerShell/blob/master/src/System.Management.Automation/engine/parser/ast.cs#L8457
|
Although @daxian-dbw pointed out that the first solution is preferable I think full solution should include both since it is impossible to manually check whether a string valid namespace without direct test with the constructor. |
|
@iSazonov Using statements cannot be so strict during parsing because types can be created on the fly like this: I agree that the syntax check itself could be made more thorough, but I don't fully understand the naming rules so it's hard for me to write a regex pattern that I'm confident only blocks invalid values. |
|
@MartinGC94 I mean the checks are performed at different times. |
|
@iSazonov If the intent is just to prevent unintentional exceptions then the current checks should be fine. Invalid namespaces like |
|
You could play with For reference https://www.regular-expressions.info/unicode.html |
|
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) |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
while I agree that this is a problem, I'm concerned about this approach. It seems that the issue is that TypeName newTypeName;
try
{
newTypeName = new TypeName(typeName.Extent, newTypeNameToSearch);
}
catch (Exception e)
{
exception = e;
break;
}this is around line 400 in engine/parser/TypeResolver.cs PS> using namespace [system];[s
ParserError:
Line |
1 | using namespace [system];[s
| ~
| Missing ] at end of attribute or type literal.After more consideration, a |
JamesWTruher
left a comment
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.
please see my comments in the conversation
|
@JamesWTruher I agree that adding |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
Superseded by #21162. @MartinGC94 and @iSazonov Thanks for your initial investigation! I have called out the thanks to both of you in the new PR. |
|
📣 Hey @MartinGC94, how did we do? We would love to hear your feedback with the link below! 🗣️ 🔗 https://aka.ms/PSRepoFeedback |
PR Summary
Fixes a parser error where an invalid namespace would cause the parser to crash when attempting to resolve a type name. For example:
using namespace [System];[SAlso made some adjustments in the completion code so namespace completion continues to work for invalid namespaces.
PR Context
Fixes #17113
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.(which runs in a different PS Host).