/ 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 Unified Diffs Ignore Whitespace Patch

Changes to src/main.c.

2173
2174
2175
2176
2177
2178
2179
2180

















2181
2182
2183
2184
2185
2186
2187
2188
2189
2190

2191


2192
2193
2194
2195
2196
2197
2198
    ** method that there may be extra parameters following the file-name.  */
    flags |= SQLITE_OPEN_URI;

    for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&');
    zFile = sqlite3_malloc(nByte);
    if( !zFile ) return SQLITE_NOMEM;

    /* Discard the scheme and authority segments of the URI. */

















    if( zUri[5]=='/' && zUri[6]=='/' ){
      iIn = 7;
      while( zUri[iIn] && zUri[iIn]!='/' ) iIn++;

      if( iIn!=7 && (iIn!=16 || memcmp("localhost", &zUri[7], 9)) ){
        *pzErrMsg = sqlite3_mprintf("invalid uri authority: %.*s", 
            iIn-7, &zUri[7]);
        rc = SQLITE_ERROR;
        goto parse_uri_out;
      }

    }else{


      iIn = 5;
    }

    /* Copy the filename and any query parameters into the zFile buffer. 
    ** Decode %HH escape codes along the way. 
    **
    ** Within this loop, variable eState may be set to 0, 1 or 2, depending







|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



<
<
<
<
<
<
<
>
|
>
>







2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200







2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
    ** method that there may be extra parameters following the file-name.  */
    flags |= SQLITE_OPEN_URI;

    for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&');
    zFile = sqlite3_malloc(nByte);
    if( !zFile ) return SQLITE_NOMEM;

    /* URI to filename translations as follows:
    **
    ** URI                     Unix              Windows
    ** ----------------------  ---------------   ----------------
    ** file:///xyz             /xyz              /xyz
    ** file://abc/xyz          /xyz              //abc/xyz
    ** file://localhost/xyz    /xyz              //localhost/xyz
    ** file:///c:/xyz          /c:/xyz           c:/xyz
    ** file:xyz                xyz               xyz
    ** file:/xyz               /xyz              /xyz
    ** file:c:/xyz             c:/xyz            c:/xyz
    ** file://xyz              //xyz             //xyz
    */
#if OS_WIN
    if( sqlite3_strglob("///[a-zA-Z]:/*", zUrl+5)==0 ){
      iIn = 8;
    }else
#else
    if( zUri[5]=='/' && zUri[6]=='/' ){
      iIn = 7;
      while( zUri[iIn] && zUri[iIn]!='/' ) iIn++;







      if( zUri[iIn]!='/' ) iIn = 5;
    }else
#endif
    {
      iIn = 5;
    }

    /* Copy the filename and any query parameters into the zFile buffer. 
    ** Decode %HH escape codes along the way. 
    **
    ** Within this loop, variable eState may be set to 0, 1 or 2, depending

Changes to test/e_uri.test.

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







<
<







129
130
131
132
133
134
135


136
137
138
139
140
141
142
# "localhost", an error is returned to the caller.
#
if {$tcl_platform(platform) == "unix"} {
  set flags [list SQLITE_OPEN_READWRITE SQLITE_OPEN_CREATE SQLITE_OPEN_URI]
  foreach {tn uri error} "
    1  {file://localhost[test_pwd /]test.db}   {not an error}
    2  {file://[test_pwd /]test.db}            {not an error}


  " {
    do_test 2.$tn {
      set DB [sqlite3_open_v2 $uri $flags ""]
      set e [sqlite3_errmsg $DB]
      sqlite3_close $DB
      set e
    } $error

Changes to test/uri.test.

277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# Check that only "" and "localhost" are acceptable as authorities.
#
catch {db close}
foreach {tn uri res} {
  1     "file://localhost/PWD/test.db"   {not an error}
  2     "file:///PWD/test.db"            {not an error}
  3     "file:/PWD/test.db"              {not an error}
  4     "file://l%6Fcalhost/PWD/test.db" {invalid uri authority: l%6Fcalhost}
  5     "file://lbcalhost/PWD/test.db"   {invalid uri authority: lbcalhost}
  6     "file://x/PWD/test.db"           {invalid uri authority: x}
} {

  if {$tcl_platform(platform)=="windows"} {
    set uri  [string map [list PWD [string range [get_pwd] 3 end]] $uri]
  } else {
    set uri  [string map [list PWD [string range [get_pwd] 1 end]] $uri]
  }







<
<
<







277
278
279
280
281
282
283



284
285
286
287
288
289
290
# Check that only "" and "localhost" are acceptable as authorities.
#
catch {db close}
foreach {tn uri res} {
  1     "file://localhost/PWD/test.db"   {not an error}
  2     "file:///PWD/test.db"            {not an error}
  3     "file:/PWD/test.db"              {not an error}



} {

  if {$tcl_platform(platform)=="windows"} {
    set uri  [string map [list PWD [string range [get_pwd] 3 end]] $uri]
  } else {
    set uri  [string map [list PWD [string range [get_pwd] 1 end]] $uri]
  }