Ticket #18736: urlencode.diff

File urlencode.diff, 1.6 KB (added by ryandesign (Ryan Carsten Schmidt), 16 years ago)
  • src/port1.0/portfetch.tcl

     
    151151# return it.
    152152proc portfetch::assemble_url {site distfile} {
    153153    if {[string index $site end] != "/"} {
    154         return "${site}/${distfile}"
    155     } else {
    156         return "${site}${distfile}"
     154        set site "${site}/"
    157155    }
     156    return "${site}[urlencode ${distfile}]"
    158157}
    159158
    160159# XXX
  • src/port1.0/portutil.tcl

     
    22102222    return $str
    22112223}
    22122224
     2225##
     2226# Percent-encode a string for safe use in a URL
     2227# This code is from http::mapReply in http.tcl included with Tcl
     2228#
     2229# @param string the string to be encoded
     2230# @return the percent-encoded string
     2231proc urlencode {string} {
     2232    global urlencodeMap
     2233    set excluded -._~a-zA-Z0-9
     2234    if {![info exists urlencodeMap]} {
     2235        for {set i 1} {$i <= 256} {incr i} {
     2236            set c [format %c $i]
     2237            if {![string match \[$excluded\] $c]} {
     2238                set urlencodeMap($c) %[format %.2x $i]
     2239            }
     2240        }
     2241        # These are handled specially
     2242        array set urlencodeMap {
     2243            " " +   \n %0d%0a
     2244        }
     2245    }
     2246    regsub -all \[^$excluded\] $string {$urlencodeMap(&)} string
     2247    regsub -all \n $string {\\n} string
     2248    regsub -all \t $string {\\t} string
     2249    regsub -all {[][{})\\]\)} $string {\\&} string
     2250    return [subst $string]
     2251}