Skip to content

Stop globbing of quoted arguments to native commands #5188

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

Merged
merged 2 commits into from
Nov 1, 2017

Conversation

lzybkr
Copy link
Contributor

@lzybkr lzybkr commented Oct 21, 2017

Fix globbing so that quoted args are not expanded.

Also Fix some minor issues with exceptions being raised when resolving
the path - falling back to no glob.

The bulk of the change is in the first commit, which passes the Ast or null instead of the IScriptExtent when constructing the parameters and arguments that are used by the parameter binder.

Fix #3931,#4971

@lzybkr lzybkr self-assigned this Oct 21, 2017
@lzybkr lzybkr force-pushed the glob_fix branch 2 times, most recently from 28e326e to 1534378 Compare October 22, 2017 02:27
@lzybkr lzybkr changed the title Use Ast for context in parameter binding [testing - do not merge] Stop globbing of quoted arguments to native commands Oct 22, 2017
@lzybkr lzybkr force-pushed the glob_fix branch 2 times, most recently from a3613a5 to ad12184 Compare October 27, 2017 18:56
@lzybkr lzybkr assigned daxian-dbw and unassigned lzybkr Oct 27, 2017
@lzybkr
Copy link
Contributor Author

lzybkr commented Oct 27, 2017

@daxian-dbw - I think this is ready for review.

@rkeithhill
Copy link
Collaborator

Must ... have ... this ... fix. :-)

@daxian-dbw
Copy link
Member

@lzybkr I was out in training last Friday. Will get this done today.

foreach (var path in paths)
{
_arguments.Append(sep);
sep = " ";
Copy link
Member

Choose a reason for hiding this comment

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

Is sep = " " really needed here? It seems we just need var sep = " " right before the foreach

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, it's more tidy - it avoids putting 2 spaces between the previous token - either the command name or an argument.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for clarifying #Closed.

Copy link
Member

@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

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

LGTM, but have one more comment about expanding ~.

}
}
}
} while (list != null);
}
else
Copy link
Member

Choose a reason for hiding this comment

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

Now we will expand ~ even if arg is not a bare word. Do we want to expand ~ unconditionally?

Copy link
Member

@daxian-dbw daxian-dbw Oct 31, 2017

Choose a reason for hiding this comment

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

Another question: it seems to me that after this change we don't glob for variables. Is it intentional?
For example, before the change

PS> $var = '*.txt'
PS> /bin/echo $var
a.txt b.txt c.txt

with the change

PS> /bin/echo $var
*.txt

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching, I missed this when reviewing Bruce's changes, but you're right, we don't want to expand ~ unconditionally. I'll fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And I see bash also expands variables unless quoted, so we should probably match that behavior too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@daxian-dbw - updated. If you sign off, I'll merge - I want to squash the last 2 commits and rebase 2 commits instead squashing the 3 commits.

@daxian-dbw daxian-dbw dismissed their stale review October 31, 2017 21:32

Question was answered.

@lzybkr lzybkr force-pushed the glob_fix branch 2 times, most recently from dd4d8ad to 8871dd5 Compare November 1, 2017 02:53
Copy link
Member

@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

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

LGTM. @lzybkr please feel free to merge the PR.

Previously we used IScriptPosition for context (e.g. error reporting)
during parameter binding, but in some cases we want more information, so
we'll use the Ast instead.

This change just adds the Ast, it doesn't make explicit use of it.
Also fix some minor issues with exceptions being raised when resolving
the path - falling back to no glob.

Fix: PowerShell#3931 PowerShell#4971
@vors
Copy link
Collaborator

vors commented Nov 2, 2017

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants