Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Updated CHANGELOG.md
- Renamed NetworkingDSc to NetworkingDsc in CHANGELOG.md - fixes [Issue #513](https://github.com/dsccommunity/NetworkingDsc/issues/513).
- HostsFile
- Fix bad return data when line contains leading spaces - fixes [Issue #526](https://github.com/dsccommunity/NetworkingDsc/issues/526)
- CI Pipeline
- Updated pipeline files to match current DSC Community patterns - fixes [Issue #528](https://github.com/dsccommunity/NetworkingDsc/issues/528).
- Updated HQRM and build steps to use windows-latest image.
Expand Down
2 changes: 1 addition & 1 deletion source/DSCResources/DSC_HostsFile/DSC_HostsFile.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ function Get-HostEntry

foreach ($hosts in $allHosts)
{
$data = $hosts -split '\s+'
$data = $hosts.Trim() -split '\s+'

if ($data.Length -gt 2)
{
Expand Down
24 changes: 24 additions & 0 deletions tests/Unit/DSC_HostsFile.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,30 @@ try
}
}
}

Context 'When a host entry has leading spaces' {

$testParams = @{
HostName = 'www.anotherexample.com'
IPAddress = '127.0.0.1'
Verbose = $true
}

Mock -CommandName Get-Content -MockWith {
return @(
'# A mocked example of a host file - this line is a comment',
'',
'127.0.0.1 localhost',
'# comment',
' 127.0.0.1 www.anotherexample.com',
''
)
}

It 'Should return absent from the get method' {
(Get-TargetResource @testParams).Ensure | Should -Be 'Present'
}
}
} #end InModuleScope $DSCResourceName
}
finally
Expand Down