@@ -1604,12 +1604,9 @@ public bool GetNamedArgumentAttributeValue(NamedAttributeArgumentAst namedAttrib
1604
1604
1605
1605
public static IEnumerable < string > GetModuleManifestKeys ( Version powershellVersion )
1606
1606
{
1607
- string [ ] keys = new string [ ] { } ;
1607
+ var keys = new List < string > ( ) ;
1608
1608
1609
- // default to version 5.0.10586.494
1610
- if ( powershellVersion == null )
1611
- {
1612
- keys = new string [ ] {
1609
+ var keysCommon = new List < string > {
1613
1610
"RootModule" ,
1614
1611
"ModuleVersion" ,
1615
1612
"GUID" ,
@@ -1633,12 +1630,18 @@ public static IEnumerable<string> GetModuleManifestKeys(Version powershellVersio
1633
1630
"CmdletsToExport" ,
1634
1631
"VariablesToExport" ,
1635
1632
"AliasesToExport" ,
1636
- "DscResourcesToExport" ,
1637
1633
"ModuleList" ,
1638
1634
"FileList" ,
1639
1635
"PrivateData" ,
1640
1636
"HelpInfoURI" ,
1641
1637
"DefaultCommandPrefix" } ;
1638
+
1639
+ keys . AddRange ( keysCommon ) ;
1640
+
1641
+ // default to version 5.0
1642
+ if ( powershellVersion == null || powershellVersion . Equals ( new Version ( "5.0" ) ) )
1643
+ {
1644
+ keys . Add ( "DscResourcesToExport" ) ;
1642
1645
}
1643
1646
return keys ;
1644
1647
}
@@ -1647,11 +1650,23 @@ public static bool IsModuleManifest(string filepath)
1647
1650
{
1648
1651
Token [ ] tokens ;
1649
1652
ParseError [ ] errors ;
1653
+ if ( filepath == null )
1654
+ {
1655
+ throw new ArgumentNullException ( "filepath" ) ;
1656
+ }
1657
+ if ( ! Path . GetExtension ( filepath ) . Equals ( ".psd1" , StringComparison . OrdinalIgnoreCase ) )
1658
+ {
1659
+ return false ;
1660
+ }
1650
1661
1651
1662
//using parsefile causes the parser to crash!
1652
1663
string fileContent = File . ReadAllText ( filepath ) ;
1653
1664
var ast = Parser . ParseInput ( fileContent , out tokens , out errors ) ;
1654
1665
var hast = ast . Find ( x => x is HashtableAst , false ) as HashtableAst ;
1666
+ if ( hast == null )
1667
+ {
1668
+ return false ;
1669
+ }
1655
1670
var keys = GetModuleManifestKeys ( null ) ;
1656
1671
int matchCount = 0 ;
1657
1672
foreach ( var pair in hast . KeyValuePairs )
0 commit comments