-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Fix incorrect name check when autoloading required modules #8218
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
Changes from all commits
c6dcb43
4e693d2
ae5c56b
b3c9a87
5c04829
28981df
cea4dd5
b8e513a
8a843ce
fa950a1
2d9cf9c
55f8a7d
d3b9651
980b8f0
0a414ff
9163bc0
59cf3d1
5b4bd92
2915606
be9c5a4
b775900
d786a68
2540605
8170584
226cbdc
bbfaa49
012c4aa
c844113
fc2b46d
5950e75
cbc650e
87a9704
2378bb8
9faf21e
60ece17
c21eb25
336ba07
30c07b8
e381a50
9344345
389b245
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1958,8 +1958,12 @@ internal PSModuleInfo LoadModuleManifest( | |
|
|
||
| foreach (ModuleSpecification requiredModule in requiredModules) | ||
| { | ||
| // The required module name is essentially raw user input. | ||
| // We must process it so paths work. | ||
| ModuleSpecification normalizedRequiredModuleSpec = requiredModule?.WithNormalizedName(Context, moduleBase); | ||
|
|
||
| ErrorRecord error = null; | ||
| PSModuleInfo module = LoadRequiredModule(fakeManifestInfo, requiredModule, moduleManifestPath, | ||
| PSModuleInfo module = LoadRequiredModule(fakeManifestInfo, normalizedRequiredModuleSpec, moduleManifestPath, | ||
| manifestProcessingFlags, containedErrors, out error); | ||
| if (module == null && error != null) | ||
| { | ||
|
|
@@ -4059,10 +4063,17 @@ internal static Collection<PSModuleInfo> GetModuleIfAvailable(ModuleSpecificatio | |
| tempResult = powerShell.Invoke<PSModuleInfo>(); | ||
| } | ||
|
|
||
| // Check if the available module is of the correct version and GUID | ||
| // Check if the available module is of the correct version and GUID. The name is already checked. | ||
| // GH #8204: The required name here may be the full path, while the module name may be just the module, | ||
| // so comparing them may fail incorrectly. | ||
| foreach (var module in tempResult) | ||
| { | ||
| if (ModuleIntrinsics.IsModuleMatchingModuleSpec(module, requiredModule)) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI here is where the problem lay; The fix is to only check against the version and GUID requirements. |
||
| if (ModuleIntrinsics.IsModuleMatchingConstraints( | ||
| module, | ||
| guid: requiredModule.Guid, | ||
| requiredVersion: requiredModule.RequiredVersion, | ||
| minimumVersion: requiredModule.Version, | ||
| maximumVersion: requiredModule.MaximumVersion == null ? null : GetMaximumVersion(requiredModule.MaximumVersion))) | ||
| { | ||
| result.Add(module); | ||
| } | ||
|
|
@@ -4541,6 +4552,11 @@ internal string GetAbsolutePath(string moduleBase, string path) | |
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Check if a path is rooted or "relative rooted". | ||
| /// </summary> | ||
| /// <param name="filePath">The file path to check.</param> | ||
| /// <returns>True if the path is rooted, false otherwise.</returns> | ||
| internal static bool IsRooted(string filePath) | ||
| { | ||
| return (Path.IsPathRooted(filePath) || | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,6 +84,11 @@ protected override void ProcessRecord() | |
|
|
||
| if (FullyQualifiedName != null) | ||
| { | ||
| // TODO: | ||
| // 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(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will you open issue to track all those
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you open an issue to track those todo's?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Next on my list |
||
| foreach (var m in Context.Modules.GetModules(FullyQualifiedName, false)) | ||
| { | ||
| modulesToRemove.Add(m, new List<PSModuleInfo> { m }); | ||
|
|
||
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.
This line here isn't strictly required.
Before my original change, if you specified a required module by absolute path and that module was already loaded, the comparison would still fail but the path would then be passed to
Get-Module -ListAvailableand the result imported.This change and the one in
ModuleIntrinsicsmeans we can make that comparison succeed and prevent needing to runGet-Module -ListAvailable.