Tcl Library Source Code

View Ticket
Login
Ticket UUID: 664392
Title: Test failures in uri module for Win32
Type: Bug Version: None
Submitter: patthoyts Created on: 2003-01-08 13:51:40
Subsystem: uri Assigned To: andreas_kupries
Priority: 6 Severity:
Status: Open Last Modified: 2026-11-23 11:06:32
Resolution: None Closed By:
    Closed on:
Description:
The uri package is failing the recent uri::canonicalize
tests under Win32 systems.

The problem is some of the tests are using the file
scheme with a hostname part:
  file://localhost/a/b/c

When using Windows a split and join operation results in
  file://localhost:/a/b/c
due to code in the uri::join for the file scheme.

Common usage under windows is to permit the drive
letter to be used as the host part and we are
supporting this - however, we must also support the RFC
specification too.

We can expect to use  file://c:/autoexec.bat (although
this should strictly be file:///c:/autoexec.bat - thus
using a null host part). Also we must permit
file://localhost/c:/ as this is what the RFC specifies.

Other problems: the path section must be in the URL/URI
style.
% uri::join scheme file path {c:\windows}
file://c:\windows

This _MUST_ be file://c:/windows. Backslashes are
illegal in URLs. This goes for Mac's and VMS too. I
believe that [file normalize] will fix the host's path
into very nearly correct RFC style. Probably just need
some quoting of illegal characters (like space). [file
native] should probably be invoked in the uri::split
function too.
User Comments: serhiy.storchaka added on 2026-11-23 11:06:32:

The canonicalize failures described here are gone since uri 1.2.7 (tcllib 1.19): with the default HostAsDriveLetter 0, file://localhost/a/b/c round-trips on Windows. What remains on trunk: uri::join scheme file path c:\windows gives file:///c:\windows, and on Windows uri::geturl file:///c:/autoexec.bat tries to open /c:/autoexec.bat.

Phil's branch pbrooks-ticket-664392 fixes both; I tested it on Windows with Tcl 8.6 and 9.1 (uri.test passes there, uri-4.1 fails on trunk). Before merging, I suggest:

  • With HostAsDriveLetter 1, geturl now takes the host as a drive letter. file://c:/autoexec.bat is not a valid file URL (the drive letter is not a host), so geturl should not start accepting it; and it breaks valid URLs: file://localhost/c:/x tries localhost:/c:/x and file://foo/bar/baz tries foo:/bar/baz. I suggest leaving HostAsDriveLetter out of geturl (it only affects how join and split handle the host).
  • A file URL is local only if it has no authority, or the authority is localhost (in any case: ABNF strings are case-insensitive) or a fully qualified name of this machine (RFC 8089, 1.1 and 3). Any other host, including an IP address such as 127.0.0.1 (RFC 8089 does not define it as local), is non-local, and geturl must not open the local file for it (RFC 8089, 5), as it does now on trunk and on the branch: file://foo/bar/baz opens /bar/baz. On Windows it is the UNC path //foo/bar/baz (Appendix E.3.1); elsewhere an error. Conversely, join of the path //foo/bar/baz (\\foo\bar\baz on Windows) gives the "traditional" file:////foo/bar/baz (E.3.2); file://foo/bar/baz is the preferred form.
  • geturl now percent-decodes the path, but join does not encode it, so they no longer round-trip (a file named 100%25.txt). join should encode (file:///c:/Program%20Files/...).
  • The drive check ^/[A-Za-z]: on the decoded path also accepts file:///c:foo (drive-relative) and %3A; ^/[A-Za-z]:(/|$) on the undecoded path would be safer.

A side note, not from the branch: a file URL has no port (RFC 8089, 2: file-auth = "localhost" / host), but uri::split file://localhost:80/etc/hosts returns host localhost path :80/etc/hosts instead of an error.

The valid forms for a drive letter are file:///c:/autoexec.bat and file://localhost/c:/autoexec.bat; file:/c:/autoexec.bat is equivalent, but join should produce the three-slash form. The new tests uri-api-7.1..7.3 on branch tests-uri use such URLs; they are knownBug on Windows now and pass with Phil's branch.