File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed
main/java/at/favre/lib/bytes
test/java/at/favre/lib/bytes Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -74,7 +74,7 @@ public static byte[] decode(String in) {
7474 } else if (c == '\n' || c == '\r' || c == ' ' || c == '\t' ) {
7575 continue ;
7676 } else {
77- return null ;
77+ throw new IllegalArgumentException ( "invalid character to decode: " + c ) ;
7878 }
7979
8080 // Append this char's 6 bits to the word.
Original file line number Diff line number Diff line change @@ -44,6 +44,11 @@ public void parseHex() throws Exception {
4444 assertArrayEquals (defaultArray , Bytes .parseHex (Bytes .parseHex ("A0E1" ).encodeHex ()).array ());
4545 }
4646
47+ @ Test (expected = IllegalArgumentException .class )
48+ public void parseHexInvalid () throws Exception {
49+ Bytes .parseHex ("A0E" );
50+ }
51+
4752 @ Test
4853 public void encodeHex () throws Exception {
4954 byte [] defaultArray = new byte []{(byte ) 0xA0 , (byte ) 0xE1 };
@@ -58,6 +63,11 @@ public void parseBase64() throws Exception {
5863 assertArrayEquals (encodingExample , Bytes .parseBase64 ("SpT9/x6v7Q==" ).array ());
5964 }
6065
66+ @ Test (expected = IllegalArgumentException .class )
67+ public void parseBase64Invalid () throws Exception {
68+ Bytes .parseBase64 ("☕" );
69+ }
70+
6171 @ Test
6272 public void encodeBase64 () throws Exception {
6373 assertEquals ("SpT9/x6v7Q==" , Bytes .from (encodingExample ).encodeBase64 ());
You can’t perform that action at this time.
0 commit comments