-
Notifications
You must be signed in to change notification settings - Fork 7.2k
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
Fix incorrect name check when autoloading required modules #8218
Fix incorrect name check when autoloading required modules #8218
Conversation
Thanks for handling the issue. I'd consider a regression test for this important feature to be essential. |
Agreed that it's essential -- I'm pretty surprised we didn't have one already. I'm halfway through writing some already. |
3205e0d
to
ae5c56b
Compare
Ok, feel free to add the test in a 2nd PR as I can understand that this is a time-pressing issue that can initially be verified with some manual testing (please include Windows as test platform though) |
We also seem to do required module autoloading in PowerShell/src/System.Management.Automation/engine/CommandDiscovery.cs Lines 307 to 313 in 4118fd2
If those are supposed to allow paths, I'll need to do the same path normalisation logic there. |
@rjmholt 1 new test is failing on Linux and macOS. Please have a look. |
src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs
Outdated
Show resolved
Hide resolved
The failing AppVeyor test is passing on my machine. Looking into it. |
src/System.Management.Automation/engine/Modules/GetModuleCommand.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs
Outdated
Show resolved
Hide resolved
// Paths in the module name may fail here because | ||
// they the wrong directory separator or are relative. | ||
// Fix with the code below: | ||
// FullyQualifiedName = FullyQualifiedName.Select(ms => ms.WithNormalizedName(Context, SessionState.Path.CurrentLocation.Path)).ToArray(); |
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.
What's the concern about putting this fix in place? Regression? Perf degradation?
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.
Just keeping the fix constrained in this PR. It shouldn't cause regressions or perf degradations, but to ensure there are no regressions (since this PR is a regression fix itself) I just left it as 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.
Will you open issue to track all those todo
comments? They can be easily forgotten :)
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.
Did you open an issue to track those todo's?
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.
Next on my list
src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs
Outdated
Show resolved
Hide resolved
// Paths in the module name may fail here because | ||
// they the wrong directory separator or are relative. | ||
// Fix with the code below: | ||
// FullyQualifiedName = FullyQualifiedName.Select(ms => ms.WithNormalizedName(Context, SessionState.Path.CurrentLocation.Path)).ToArray(); |
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.
Did you open an issue to track those todo's?
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.
Only pending action item left is to open an issue tracking all "TODO" comments.
Since the CodeFactor issues are for existing methods, re-ordering will cause larger diffs. We can ignore CodeFactor issues for this PR. |
PR Summary
Fixes #8204.
The change I made in #7125 made the check too strict on the module we try to autoload it from requires and rejected it based on name.
This PR removes that name check but also sets up a fix for the more general problem that a
ModuleSpecification
can always specify a path rather than a name. I added some reusable logic to make this easier to service.The main contribution is regression testing for
RequiredModules
,#requires -Modules
and other cmdlets that can useModuleSpecification
s.However, the general pervasive problem is that
ModuleSpecification
s contain raw user input and we don't do very much about handling paths that might be given as module names, namely:.
and..
The methods I've added deal with these and I've applied them in one place to help correct the immediate problem and make it more efficient.
But the fact remains that we have no way in the type system to identify when this resolution has already occurred; there are over 120 uses of the
ModuleSpecification
type in the code base, and we don't have a way to differentiate when they contain raw user input and when they can be trusted to have a canonical path. The way the module cmdlets are written currently, we redo a fair amount of this validation and normalisation logic, and it's probably somewhere we could find serious perf improvements.PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
to the beginning of the title and remove the prefix when the PR is ready.[feature]
if the change is significant or affects feature tests