8000 Fixing bug #2607 related to ModuleSpec syntax in RequiredModules by anmenaga · Pull Request #3594 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Fixing bug #2607 related to ModuleSpec syntax in RequiredModules #3594

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

Conversation

anmenaga
Copy link

This fixes issue #2607.
'RequiredModules' is a field in module manifest that can reference other modules using ModuleSpecification format.
The basic version of this format (just module name) was working fine, however there was a problem when more detailed version of the format was used (the one that uses module versions or/and GUIDs).
During module import, there is a check for cyclic references through 'RequiredModules' field. The bug was in this check for cyclic references , related to comparison rules for ModuleSpecification objects - as a result code was incorrectly reporting 'cyclic reference' error in cases when there was none.

Added tests for different ModuleSpecification formats and a test for error when there is actually a cyclic reference.

Test results before the fix:
requiredmodulefix_before

Test results after the fix:
requiredmodulefix_after

@@ -4104,10 +4104,11 @@ internal PSModuleInfo LoadRequiredModule(PSModuleInfo currentModule, ModuleSpeci
if (currentModule != null)
{
requiredModules.Add(new ModuleSpecification(currentModule), new List<ModuleSpecification> { requiredModuleSpecification });
requiredModules.Add(requiredModuleSpecification, new List<ModuleSpecification> ( requiredModuleInfo.RequiredModulesSpecification ));
Copy link
Contributor

Choose a reason for hiding this comment

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

does requiredModuleSpecification only needs to be added when currentModule is not null?
this is confusing here. if so, please add comment explains why

Copy link
Author

Choose a reason for hiding this comment

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

Originally I was thinking that both addition should be bundled together; but thinking more about it - it is better to move the new addition to its own 'if' check. Updated.


try
{
Import-Module $lastModule -ErrorAction Stop
Copy link
Contributor

Choose a reason for hiding this comment

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

please also check that the module is actually loaded.

Copy link
Author

Choose a reason for hiding this comment

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

Good point; updated.

@anmenaga anmenaga force-pushed the FixedModuleSpecSyntaxInRequiredModules branch from 5fc877d to bad1221 Compare April 28, 2017 17:57
@chunqingchen 8000
Copy link
Contributor

good to sign off

@daxian-dbw daxian-dbw merged commit c0aafdb into PowerShell:master May 1, 2017
@anmenaga anmenaga deleted the FixedModuleSpecSyntaxInRequiredModules branch October 31, 2018 21:20
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
0