Tcl Library Source Code

View Ticket
Login
Ticket UUID: 03f5d49c12913f3952b2b896005b0b0f744463bb
Title: ncgi::redirect uri regexp fix
Type: Patch Version: 1.16
Submitter: anonymous Created on: 2014-06-27 05:37:53
Subsystem: ncgi Assigned To: aku
Priority: 6 Severity: Important
Status: Closed Last Modified: 2014-06-30 17:23:48
Resolution: Fixed Closed By: aku
    Closed on: 2014-06-30 17:23:48
Description:
The regsub that extracts request_uri from env(REQUEST_URI) fails to discard the query string if the query string contains a "/".

e.g. if the current page is "http://foo.com/cgi-bin/view.tcl?path=/a/b/c"
... and we try to do "ncgi::redirect login.tcl"
we end up at "http://foo.com/cgi-bin/view.tcl?path=/a/b/login.tcl"

with the patch we get to "http://foo.com/cgi-bin/login.tcl"

Why use custom regular expressions in ncgi when we have uri::split?

--- ncgi.tcl.orig	2014-06-27 15:16:58.000000000 +1000
+++ ncgi.tcl	2014-06-27 15:24:37.000000000 +1000
@@ -28,6 +28,7 @@
 # We use newer string routines
 package require Tcl 8.4
 package require fileutil ; # Required by importFile.
+package require uri

 package provide ncgi 1.4.2

@@ -728,7 +729,7 @@

 	if {[info exists env(REQUEST_URI)]} {
 	    # Not all servers have the leading protocol spec
-	    regsub -- {^https?://[^/]*/} $env(REQUEST_URI) / request_uri
+        set request_uri /[dict get [uri::split $env(REQUEST_URI)] path]
 	} elseif {[info exists env(SCRIPT_NAME)]} {
 	    set request_uri $env(SCRIPT_NAME)
 	} else {
User Comments: aku added on 2014-06-30 17:23:48:
Accepted the patch, with slight modifications.
- Replaced (dict get) with array commands.
- Keeps the package at needing Tcl 8.4+, instead of bumping it to require Tcl 8.5+

Fixed in revision [9f2e9488eb].
Committed.
Pushed.

Thank you.

aku added on 2014-06-27 06:17:59:
> Why use custom regular expressions in ncgi when we have uri::split?

IIRC "ncgi" existed before "uri" was written.