File tree 2 files changed +10
-0
lines changed
2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -329,6 +329,10 @@ extension Base64 {
329
329
330
330
@inlinable
331
331
public static func decode< Buffer: Collection > ( bytes: Buffer , options: DecodingOptions = [ ] ) throws -> [ UInt8 ] where Buffer. Element == UInt8 {
332
+ guard bytes. count > 0 else {
333
+ return [ ]
334
+ }
335
+
332
336
let decoded = try bytes. withContiguousStorageIfAvailable { ( input) -> [ UInt8 ] in
333
337
let outputLength = ( ( input. count + 3 ) / 4 ) * 3
334
338
Original file line number Diff line number Diff line change @@ -42,6 +42,12 @@ class ChromiumTests: XCTestCase {
42
42
XCTAssertEqual ( decoded? . count, 0 )
43
43
}
44
44
45
+ func testDecodeEmptyBytes( ) throws {
46
+ var decoded : [ UInt8 ] ?
47
+ XCTAssertNoThrow ( decoded = try Base64 . decode ( bytes: [ ] ) )
48
+ XCTAssertEqual ( decoded? . count, 0 )
49
+ }
50
+
45
51
func testBase64DecodingArrayOfNulls( ) throws {
46
52
let expected = Array ( repeating: UInt8 ( 0 ) , count: 10 )
47
53
var decoded : [ UInt8 ] ?
You can’t perform that action at this time.
0 commit comments