/ Check-in [74c12dee]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Update the URI filename parser to allow (and ignore) authority names in unix and to pass the authority through to the OS on windows, as this appears to be what web-browsers are doing.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | uri-enhancement
Files: files | file ages | folders
SHA1: 74c12dee1721128f6eb15c4a6a9ca3cf351b76c6
User & Date: drh 2013-07-23 20:54:01
Context
2013-07-23
22:28
Get the new URI logic working for Windows. Closed-Leaf check-in: 0165789f user: drh tags: uri-enhancement
20:54
Update the URI filename parser to allow (and ignore) authority names in unix and to pass the authority through to the OS on windows, as this appears to be what web-browsers are doing. check-in: 74c12dee user: drh tags: uri-enhancement
2013-07-18
20:28
Remove unused "codec" code from the command-line shell. check-in: 37abfe0c user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/main.c.

  2173   2173       ** method that there may be extra parameters following the file-name.  */
  2174   2174       flags |= SQLITE_OPEN_URI;
  2175   2175   
  2176   2176       for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&');
  2177   2177       zFile = sqlite3_malloc(nByte);
  2178   2178       if( !zFile ) return SQLITE_NOMEM;
  2179   2179   
  2180         -    /* Discard the scheme and authority segments of the URI. */
         2180  +    /* URI to filename translations as follows:
         2181  +    **
         2182  +    ** URI                     Unix              Windows
         2183  +    ** ----------------------  ---------------   ----------------
         2184  +    ** file:///xyz             /xyz              /xyz
         2185  +    ** file://abc/xyz          /xyz              //abc/xyz
         2186  +    ** file://localhost/xyz    /xyz              //localhost/xyz
         2187  +    ** file:///c:/xyz          /c:/xyz           c:/xyz
         2188  +    ** file:xyz                xyz               xyz
         2189  +    ** file:/xyz               /xyz              /xyz
         2190  +    ** file:c:/xyz             c:/xyz            c:/xyz
         2191  +    ** file://xyz              //xyz             //xyz
         2192  +    */
         2193  +#if OS_WIN
         2194  +    if( sqlite3_strglob("///[a-zA-Z]:/*", zUrl+5)==0 ){
         2195  +      iIn = 8;
         2196  +    }else
         2197  +#else
  2181   2198       if( zUri[5]=='/' && zUri[6]=='/' ){
  2182   2199         iIn = 7;
  2183   2200         while( zUri[iIn] && zUri[iIn]!='/' ) iIn++;
  2184         -
  2185         -      if( iIn!=7 && (iIn!=16 || memcmp("localhost", &zUri[7], 9)) ){
  2186         -        *pzErrMsg = sqlite3_mprintf("invalid uri authority: %.*s", 
  2187         -            iIn-7, &zUri[7]);
  2188         -        rc = SQLITE_ERROR;
  2189         -        goto parse_uri_out;
  2190         -      }
  2191         -    }else{
         2201  +      if( zUri[iIn]!='/' ) iIn = 5;
         2202  +    }else
         2203  +#endif
         2204  +    {
  2192   2205         iIn = 5;
  2193   2206       }
  2194   2207   
  2195   2208       /* Copy the filename and any query parameters into the zFile buffer. 
  2196   2209       ** Decode %HH escape codes along the way. 
  2197   2210       **
  2198   2211       ** Within this loop, variable eState may be set to 0, 1 or 2, depending

Changes to test/e_uri.test.

   129    129   # "localhost", an error is returned to the caller.
   130    130   #
   131    131   if {$tcl_platform(platform) == "unix"} {
   132    132     set flags [list SQLITE_OPEN_READWRITE SQLITE_OPEN_CREATE SQLITE_OPEN_URI]
   133    133     foreach {tn uri error} "
   134    134       1  {file://localhost[test_pwd /]test.db}   {not an error}
   135    135       2  {file://[test_pwd /]test.db}            {not an error}
   136         -    3  {file://x[test_pwd /]test.db}           {invalid uri authority: x}
   137         -    4  {file://invalid[test_pwd /]test.db}     {invalid uri authority: invalid}
   138    136     " {
   139    137       do_test 2.$tn {
   140    138         set DB [sqlite3_open_v2 $uri $flags ""]
   141    139         set e [sqlite3_errmsg $DB]
   142    140         sqlite3_close $DB
   143    141         set e
   144    142       } $error

Changes to test/uri.test.

   277    277   # Check that only "" and "localhost" are acceptable as authorities.
   278    278   #
   279    279   catch {db close}
   280    280   foreach {tn uri res} {
   281    281     1     "file://localhost/PWD/test.db"   {not an error}
   282    282     2     "file:///PWD/test.db"            {not an error}
   283    283     3     "file:/PWD/test.db"              {not an error}
   284         -  4     "file://l%6Fcalhost/PWD/test.db" {invalid uri authority: l%6Fcalhost}
   285         -  5     "file://lbcalhost/PWD/test.db"   {invalid uri authority: lbcalhost}
   286         -  6     "file://x/PWD/test.db"           {invalid uri authority: x}
   287    284   } {
   288    285   
   289    286     if {$tcl_platform(platform)=="windows"} {
   290    287       set uri  [string map [list PWD [string range [get_pwd] 3 end]] $uri]
   291    288     } else {
   292    289       set uri  [string map [list PWD [string range [get_pwd] 1 end]] $uri]
   293    290     }