GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Rework passing array literal to native commands by lzybkr · Pull Request #5301 · PowerShell/PowerShell

Conversation

@lzybkr

@lzybkr Jason Shirk (lzybkr) commented Nov 2, 2017

Copy link
Copy Markdown
Contributor

Now that the Ast is passed through to the NativeCommandParameterBinder, there is a cleaner fix to ensuring we pass the correct text to a command that uses PowerShell array syntax.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@lzybkr
Rework passing array literal to native commands
b58df7d
@lzybkr
Jason Shirk (lzybkr) requested review from Steve Lee (SteveL-MSFT), Dongbo Wang (daxian-dbw) and sergei (vors) November 2, 2017 01:52
@lzybkr
Jason Shirk (lzybkr) requested a review from Bruce Payette (BrucePay) as a code owner November 2, 2017 01:52
vors
sergei (vors) reviewed Nov 2, 2017
View reviewed changes
Comment thread test/powershell/Language/Scripting/NativeExecution/NativeCommandArguments.Tests.ps1 Outdated
}

It "Should handle PowerShell arrays with or without spaces correctly: <arguments>" -TestCases @(
@{arguments = "a 1,2"; expected = "a", "1,2"}

@vors sergei (vors) Nov 2, 2017

Copy link
Copy Markdown
Collaborator

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.

let's add something boring, like a,1,2 here as well

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lzybkr Jason Shirk (lzybkr) Nov 2, 2017

Copy link
Copy Markdown
Contributor Author

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.

There is no difference between 2 and 3 elements - it's just spaces around the argument(s) that matter.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@iSazonov Ilya (iSazonov) Nov 2, 2017

Copy link
Copy Markdown
Collaborator

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.

Should we add 1,2 3?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lzybkr Jason Shirk (lzybkr) Nov 2, 2017

Copy link
Copy Markdown
Contributor Author

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 really didn't need a 1,2, 1,2 would have been sufficient, but I had a bug in the test with array vs. scalar and the first thought I had was to add a to force array. I'm fixing by using @() instead to force array.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
iSazonov
Ilya (iSazonov) reviewed Nov 2, 2017
View reviewed changes

@iSazonov Ilya (iSazonov) left a comment

Copy link
Copy Markdown
Collaborator

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.

Leave a comment

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/System.Management.Automation/engine/NativeCommandParameterBinder.cs
"array argument and ArrayLiteralAst differ in number of elements");

int currentElement = -1;
string separator = "";

@iSazonov Ilya (iSazonov) Nov 2, 2017

Copy link
Copy Markdown
Collaborator

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.

Should we use String.Empty?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lzybkr Jason Shirk (lzybkr) Nov 2, 2017

Copy link
Copy Markdown
Contributor Author

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.

No reason to imo.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/System.Management.Automation/engine/NativeCommandParameterBinder.cs Outdated
var beforeNext = next.Extent.StartOffset - 1;

if (afterPrev == beforeNext)
return ",";

@iSazonov Ilya (iSazonov) Nov 2, 2017

Copy link
Copy Markdown
Collaborator

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.

Could you please use one line formatting as above in line 357?
Below too in 376 and 379.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/powershell/Language/Scripting/NativeExecution/NativeCommandArguments.Tests.ps1 Outdated
}

It "Should handle PowerShell arrays with or without spaces correctly: <arguments>" -TestCases @(
@{arguments = "a 1,2"; expected = "a", "1,2"}

@iSazonov Ilya (iSazonov) Nov 2, 2017

Copy link
Copy Markdown
Collaborator

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.

Should we add 1,2 3?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@lzybkr
Address review feedback
619f8ae
@daxian-dbw Dongbo Wang (daxian-dbw) self-assigned this Nov 6, 2017
daxian-dbw
Dongbo Wang (daxian-dbw) approved these changes Nov 7, 2017
View reviewed changes

@daxian-dbw Dongbo Wang (daxian-dbw) left a comment

Copy link
Copy Markdown
Member

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@daxian-dbw
Dongbo Wang (daxian-dbw) merged commit 8391b9e into PowerShell:master Nov 7, 2017
@dantraMSFT Dan Travison (dantraMSFT) mentioned this pull request Jan 9, 2018
Debug assert "array argument and ArrayLiteralAst differ in number of elements" while running ConsoleHost tests #5733
Closed
@lzybkr
Jason Shirk (lzybkr) deleted the fix_array_native_args branch November 24, 2018 06:39
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
@lzybkr @daxian-dbw
Rework passing array literal to native commands (PowerShell#5301)
4740b38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@iSazonov Ilya (iSazonov) iSazonov left review comments
@daxian-dbw Dongbo Wang (daxian-dbw) daxian-dbw approved these changes
@SteveL-MSFT Steve Lee (SteveL-MSFT) Awaiting requested review from SteveL-MSFT
@BrucePay Bruce Payette (BrucePay) Awaiting requested review from BrucePay
+1 more reviewer
@vors sergei (vors) vors left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@daxian-dbw Dongbo Wang (daxian-dbw)

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@lzybkr @daxian-dbw @vors @iSazonov
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.