Skip to content

Commit ca8d3bb

Browse files
Merge pull request #644 from PowershellFrameworkCollective/development
1.12.346
2 parents 45e704b + aab5bf9 commit ca8d3bb

File tree

8 files changed

+73
-9
lines changed

8 files changed

+73
-9
lines changed

PSFramework/PSFramework.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
RootModule = 'PSFramework.psm1'
55

66
# Version number of this module.
7-
ModuleVersion = '1.12.345'
7+
ModuleVersion = '1.12.346'
88

99
# ID used to uniquely identify this module
1010
GUID = '8028b914-132b-431f-baa9-94a6952f21ff'

PSFramework/bin/PSFramework.dll

0 Bytes
Binary file not shown.

PSFramework/bin/PSFramework.pdb

0 Bytes
Binary file not shown.

PSFramework/bin/PSFramework.xml

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PSFramework/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## 1.12.346 (2024-09-25)
4+
5+
- Fix: MessageLevel Modifiers break Write-PSFMessage
6+
37
## 1.12.345 (2024-09-17)
48

59
> Breaking Change
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Describe "New-PSFMessageLevelModifier Unit Tests" -Tag "CI", "Pipeline", "Unit" {
2+
BeforeAll {
3+
[PSFramework.Message.MessageHost]::MessageLevelModifiers.Clear()
4+
}
5+
AfterAll {
6+
[PSFramework.Message.MessageHost]::MessageLevelModifiers.Clear()
7+
}
8+
It "Should create a new message level modifier without error and as defined" {
9+
{ New-PSFMessageLevelModifier -Name Test -Modifier -3 -IncludeFunctionName Get-Test -IncludeModuleName TestModule -IncludeTags Foo, Bar -EnableException } | Should -Not -Throw
10+
{ Write-PSFMessage -Message Test } | Should -Not -Throw
11+
12+
$modifier = Get-PSFMessageLevelModifier
13+
$modifier.Name | Should -Be 'Test'
14+
$modifier.Modifier | Should -Be -3
15+
$modifier.IncludeFunctionName | Should -Be 'Get-Test'
16+
$modifier.IncludeModuleName | Should -Be TestModule
17+
$modifier.IncludeTags.Count | Should -Be 2
18+
$modifier.IncludeTags | Should -Contain Foo
19+
$modifier.IncludeTags | Should -Contain Bar
20+
}
21+
22+
It "Should apply filters correctly" {
23+
$modifier = Get-PSFMessageLevelModifier
24+
$modifier.AppliesTo("Get-Test","TestModule", @('Foo', 'Test')) | Should -BeTrue
25+
$modifier.AppliesTo("Get-Test","TestModule", @('Test')) | Should -BeFalse
26+
$modifier.AppliesTo("Get-Test","TestModule", @('Bar', 'Test')) | Should -BeTrue
27+
$modifier.AppliesTo("Get-Test2","TestModule", @('Foo', 'Test')) | Should -BeFalse
28+
}
29+
}

library/PSFramework/Message/MessageLevelModifier.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,17 @@ public class MessageLevelModifier
6161
public bool AppliesTo(string FunctionName, string ModuleName, List<string> Tags)
6262
{
6363
// Negatives
64-
if (ExcludeFunctionName.Equals(FunctionName, StringComparison.OrdinalIgnoreCase))
64+
if (!String.IsNullOrEmpty(ExcludeFunctionName) && ExcludeFunctionName.Equals(FunctionName, StringComparison.OrdinalIgnoreCase))
6565
return false;
66-
if (ExcludeModuleName.Equals(ModuleName, StringComparison.OrdinalIgnoreCase))
66+
if (!String.IsNullOrEmpty(ExcludeModuleName) && ExcludeModuleName.Equals(ModuleName, StringComparison.OrdinalIgnoreCase))
6767
return false;
68+
6869
if (Tags != null)
6970
foreach (string tag in ExcludeTags)
70-
foreach (string tag2 in Tags)
71-
if (tag.Equals(tag2, StringComparison.OrdinalIgnoreCase))
72-
return false;
71+
if (!String.IsNullOrEmpty(tag))
72+
foreach (string tag2 in Tags)
73+
if (tag.Equals(tag2, StringComparison.OrdinalIgnoreCase))
74+
return false;
7375

7476
// Positives
7577
if (!String.IsNullOrEmpty(IncludeFunctionName))
@@ -83,9 +85,10 @@ public bool AppliesTo(string FunctionName, string ModuleName, List<string> Tags)
8385
{
8486
if (Tags != null)
8587
foreach (string tag in IncludeTags)
86-
foreach (string tag2 in Tags)
87-
if (tag.Equals(tag2, StringComparison.OrdinalIgnoreCase))
88-
return true;
88+
if (!String.IsNullOrEmpty(tag))
89+
foreach (string tag2 in Tags)
90+
if (tag.Equals(tag2, StringComparison.OrdinalIgnoreCase))
91+
return true;
8992

9093
return false;
9194
}

library/PSFramework/Serialization/SerializationTypeConverter.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,12 @@ public static object GetSerializationData(PSObject psObject)
262262
/// </summary>
263263
public static readonly ConcurrentDictionary<string, bool> AssemblyShortnameMapping = new ConcurrentDictionary<string, bool>(StringComparer.InvariantCultureIgnoreCase);
264264

265+
/// <summary>
266+
/// Converts an object into XML
267+
/// </summary>
268+
/// <param name="Item">The object to serialize</param>
269+
/// <returns>The XML form of the object</returns>
270+
/// <exception cref="ArgumentNullException">$null objects are not accepted</exception>
265271
public static string ConvertToXml(object Item)
266272
{
267273
if (Item == null)
@@ -278,6 +284,12 @@ public static string ConvertToXml(object Item)
278284
return result;
279285
}
280286

287+
/// <summary>
288+
/// Deserializes an XML object back into its object form
289+
/// </summary>
290+
/// <param name="Xml">The XML text to convert</param>
291+
/// <param name="ExpectedType">What type to convert to</param>
292+
/// <returns>The converted object</returns>
281293
public static object ConvertFromXml(string Xml, Type ExpectedType)
282294
{
283295
object result;

0 commit comments

Comments
 (0)