Skip to content

Commit efdb418

Browse files
committed
Fix extra_capabilities not being split and trim comma-separated lists
extra_capabilities was passed to Add-CapabilitiesToImage as a single raw string instead of an array, so DISM received one bogus /CapabilityName:"A,B" argument and failed (e.g. OpenSSH.Server,OpenSSH.Client on Windows Server 2025). Add a ConvertFrom-CommaSeparatedString helper that splits on commas, trims whitespace around each entry and drops empty entries, and use it for extra_features, extra_packages and extra_capabilities. This also fixes whitespace-padded values (e.g. "A, B") that previously broke DISM, and tolerates trailing commas. Add unit tests for the new helper. Closes: #422
1 parent 342c678 commit efdb418

2 files changed

Lines changed: 46 additions & 3 deletions

File tree

Tests/WinImageBuilder.Tests.ps1

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,33 @@ Describe "Test New-WindowsOnlineImage" {
249249

250250
Remove-Item -Force -ErrorAction SilentlyContinue "${fakeConfigPath}.offline"
251251
}
252+
253+
Describe "Test ConvertFrom-CommaSeparatedString" {
254+
InModuleScope $moduleName {
255+
It "splits comma separated values into separate entries" {
256+
$result = @(ConvertFrom-CommaSeparatedString "OpenSSH.Server,OpenSSH.Client")
257+
$result.Count | Should -Be 2
258+
$result[0] | Should -Be "OpenSSH.Server"
259+
$result[1] | Should -Be "OpenSSH.Client"
260+
}
261+
It "trims whitespace around each entry" {
262+
$result = @(ConvertFrom-CommaSeparatedString "Microsoft-Hyper-V, Microsoft-Hyper-V-Management-Clients")
263+
$result[0] | Should -Be "Microsoft-Hyper-V"
264+
$result[1] | Should -Be "Microsoft-Hyper-V-Management-Clients"
265+
}
266+
It "drops empty entries produced by a trailing comma" {
267+
$result = @(ConvertFrom-CommaSeparatedString "OpenSSH.Server,")
268+
$result.Count | Should -Be 1
269+
$result[0] | Should -Be "OpenSSH.Server"
270+
}
271+
It "returns an empty array for an empty value" {
272+
$result = @(ConvertFrom-CommaSeparatedString "")
273+
$result.Count | Should -Be 0
274+
}
275+
It "returns a single entry for a value without commas" {
276+
$result = @(ConvertFrom-CommaSeparatedString "OpenSSH.Server")
277+
$result.Count | Should -Be 1
278+
$result[0] | Should -Be "OpenSSH.Server"
279+
}
280+
}
281+
}

WinImageBuilder.psm1

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,19 @@ function Add-PackageToImage {
668668
}
669669
}
670670

671+
function ConvertFrom-CommaSeparatedString {
672+
# Splits a comma separated config value into a clean array, trimming whitespace
673+
# around each entry and dropping empty entries (e.g. from a trailing comma).
674+
Param(
675+
[Parameter(Mandatory=$false)]
676+
[string]$Value
677+
)
678+
if (!$Value) {
679+
return @()
680+
}
681+
return @($Value.Split(",") | ForEach-Object { $_.Trim() } | Where-Object { $_ })
682+
}
683+
671684
function Enable-FeaturesInImage {
672685
Param(
673686
[Parameter(Mandatory=$true)]
@@ -1737,15 +1750,15 @@ function New-WindowsCloudImage {
17371750
-driversBasePath $windowsImageConfig.virtio_base_path
17381751
}
17391752
if ($windowsImageConfig.extra_features) {
1740-
Enable-FeaturesInImage $winImagePath $windowsImageConfig.extra_features.split(",")
1753+
Enable-FeaturesInImage $winImagePath (ConvertFrom-CommaSeparatedString $windowsImageConfig.extra_features)
17411754
}
17421755
if ($windowsImageConfig.extra_packages) {
1743-
foreach ($package in $windowsImageConfig.extra_packages.split(",")) {
1756+
foreach ($package in (ConvertFrom-CommaSeparatedString $windowsImageConfig.extra_packages)) {
17441757
Add-PackageToImage $winImagePath $package -ignoreErrors $windowsImageConfig.extra_packages_ignore_errors
17451758
}
17461759
}
17471760
if ($windowsImageConfig.extra_capabilities) {
1748-
Add-CapabilitiesToImage $winImagePath $windowsImageConfig.extra_capabilities
1761+
Add-CapabilitiesToImage $winImagePath (ConvertFrom-CommaSeparatedString $windowsImageConfig.extra_capabilities)
17491762
}
17501763
if ($windowsImageConfig.clean_updates_offline) {
17511764
Clean-WindowsUpdates $winImagePath -PurgeUpdates $windowsImageConfig.purge_updates

0 commit comments

Comments
 (0)