From 7eb7efb737344db1dfe35348586a1a290943a5c2 Mon Sep 17 00:00:00 2001 From: Chris Church Date: Tue, 15 Sep 2015 16:26:15 -0400 Subject: [PATCH] Fix win_lineinfile to pass integration tests when strict mode is enabled. --- lib/ansible/modules/windows/win_lineinfile.ps1 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/windows/win_lineinfile.ps1 b/lib/ansible/modules/windows/win_lineinfile.ps1 index ddf1d4e3000..4ba9086a6e9 100644 --- a/lib/ansible/modules/windows/win_lineinfile.ps1 +++ b/lib/ansible/modules/windows/win_lineinfile.ps1 @@ -387,8 +387,11 @@ Elseif (Test-Path $dest) { $found = $FALSE; Foreach ($encoding in $sortedlist.GetValueList()) { $preamble = $encoding.GetPreamble(); - If ($preamble) { - Foreach ($i in 0..$preamble.Length) { + If ($preamble -and $bom) { + Foreach ($i in 0..($preamble.Length - 1)) { + If ($i -ge $bom.Length) { + break; + } If ($preamble[$i] -ne $bom[$i]) { break; } @@ -427,7 +430,7 @@ If ($state -eq "present") { } Else { - If ($regex -eq $FALSE -and $line -eq $FALSE) { + If ($regexp -eq $FALSE -and $line -eq $FALSE) { Fail-Json (New-Object psobject) "one of line= or regexp= is required with state=absent"; }