11package datadog.trace.api.http
22
3+ import java.nio.charset.Charset
34import spock.lang.Specification
45
56class MultipartContentDecoderTest extends Specification {
@@ -13,7 +14,7 @@ class MultipartContentDecoderTest extends Specification {
1314 MultipartContentDecoder . decodeBytes(bytes, bytes. length, ' text/plain; charset=UTF-8' ) == text
1415 }
1516
16- void ' decodeBytes falls back to UTF-8 when Content-Type has no charset' () {
17+ void ' decodeBytes falls back to machine default when Content-Type has no charset' () {
1718 given :
1819 def text = ' hello world'
1920 byte [] bytes = text. getBytes(' UTF-8' )
@@ -22,7 +23,7 @@ class MultipartContentDecoderTest extends Specification {
2223 MultipartContentDecoder . decodeBytes(bytes, bytes. length, ' text/plain' ) == text
2324 }
2425
25- void ' decodeBytes falls back to UTF-8 when Content-Type is null' () {
26+ void ' decodeBytes falls back to machine default when Content-Type is null' () {
2627 given :
2728 def text = ' hello world'
2829 byte [] bytes = text. getBytes(' UTF-8' )
@@ -31,13 +32,13 @@ class MultipartContentDecoderTest extends Specification {
3132 MultipartContentDecoder . decodeBytes(bytes, bytes. length, null ) == text
3233 }
3334
34- void ' decodeBytes falls back to ISO-8859-1 when bytes are invalid for declared charset' () {
35+ void ' decodeBytes falls back to machine default when bytes cannot be decoded with default charset' () {
3536 given :
36- // 0xE9 is 'é' in ISO-8859-1 but an invalid lone UTF-8 byte
3737 byte [] bytes = ' café' . getBytes(' ISO-8859-1' )
38+ String expected = new String (bytes, Charset . defaultCharset())
3839
3940 expect :
40- MultipartContentDecoder . decodeBytes(bytes, bytes. length, null ) == ' café '
41+ MultipartContentDecoder . decodeBytes(bytes, bytes. length, null ) == expected
4142 }
4243
4344 void ' decodeBytes uses declared ISO-8859-1 charset' () {
@@ -62,13 +63,14 @@ class MultipartContentDecoderTest extends Specification {
6263 MultipartContentDecoder . decodeBytes(new byte [16 ], 0 , null ) == ' '
6364 }
6465
65- void ' decodeBytes falls back to ISO-8859-1 when declared charset cannot decode the bytes' () {
66+ void ' decodeBytes falls back to machine default when declared charset cannot decode the bytes' () {
6667 given :
6768 // bytes are ISO-8859-1 encoded but Content-Type explicitly declares UTF-8
6869 byte [] bytes = ' café' . getBytes(' ISO-8859-1' )
70+ String expected = new String (bytes, Charset . defaultCharset())
6971
7072 expect :
71- MultipartContentDecoder . decodeBytes(bytes, bytes. length, ' text/plain; charset=UTF-8' ) == ' café '
73+ MultipartContentDecoder . decodeBytes(bytes, bytes. length, ' text/plain; charset=UTF-8' ) == expected
7274 }
7375
7476 void ' extractCharset returns null for null contentType' () {
0 commit comments