[feature] Make UTF-8 Default Encoding for application/json (#6109)

When a charset is not supplied for a JSON response, the default encoding should be UTF-8 per RFC 8259. This commit changes the default charset to UTF-8 for JSON responses when a charset is not defined.
This commit is contained in:
Mark Kraus authored and Ilya committed 2018-02-22 09:31:00 +04:00
1 parent f906e9ddba
commit c6cd66bca8
3 files changed
+42

No files matched your search

@@ -992,6 +992,22 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" {
$response.Output.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName
$response.Output | Should BeOfType 'Microsoft.PowerShell.Commands.BasicHtmlWebResponseObject'
}
It "Verifies Invoke-WebRequest defaults to UTF8 on application/json when no charset is present" {
# when contenttype is set, WebListener suppresses charset unless it is included in the query
$query = @{
contenttype = 'application/json'
body = '{"Test": "Test"}'
}
$uri = Get-WebListenerUrl -Test 'Response' -Query $query
$expectedEncoding = [System.Text.Encoding]::UTF8
$response = ExecuteWebRequest -Uri $uri -UseBasicParsing
$response.Error | Should BeNullOrEmpty
$response.Output.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName
$response.Output | Should BeOfType 'Microsoft.PowerShell.Commands.BasicHtmlWebResponseObject'
$response.Output.Content | Should BeExactly $query.body
}
}
#endregion charset encoding tests
@@ -2302,6 +2318,21 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" {
$response.Error | Should BeNullOrEmpty
$response.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName
}
It "Verifies Invoke-RestMethod defaults to UTF8 on application/json when no charset is present" {
# when contenttype is set, WebListener suppresses charset unless it is included in the query
$query = @{
contenttype = 'application/json'
body = '{"Test": "Test"}'
}
$uri = Get-WebListenerUrl -Test 'Response' -Query $query
$expectedEncoding = [System.Text.Encoding]::UTF8
$response = ExecuteRestMethod -Uri $uri -UseBasicParsing
$response.Error | Should BeNullOrEmpty
$response.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName
$response.output.Test | Should BeExactly 'Test'
}
}
#endregion charset encoding tests