File tree Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -329,6 +329,10 @@ extension Base64 {
329329
330330    @inlinable  
331331    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+ 
332336        let  decoded  =  try   bytes. withContiguousStorageIfAvailable  {  ( input)  ->  [ UInt8 ]  in 
333337            let  outputLength  =  ( ( input. count +  3 )  /  4 )  *  3 
334338
Original file line number Diff line number Diff line change @@ -42,6 +42,12 @@ class ChromiumTests: XCTestCase {
4242        XCTAssertEqual ( decoded? . count,  0 ) 
4343    } 
4444
45+     func  testDecodeEmptyBytes( )  throws  { 
46+         var  decoded :  [ UInt8 ] ? 
47+         XCTAssertNoThrow ( decoded =  try   Base64 . decode ( bytes:  [ ] ) ) 
48+         XCTAssertEqual ( decoded? . count,  0 ) 
49+     } 
50+ 
4551    func  testBase64DecodingArrayOfNulls( )  throws  { 
4652        let  expected  =  Array ( repeating:  UInt8 ( 0 ) ,  count:  10 ) 
4753        var  decoded :  [ UInt8 ] ? 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments