Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix completion that relies on pseudobinding in script blocks#25122

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@MartinGC94
Copy link
Contributor

PR Summary

Fixes an issue in the pseudobinding code where a parse exception would prevent the pseudobinding from working when attempting to parse an incomplete script. This would prevent this:& {(New-Guid).<Tab> from working.
It would fail because the script text has errors (due to incomplete input) and the safe value visitor would try to create a scriptblock based on the incomplete text.

PR Context

PR Checklist

@iSazonoviSazonov added the CL-GeneralIndicates that a PR should be marked as a general cmdlet change in the Change Log labelMar 5, 2025
{
try
{
commandName=GetSafeValueVisitor.GetSafeValue(commandAst.CommandElements[0],null,GetSafeValueVisitor.SafeValueContext.ModuleAnalysis)asstring;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please add a code comment to document the scenario, maybe with examples of command names we expect here?

MartinGC94 reacted with thumbs up emoji
@iSazonoviSazonov self-assigned thisMar 5, 2025
stringcommandName=commandAst.GetCommandName();
if(commandNameisnull)
{
// GetCommandName only works if the name is a string constant. GetSafeValueVistor can evaluate some safe dynamic expressions
Copy link
Collaborator

Choose a reason for hiding this comment

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

GetCommandName? Comment for the method says about scripts, modules, aliases. So I'd like to understand what could be going on here.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

GetCommandName is the method that was run on line 280. It failed to get the name because it only handles constants but there's also thisGetSafeValueVisitor that can handle a bit more dynamic expressions but still be safe. When this visitor sees a scriptblock expression, it tries to create a new scriptblock using the text but that fails when there's any parse errors in the script text. This is why:& {(New-Guid).<Tab> fails, but& {(New-Guid).N<Tab> does not, because the N removes the parser error from the missing name after the member access token.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks! I see GetSafeValue() process StringConstantExpressionAst too so we could not call commandAst.GetCommandName(). Perhaps it was added as fast way vs visitor.

@iSazonov

This comment was marked as outdated.

@azure-pipelines

This comment was marked as outdated.

@iSazonoviSazonovenabled auto-merge (squash)March 5, 2025 17:05
@iSazonoviSazonov merged commit650189e intoPowerShell:masterMar 5, 2025
39 of 41 checks passed
@microsoft-github-policy-service
Copy link
Contributor

microsoft-github-policy-servicebot commentedMar 5, 2025
edited by unfurl-linksbot
Loading

📣 Hey@MartinGC94, how did we do? We would love to hear your feedback with the link below! 🗣️

🔗https://aka.ms/PSRepoFeedback

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

Reviewers

@iSazonoviSazonoviSazonov approved these changes

+1 more reviewer

@jborean93jborean93jborean93 approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

@iSazonoviSazonov

Labels

CL-GeneralIndicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@MartinGC94@iSazonov@jborean93

[8]ページ先頭

©2009-2025 Movatter.jp