Skip to content

Commit 21b3820

Browse files
committed
test(appsec): add missing corner cases to MultipartContentDecoderTest
1 parent 4738eed commit 21b3820

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

internal-api/src/test/groovy/datadog/trace/api/http/MultipartContentDecoderTest.groovy

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,30 @@ class MultipartContentDecoderTest extends Specification {
5757
MultipartContentDecoder.decodeBytes(bytes, 5, null) == 'hello'
5858
}
5959

60+
void 'decodeBytes returns empty string for zero length'() {
61+
expect:
62+
MultipartContentDecoder.decodeBytes(new byte[16], 0, null) == ''
63+
}
64+
65+
void 'decodeBytes falls back to ISO-8859-1 when declared charset cannot decode the bytes'() {
66+
given:
67+
// bytes are ISO-8859-1 encoded but Content-Type explicitly declares UTF-8
68+
byte[] bytes = 'café'.getBytes('ISO-8859-1')
69+
70+
expect:
71+
MultipartContentDecoder.decodeBytes(bytes, bytes.length, 'text/plain; charset=UTF-8') == 'café'
72+
}
73+
6074
void 'extractCharset returns null for null contentType'() {
6175
expect:
6276
MultipartContentDecoder.extractCharset(null) == null
6377
}
6478

79+
void 'extractCharset returns null for empty contentType'() {
80+
expect:
81+
MultipartContentDecoder.extractCharset('') == null
82+
}
83+
6584
void 'extractCharset returns null for contentType without charset'() {
6685
expect:
6786
MultipartContentDecoder.extractCharset('text/plain') == null
@@ -86,4 +105,9 @@ class MultipartContentDecoderTest extends Specification {
86105
MultipartContentDecoder.extractCharset('text/plain; charset=UTF-8').name() == 'UTF-8'
87106
MultipartContentDecoder.extractCharset('text/xml; charset=ISO-8859-1').name() == 'ISO-8859-1'
88107
}
108+
109+
void 'extractCharset extracts charset when followed by additional parameters'() {
110+
expect:
111+
MultipartContentDecoder.extractCharset('text/plain; charset=UTF-8; boundary=something').name() == 'UTF-8'
112+
}
89113
}

0 commit comments

Comments
 (0)