* Switch to LiteralPath instead of Path. Closes #44508 * add changelog fragment * fix line endings and remove final empty line * Minor text changes in changelog
This commit is contained in:
parent
af49627a08
commit
a7f35e232e
2 changed files with 7 additions and 5 deletions
2
changelogs/fragments/44508-win_lineinfile.yaml
Normal file
2
changelogs/fragments/44508-win_lineinfile.yaml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- win_lineinfile - changed `-Path` to `-LiteralPath` so that square brackes in the path are interpreted literally - https://github.com/ansible/ansible/issues/44508
|
|
@ -82,7 +82,7 @@ function Present($path, $regexp, $line, $insertafter, $insertbefore, $create, $b
|
||||||
|
|
||||||
# Check if path exists. If it does not exist, either create it if create == "yes"
|
# Check if path exists. If it does not exist, either create it if create == "yes"
|
||||||
# was specified or fail with a reasonable error message.
|
# was specified or fail with a reasonable error message.
|
||||||
If (-not (Test-Path -Path $path)) {
|
If (-not (Test-Path -LiteralPath $path)) {
|
||||||
If (-not $create) {
|
If (-not $create) {
|
||||||
Fail-Json @{} "Path $path does not exist !";
|
Fail-Json @{} "Path $path does not exist !";
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,7 @@ function Present($path, $regexp, $line, $insertafter, $insertbefore, $create, $b
|
||||||
function Absent($path, $regexp, $line, $backup, $validate, $encodingobj, $linesep, $check_mode, $diff_support) {
|
function Absent($path, $regexp, $line, $backup, $validate, $encodingobj, $linesep, $check_mode, $diff_support) {
|
||||||
|
|
||||||
# Check if path exists. If it does not exist, fail with a reasonable error message.
|
# Check if path exists. If it does not exist, fail with a reasonable error message.
|
||||||
If (-not (Test-Path -Path $path)) {
|
If (-not (Test-Path -LiteralPath $path)) {
|
||||||
Fail-Json @{} "Path $path does not exist !";
|
Fail-Json @{} "Path $path does not exist !";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,7 +316,7 @@ $encoding = Get-AnsibleParam -obj $params -name "encoding" -type "str" -default
|
||||||
$newline = Get-AnsibleParam -obj $params -name "newline" -type "str" -default "windows" -validateset "unix","windows";
|
$newline = Get-AnsibleParam -obj $params -name "newline" -type "str" -default "windows" -validateset "unix","windows";
|
||||||
|
|
||||||
# Fail if the path is not a file
|
# Fail if the path is not a file
|
||||||
If (Test-Path -Path $path -PathType "container") {
|
If (Test-Path -LiteralPath $path -PathType "container") {
|
||||||
Fail-Json @{} "Path $path is a directory";
|
Fail-Json @{} "Path $path is a directory";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,7 +339,7 @@ If ($encoding -ne "auto") {
|
||||||
# Otherwise see if we can determine the current encoding of the target file.
|
# Otherwise see if we can determine the current encoding of the target file.
|
||||||
# If the file doesn't exist yet (create == 'yes') we use the default or
|
# If the file doesn't exist yet (create == 'yes') we use the default or
|
||||||
# explicitly specified encoding set above.
|
# explicitly specified encoding set above.
|
||||||
ElseIf (Test-Path -Path $path) {
|
ElseIf (Test-Path -LiteralPath $path) {
|
||||||
|
|
||||||
# Get a sorted list of encodings with preambles, longest first
|
# Get a sorted list of encodings with preambles, longest first
|
||||||
$max_preamble_len = 0;
|
$max_preamble_len = 0;
|
||||||
|
@ -356,7 +356,7 @@ ElseIf (Test-Path -Path $path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get the first N bytes from the file, where N is the max preamble length we saw
|
# Get the first N bytes from the file, where N is the max preamble length we saw
|
||||||
[Byte[]]$bom = Get-Content -Encoding Byte -ReadCount $max_preamble_len -TotalCount $max_preamble_len -Path $path;
|
[Byte[]]$bom = Get-Content -Encoding Byte -ReadCount $max_preamble_len -TotalCount $max_preamble_len -LiteralPath $path;
|
||||||
|
|
||||||
# Iterate through the sorted encodings, looking for a full match.
|
# Iterate through the sorted encodings, looking for a full match.
|
||||||
$found = $false;
|
$found = $false;
|
||||||
|
|
Loading…
Reference in a new issue