Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix support for JSON output when charset is set #44762

Merged
merged 3 commits into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/win_uri-json.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- 'win_uri: Fix support for JSON output when charset is set'
12 changes: 9 additions & 3 deletions lib/ansible/modules/windows/win_uri.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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_password = Get-AnsibleParam -obj $params -name "client_cert_password" -type "str"

$JSON_CANDIDATES = @('text', 'json', 'javascript')

$result = @{
changed = $false
url = $url
Expand Down Expand Up @@ -232,8 +234,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
}
}
}

Expand All @@ -246,7 +252,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
}
Expand Down
1 change: 1 addition & 0 deletions test/sanity/pslint/ignore.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 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
Expand Down