Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ entries are carried over from the manifest's release notes.

### Fixed

- A version in an assignment filter with a part too large for a 64-bit number, such as
`10.0.99999999999999999999`, is not a version that `Test-IntuneAssignmentFilter` can order, so
`-gt`, `-ge`, `-lt` and `-le` on it do not match. It ended the command with a conversion

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Nit (optional): the entry gets the old behaviour wrong. The cast error didn't end the command. It ended only the foreach statement, the missing parts were filled with zeros, and the command went on with a wrong verdict. I measured on main: Test-IntuneAssignmentFilter -Rule '(device.operatingSystemVersion -ge "10.0.99999999999999999999")' -Device @{ operatingSystemVersion = '10.0.22631' } writes one InvalidCastFromStringToInteger error and returns Matched = True, because the rule's version was read as 10.0.0.0. The wrong match is what a user would act on, so it belongs in the entry. Fix: say something like "It was read as 10.0 with the rest of the version dropped, so the clause could match, and a conversion error was written."

error (#106).
- A `Severity` setting that is not a hashtable, such as `Severity = 'Error'` in a settings file
or in `-Settings`, ends `Test-IntuneScript` with `SettingsInvalid` and a message that names the
source. It ended with a strict-mode error, `PropertyNotFoundStrict`, that named neither the
Expand Down
12 changes: 10 additions & 2 deletions Private/Get-IslVersionPart.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ function Get-IslVersionPart {
.DESCRIPTION
A text of one to four numbers separated by dots, with white space around it allowed, gives
four numbers, the parts that are missing as 0: '10.0.26100' gives 10, 0, 26100, 0. Any other
text is not a version, and gives nothing.
text is not a version, and gives nothing; so does a text with a part too large for a 64-bit
number, which has no order the comparison could use.

.PARAMETER Text
The text to read.
Expand Down Expand Up @@ -34,7 +35,14 @@ function Get-IslVersionPart {
return
}
$parts = [System.Collections.Generic.List[long]]::new()
foreach ($part in ($Text.Trim() -split '\.')) { $parts.Add([long]$part) }
foreach ($part in ($Text.Trim() -split '\.')) {
$number = [long]0
$style = [System.Globalization.NumberStyles]::None
if (-not [long]::TryParse($part, $style, [cultureinfo]::InvariantCulture, [ref]$number)) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Nit (optional): the regex above checks with \d, which in .NET matches any Unicode decimal digit, for example '١٠.0' (Arabic-Indic digits). TryParse reads only ASCII digits, so such a text now gives nothing. That is the right result, but it is reached by accident and no case pins it. Fix: write the pattern with [0-9] so that it says what it accepts, or add '١٠.0' to the "gives nothing" cases.

return
}
$parts.Add($number)
}
while ($parts.Count -lt 4) { $parts.Add(0) }
$parts.ToArray()
}
2 changes: 2 additions & 0 deletions Tests/Unit/Private/Get-IslVersionPart.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Describe 'Get-IslVersionPart' -Tag 'Unit', 'Private' {
@{ Text = '10'; Expected = @(10, 0, 0, 0) }
@{ Text = '10.0.26100'; Expected = @(10, 0, 26100, 0) }
@{ Text = '10.0.26100.4202'; Expected = @(10, 0, 26100, 4202) }
@{ Text = '9223372036854775807'; Expected = @([long]::MaxValue, 0, 0, 0) }
@{ Text = ' 6.3 '; Expected = @(6, 3, 0, 0) }
) {
$parts = Get-Part -Text $Text
Expand All @@ -38,6 +39,7 @@ Describe 'Get-IslVersionPart' -Tag 'Unit', 'Private' {
@{ Text = '1.2.3.4.5' }
@{ Text = '10.0.' }
@{ Text = '-1.0' }
@{ Text = '10.0.99999999999999999999' }
) {
Get-Part -Text $Text | Should-BeCollection @()
}
Expand Down
10 changes: 10 additions & 0 deletions Tests/Unit/Public/Test-IntuneAssignmentFilter.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@ Describe 'Test-IntuneAssignmentFilter' -Tag 'Unit', 'Public' {
$unequal.Matched | Should-BeTrue
}

It 'treats a version with a part too large for a 64-bit number as never ordered' {
$device = @{ operatingSystemVersion = '10.0.22631' }
$rule = '(device.operatingSystemVersion -ge "10.0.99999999999999999999")'
$inRule = Test-IntuneAssignmentFilter -Rule $rule -Device $device
$inRule.Matched | Should-BeFalse
$huge = @{ operatingSystemVersion = '10.0.99999999999999999999' }
$onDevice = Test-IntuneAssignmentFilter -Rule '(device.operatingSystemVersion -lt 10.0)' -Device $huge
$onDevice.Matched | Should-BeFalse
}

It 'validates the syntax without a device on request' {
$result = Test-IntuneAssignmentFilter -Rule '(device.cpuArchitecture -eq "x64")' -SyntaxOnly 3>$null
$result.Matched | Should-BeNull
Expand Down