Tk Library Source Code

Artifact [496285c7c9]
Login

Artifact 496285c7c9f5212c58d054efcf4386058cd087ec:

Attachment "base64.tcl.patch" to ticket [1869943fff] added by billiob 2008-01-12 21:06:09.
--- base64.tcl	2007/07/29 16:21:31
+++ base64.tcl	2008/01/12 00:00:22
@@ -280,6 +280,8 @@
 	binary scan $string c* X
 	
 	set output ""
+
+	set nums ""
 	
 	foreach x $X {
 	    set bits [lindex $base64 $x]
@@ -298,17 +300,20 @@
 		# padding characters.  If x=={}, we have 12 bits of input 
 		# (enough for 1 8-bit output).  If x!={}, we have 18 bits of
 		# input (enough for 2 8-bit outputs).
-		
-		foreach {v w z} $nums break
-		set a [expr {($v << 2) | (($w & 0x30) >> 4)}]
-		
-		if {$z == {}} {
-		    append output [binary format c $a ]
-		} else {
-		    set b [expr {(($w & 0xF) << 4) | (($z & 0x3C) >> 2)}]
-		    append output [binary format cc $a $b]
-		}		
-		break
+		# if string is just characters nor part of the Base64 alphabet + '='
+		# then nums is still "".
+		if { $nums != ""} { 
+			foreach {v w z} $nums break
+			set a [expr {($v << 2) | (($w & 0x30) >> 4)}]
+			
+			if {$z == {}} {
+				append output [binary format c $a ]
+			} else {
+				set b [expr {(($w & 0xF) << 4) | (($z & 0x3C) >> 2)}]
+				append output [binary format cc $a $b]
+			}		
+			break
+		}
 	    } else {
 		# RFC 2045 says that line breaks and other characters not part
 		# of the Base64 alphabet must be ignored, and that the decoder