@@ -801,6 +801,29 @@ public void DecodingLessThan4BytesWithWhiteSpaces(byte[] utf8Bytes, byte decoded
801
801
Assert . Equal ( decoded , utf8Bytes [ 0 ] ) ;
802
802
}
803
803
804
+ [ Theory ]
805
+ [ InlineData ( new char [ ] { '\r ' , '\r ' , '-' , '-' } , 251 ) ]
806
+ [ InlineData ( new char [ ] { '\r ' , '_' , '\r ' , '-' } , 255 ) ]
807
+ [ InlineData ( new char [ ] { '_' , '_' , '\r ' , '\r ' } , 255 ) ]
808
+ [ InlineData ( new char [ ] { 'p' , '\r ' , 'a' , '\r ' } , 165 ) ]
809
+ [ InlineData ( new char [ ] { '\r ' , 'p' , '\r ' , 'a' , '\r ' } , 165 ) ]
810
+ [ InlineData ( new char [ ] { 'p' , '\r ' , 'a' , '\r ' , '=' , '=' } , 165 ) ]
811
+ public void DecodingLessThan4CharsWithWhiteSpaces ( char [ ] utf8Bytes , byte decoded )
812
+ {
813
+ Assert . True ( Base64Url . IsValid ( utf8Bytes , out int decodedLength ) ) ;
814
+ Assert . Equal ( 1 , decodedLength ) ;
815
+ Span < byte > decodedSpan = new byte [ decodedLength ] ;
816
+ OperationStatus status = Base64Url . DecodeFromChars ( utf8Bytes , decodedSpan , out int bytesRead , out int bytesDecoded ) ;
817
+ Assert . Equal ( OperationStatus . Done , status ) ;
818
+ Assert . Equal ( utf8Bytes . Length , bytesRead ) ;
819
+ Assert . Equal ( decodedLength , bytesDecoded ) ;
820
+ Assert . Equal ( decoded , decodedSpan [ 0 ] ) ;
821
+ decodedSpan . Clear ( ) ;
822
+ Assert . True ( Base64Url . TryDecodeFromChars ( utf8Bytes , decodedSpan , out bytesDecoded ) ) ;
823
+ Assert . Equal ( decodedLength , bytesDecoded ) ;
824
+ Assert . Equal ( decoded , decodedSpan [ 0 ] ) ;
825
+ }
826
+
804
827
[ Theory ]
805
828
[ InlineData ( new byte [ ] { 0x4a , 0x74 , 0xa , 0x4a , 0x4a , 0x74 , 0xa , 0x4a } , new byte [ ] { 38 , 210 , 73 , 180 } ) ]
806
829
[ InlineData ( new byte [ ] { 0xa , 0x2d , 0x56 , 0xa , 0xa , 0xa , 0x2d , 0x4a , 0x4a , 0x4a , } , new byte [ ] { 249 , 95 , 137 , 36 } ) ]
@@ -823,6 +846,25 @@ public void DecodingNotMultipleOf4WithWhiteSpace(byte[] utf8Bytes, byte[] decode
823
846
Assert . True ( utf8Bytes . AsSpan ( ) . Slice ( 0 , bytesDecoded ) . SequenceEqual ( decoded ) ) ;
824
847
}
825
848
849
+ [ Theory ]
850
+ [ InlineData ( new char [ ] { 'J' , 't' , '\r ' , 'J' , 'J' , 't' , '\r ' , 'J' } , new byte [ ] { 38 , 210 , 73 , 180 } ) ]
851
+ [ InlineData ( new char [ ] { '\r ' , '-' , 'V' , '\r ' , '\r ' , '\r ' , '-' , 'J' , 'J' , 'J' , } , new byte [ ] { 249 , 95 , 137 , 36 } ) ]
852
+ public void DecodingNotMultipleOf4CharsWithWhiteSpace ( char [ ] utf8Bytes , byte [ ] decoded )
853
+ {
854
+ Assert . True ( Base64Url . IsValid ( utf8Bytes , out int decodedLength ) ) ;
855
+ Assert . Equal ( 4 , decodedLength ) ;
856
+ Span < byte > decodedSpan = new byte [ decodedLength ] ;
857
+ OperationStatus status = Base64Url . DecodeFromChars ( utf8Bytes , decodedSpan , out int bytesRead , out int bytesDecoded ) ;
858
+ Assert . Equal ( OperationStatus . Done , status ) ;
859
+ Assert . Equal ( utf8Bytes . Length , bytesRead ) ;
860
+ Assert . Equal ( decodedLength , bytesDecoded ) ;
861
+ Assert . True ( decodedSpan . SequenceEqual ( decoded ) ) ;
862
+ decodedSpan . Clear ( ) ;
863
+ Assert . True ( Base64Url . TryDecodeFromChars ( utf8Bytes , decodedSpan , out bytesDecoded ) ) ;
864
+ Assert . Equal ( decodedLength , bytesDecoded ) ;
865
+ Assert . True ( decodedSpan . SequenceEqual ( decoded ) ) ;
866
+ }
867
+
826
868
[ Theory ]
827
869
[ MemberData ( nameof ( BasicDecodingWithExtraWhitespaceShouldBeCountedInConsumedBytes_MemberData ) ) ]
828
870
public void BasicDecodingWithExtraWhitespaceShouldBeCountedInConsumedBytes ( string inputString , int expectedConsumed , int expectedWritten )
0 commit comments