mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 13:20:23 -07:00
Fix support for JSON output when charset is set (#44762)
* Fix support for JSON output when charset is set This fixes #41797 * Add specific exception to catch * Add Changelog fragment
This commit is contained in:
parent
8979af45a5
commit
5e814d8d17
3 changed files with 12 additions and 3 deletions
2
changelogs/fragments/win_uri-json.yml
Normal file
2
changelogs/fragments/win_uri-json.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- 'win_uri: Fix support for JSON output when charset is set'
|
|
@ -36,6 +36,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 = Get-AnsibleParam -obj $params -name "client_cert" -type "path"
|
||||||
$client_cert_password = Get-AnsibleParam -obj $params -name "client_cert_password" -type "str"
|
$client_cert_password = Get-AnsibleParam -obj $params -name "client_cert_password" -type "str"
|
||||||
|
|
||||||
|
$JSON_CANDIDATES = @('text', 'json', 'javascript')
|
||||||
|
|
||||||
$result = @{
|
$result = @{
|
||||||
changed = $false
|
changed = $false
|
||||||
url = $url
|
url = $url
|
||||||
|
@ -232,8 +234,12 @@ if ($return_content -or $dest) {
|
||||||
$memory_st.Seek(0, [System.IO.SeekOrigin]::Begin)
|
$memory_st.Seek(0, [System.IO.SeekOrigin]::Begin)
|
||||||
$content_bytes = $memory_st.ToArray()
|
$content_bytes = $memory_st.ToArray()
|
||||||
$result.content = [System.Text.Encoding]::UTF8.GetString($content_bytes)
|
$result.content = [System.Text.Encoding]::UTF8.GetString($content_bytes)
|
||||||
if ($result.ContainsKey("content_type") -and $result.content_type -in @("application/json", "application/javascript")) {
|
if ($result.ContainsKey("content_type") -and $result.content_type -Match ($JSON_CANDIDATES -join '|')) {
|
||||||
$result.json = ConvertFrom-Json -InputObject $result.content
|
try {
|
||||||
|
$result.json = ConvertFrom-Json -InputObject $result.content
|
||||||
|
} catch [System.ArgumentException] {
|
||||||
|
# Simply continue, since 'text' might be anything
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,7 +252,7 @@ if ($return_content -or $dest) {
|
||||||
|
|
||||||
$sp = New-Object -TypeName System.Security.Cryptography.SHA1CryptoServiceProvider
|
$sp = New-Object -TypeName System.Security.Cryptography.SHA1CryptoServiceProvider
|
||||||
$content_checksum = [System.BitConverter]::ToString($sp.ComputeHash($memory_st)).Replace("-", "").ToLower()
|
$content_checksum = [System.BitConverter]::ToString($sp.ComputeHash($memory_st)).Replace("-", "").ToLower()
|
||||||
|
|
||||||
if ($actual_checksum -eq $content_checksum) {
|
if ($actual_checksum -eq $content_checksum) {
|
||||||
$changed = $false
|
$changed = $false
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,6 +99,7 @@ lib/ansible/modules/windows/win_stat.ps1 PSUseApprovedVerbs
|
||||||
lib/ansible/modules/windows/win_unzip.ps1 PSAvoidUsingCmdletAliases
|
lib/ansible/modules/windows/win_unzip.ps1 PSAvoidUsingCmdletAliases
|
||||||
lib/ansible/modules/windows/win_unzip.ps1 PSUseApprovedVerbs
|
lib/ansible/modules/windows/win_unzip.ps1 PSUseApprovedVerbs
|
||||||
lib/ansible/modules/windows/win_uri.ps1 PSAvoidUsingConvertToSecureStringWithPlainText
|
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_user.ps1 PSAvoidUsingCmdletAliases
|
||||||
lib/ansible/modules/windows/win_wait_for.ps1 PSAvoidUsingEmptyCatchBlock
|
lib/ansible/modules/windows/win_wait_for.ps1 PSAvoidUsingEmptyCatchBlock
|
||||||
lib/ansible/modules/windows/win_webpicmd.ps1 PSAvoidUsingInvokeExpression
|
lib/ansible/modules/windows/win_webpicmd.ps1 PSAvoidUsingInvokeExpression
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue