Index: openacs-4/packages/acs-tcl/tcl/00-icanuse-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/00-icanuse-procs.tcl,v diff -u -r1.3 -r1.4 --- openacs-4/packages/acs-tcl/tcl/00-icanuse-procs.tcl 22 Oct 2024 09:37:22 -0000 1.3 +++ openacs-4/packages/acs-tcl/tcl/00-icanuse-procs.tcl 24 Oct 2024 14:09:09 -0000 1.4 @@ -347,6 +347,70 @@ } } +if {[info commands ::ns_joinurl] eq ""} { + + ad_proc ::ns_joinurl {dict} { + Inverse operation of ns_parseurl + + @see ns_parseurl + } { + # + # Inverse operation of ns_parseurl + # + set valid_keys {proto userinfo host port path tail query fragment} + if {!([string is list $dict] && ([llength $dict] & 1) == 0)} { + error "the provided argument is not a dict: $dict" + } + foreach key [dict keys $dict] { + if {$key ni $valid_keys} { + error "the provided dict contains invalid key: $key" + } + } + set URL "" + dict with dict { + if {[info exists host]} { + if {[info exists proto]} { + append URL [expr {$proto ne "" ? "$proto:" : ""}] + } + append URL // + if {[info exists userinfo] && $userinfo ne ""} { + append URL $userinfo @ + } + append URL [expr {[string match *:* $host] ? "\[$host\]" : $host}] + if {[info exists port]} { + append URL : $port + } + } else { + if {[info exists proto]} { + error "key 'proto' (value $proto) was provided without a key 'host'" + } elseif {[info exists userinfo]} { + error "key 'userinfo' (value $userinfo) was provided without a key 'host'" + } elseif {[info exists port]} { + error "key 'port' (value $port) was provided without a key 'host'" + } + } + if {[info exists path]} { + if { $path ne ""} { + append URL / + } + append URL $path / + } + + if {[info exists tail] && $tail ne ""} { + append URL $tail + } + + if {[info exists query] && $query ne ""} { + append URL ? $query + } + if {[info exists fragment] && $fragment ne ""} { + append URL # $fragment + } + } + return $URL + } +} + # Local variables: # mode: tcl # tcl-indent-level: 4