]> gitweb.factorcode.org Git - factor.git/commitdiff
fix bug in base64 -- would fail with bitor trying to OR f with an integer
authorDoug Coleman <erg@jobim.local>
Fri, 10 Apr 2009 00:50:25 +0000 (19:50 -0500)
committerDoug Coleman <erg@jobim.local>
Fri, 10 Apr 2009 00:50:25 +0000 (19:50 -0500)
basis/base64/base64-tests.factor
basis/base64/base64.factor

index ddefff35bb653a57356a502a5d997e4859bdabbc..572d8a5227db00f68e687376b5fa05658f811b21 100644 (file)
@@ -23,5 +23,8 @@ IN: base64.tests
     ascii encode >base64-lines >string
 ] unit-test
 
+[ { 33 52 17 40 12 51 33 43 18 33 23 } base64> ]
+[ malformed-base64? ] must-fail-with
+
 \ >base64 must-infer
 \ base64> must-infer
index c51d871bb5996009d8a3b226c81bc29901b5cef3..111fe49f9567efd0db0ab3b6dddcc2e48b3580da 100644 (file)
@@ -18,6 +18,8 @@ IN: base64
     "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
     nth ; inline
 
+ERROR: malformed-base64 ;
+
 : base64>ch ( ch -- ch )
     {
         f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f
@@ -25,7 +27,7 @@ IN: base64
         f 0 f f f 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
         22 23 24 25 f f f f f f 26 27 28 29 30 31 32 33 34 35 36 37 38 39
         40 41 42 43 44 45 46 47 48 49 50 51
-    } nth ; inline
+    } nth [ malformed-base64 ] unless* ; inline
 
 SYMBOL: column
 
@@ -48,8 +50,6 @@ SYMBOL: column
     [ 3 0 pad-tail binary [ encode3 ] with-byte-writer ]
     [ 1+ ] bi* head-slice 4 CHAR: = pad-tail write-lines ; inline
 
-ERROR: malformed-base64 ;
-
 : decode4 ( seq -- )
     [ 0 [ base64>ch swap 6 shift bitor ] reduce 3 >be ]
     [ [ CHAR: = = ] count ] bi head-slice*