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 Index: openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl,v diff -u -r1.195 -r1.196 --- openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl 21 Oct 2024 15:49:22 -0000 1.195 +++ openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl 24 Oct 2024 14:09:09 -0000 1.196 @@ -867,31 +867,10 @@ # is already correctly encoded. # set newQuery [::util::skip_suspicious_query_vars [dict get $parsedURL query]] - set fullQuery [expr {$newQuery eq "" || $export_string eq "" - ? [string cat $newQuery $export_string] - : [string cat $newQuery & $export_string] }] - - set URL {} - if {[dict exists $parsedURL host]} { - set URL \ - [util::join_location \ - {*}[expr {[dict exists $parsedURL proto] ? [list -proto [dict get $parsedURL proto]] : {}}] \ - {*}[expr {[dict exists $parsedURL host] ? [list -hostname [dict get $parsedURL host]] : {}}] \ - {*}[expr {[dict exists $parsedURL port] ? [list -port [dict get $parsedURL port]] : {}}] \ - ] - append URL / - } - if {[dict exists $parsedURL path] && [dict get $parsedURL path] ne ""} { - append URL [dict get $parsedURL path]/ - } - if {[dict exists $parsedURL tail] && [dict get $parsedURL tail] ne ""} { - append URL [dict get $parsedURL tail] - } - - set export_string $URL - if {$fullQuery ne ""} { - append export_string ?$fullQuery - } + dict set parsedURL query [expr {$newQuery eq "" || $export_string eq "" + ? [string cat $newQuery $export_string] + : [string cat $newQuery & $export_string] }] + set export_string [ns_joinurl $parsedURL] } else { # The base has no query vars: encode URL part if not # explicitly said otherwise. Include also as exception