Index: src/port1.0/portfetch.tcl
===================================================================
--- src/port1.0/portfetch.tcl	(revision 47668)
+++ src/port1.0/portfetch.tcl	(working copy)
@@ -151,10 +151,9 @@
 # return it.
 proc portfetch::assemble_url {site distfile} {
     if {[string index $site end] != "/"} {
-        return "${site}/${distfile}"
-    } else {
-        return "${site}${distfile}"
+        set site "${site}/"
     }
+    return "${site}[urlencode ${distfile}]"
 }
 
 # XXX
Index: src/port1.0/portutil.tcl
===================================================================
--- src/port1.0/portutil.tcl	(revision 47668)
+++ src/port1.0/portutil.tcl	(working copy)
@@ -2210,3 +2222,30 @@
     return $str
 }
 
+##
+# Percent-encode a string for safe use in a URL
+# This code is from http::mapReply in http.tcl included with Tcl
+#
+# @param string the string to be encoded
+# @return the percent-encoded string
+proc urlencode {string} {
+    global urlencodeMap
+    set excluded -._~a-zA-Z0-9
+    if {![info exists urlencodeMap]} {
+        for {set i 1} {$i <= 256} {incr i} {
+            set c [format %c $i]
+            if {![string match \[$excluded\] $c]} {
+                set urlencodeMap($c) %[format %.2x $i]
+            }
+        }
+        # These are handled specially
+        array set urlencodeMap {
+            " " +   \n %0d%0a
+        }
+    }
+    regsub -all \[^$excluded\] $string {$urlencodeMap(&)} string
+    regsub -all \n $string {\\n} string
+    regsub -all \t $string {\\t} string
+    regsub -all {[][{})\\]\)} $string {\\&} string
+    return [subst $string]
+}

