diff --git a/changelogs/fragments/win_uri-json.yml b/changelogs/fragments/win_uri-json.yml new file mode 100644 index 00000000000..ef34e7501b8 --- /dev/null +++ b/changelogs/fragments/win_uri-json.yml @@ -0,0 +1,2 @@ +bugfixes: +- win_uri -- Fix support for JSON output when charset is set diff --git a/lib/ansible/modules/windows/win_uri.ps1 b/lib/ansible/modules/windows/win_uri.ps1 index 951cfbd9bfe..78efddb7f02 100644 --- a/lib/ansible/modules/windows/win_uri.ps1 +++ b/lib/ansible/modules/windows/win_uri.ps1 @@ -37,6 +37,8 @@ $validate_certs = Get-AnsibleParam -obj $params -name "validate_certs" -type "bo $client_cert = Get-AnsibleParam -obj $params -name "client_cert" -type "path" $client_cert_password = Get-AnsibleParam -obj $params -name "client_cert_password" -type "str" +$JSON_CANDIDATES = @('text', 'json', 'javascript') + $result = @{ changed = $false url = $url @@ -237,8 +239,12 @@ if ($return_content -or $dest) { $memory_st.Seek(0, [System.IO.SeekOrigin]::Begin) $content_bytes = $memory_st.ToArray() $result.content = [System.Text.Encoding]::UTF8.GetString($content_bytes) - if ($result.ContainsKey("content_type") -and $result.content_type -in @("application/json", "application/javascript")) { - $result.json = ConvertFrom-Json -InputObject $result.content + if ($result.ContainsKey("content_type") -and $result.content_type -Match ($JSON_CANDIDATES -join '|')) { + try { + $result.json = ConvertFrom-Json -InputObject $result.content + } catch [System.ArgumentException] { + # Simply continue, since 'text' might be anything + } } } @@ -251,7 +257,7 @@ if ($return_content -or $dest) { $sp = New-Object -TypeName System.Security.Cryptography.SHA1CryptoServiceProvider $content_checksum = [System.BitConverter]::ToString($sp.ComputeHash($memory_st)).Replace("-", "").ToLower() - + if ($actual_checksum -eq $content_checksum) { $changed = $false } diff --git a/test/sanity/pslint/ignore.txt b/test/sanity/pslint/ignore.txt index 42169167d0e..c74e7375e0b 100644 --- a/test/sanity/pslint/ignore.txt +++ b/test/sanity/pslint/ignore.txt @@ -107,6 +107,7 @@ lib/ansible/modules/windows/win_stat.ps1 PSUseApprovedVerbs lib/ansible/modules/windows/win_unzip.ps1 PSAvoidUsingCmdletAliases lib/ansible/modules/windows/win_unzip.ps1 PSUseApprovedVerbs lib/ansible/modules/windows/win_uri.ps1 PSAvoidUsingConvertToSecureStringWithPlainText +lib/ansible/modules/windows/win_uri.ps1 PSAvoidUsingEmptyCatchBlock lib/ansible/modules/windows/win_user.ps1 PSAvoidUsingCmdletAliases lib/ansible/modules/windows/win_wait_for.ps1 PSAvoidUsingEmptyCatchBlock lib/ansible/modules/windows/win_webpicmd.ps1 PSAvoidUsingInvokeExpression