Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign upFix incorrect name check when autoloading required modules #8218
Conversation
rjmholt
requested review from
BrucePay and
daxian-dbw
as
code owners
Nov 9, 2018
iSazonov
requested review from
adityapatwardhan and
TravisEz13
Nov 9, 2018
iSazonov
assigned
adityapatwardhan
Nov 9, 2018
This comment has been minimized.
This comment has been minimized.
|
Thanks for handling the issue. I'd consider a regression test for this important feature to be essential. |
This comment has been minimized.
This comment has been minimized.
|
Agreed that it's essential -- I'm pretty surprised we didn't have one already. I'm halfway through writing some already. |
rjmholt
added some commits
Nov 9, 2018
rjmholt
force-pushed the
rjmholt:fix-required-module-load-failure
branch
to
ae5c56b
Nov 9, 2018
This comment has been minimized.
This comment has been minimized.
|
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) |
rjmholt
added some commits
Nov 9, 2018
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
@rjmholt 1 new test is failing on Linux and macOS. Please have a look. |
rjmholt
requested a review
from
Francisco-Gamino
as a
code owner
Nov 9, 2018
rjmholt
added some commits
Nov 9, 2018
This comment has been minimized.
This comment has been minimized.
|
The failing AppVeyor test is passing on my machine. Looking into it. |
daxian-dbw
reviewed
Nov 13, 2018
| // 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(); |
This comment has been minimized.
This comment has been minimized.
daxian-dbw
Nov 13, 2018
Member
What's the concern about putting this fix in place? Regression? Perf degradation?
This comment has been minimized.
This comment has been minimized.
rjmholt
Nov 13, 2018
Author
Member
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.
This comment has been minimized.
This comment has been minimized.
daxian-dbw
Nov 13, 2018
Member
Will you open issue to track all those todo comments? They can be easily forgotten :)
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
rjmholt
added some commits
Nov 13, 2018
rjmholt
added some commits
Nov 13, 2018
daxian-dbw
reviewed
Nov 13, 2018
| // 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(); |
This comment has been minimized.
This comment has been minimized.
daxian-dbw
approved these changes
Nov 13, 2018
|
Only pending action item left is to open an issue tracking all "TODO" comments. |
This comment has been minimized.
This comment has been minimized.
|
Since the CodeFactor issues are for existing methods, re-ordering will cause larger diffs. We can ignore CodeFactor issues for this PR. |
rjmholt commentedNov 9, 2018
•
edited
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
ModuleSpecificationcan 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 -Modulesand other cmdlets that can useModuleSpecifications.However, the general pervasive problem is that
ModuleSpecifications 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
ModuleSpecificationtype 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,.ps1and.psm1files 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