uri icon indicating copy to clipboard operation
uri copied to clipboard

Windows host handling

Open peterpostmann opened this issue 8 years ago • 5 comments

Hi,

I think a found a bug on windows. For the uri 'file:///C:/path/file_a.ext' parse returns

array (size=2)
  'scheme' => string 'file' (length=4)
  'path' => string 'C:/path/file_a.ext' (length=18)

This causes resolve('file:///C:/path/file_a.ext', 'file_b.ext') to generate wrong URIs: file://C:/path/file_b.ext (one slash is missing, because the empty host is missing).

parse_url produces the same result, which is correct with reagards to http://php.net/manual/en/wrappers.file.php, but it cannot be used to reconstruct file uris directly.

The behavior of _parse_fallback is correct and has this output:

array (size=3)
  'scheme' => string 'file' (length=4)
  'path' => string '/C:/path/file_a.ext' (length=19)
  'host' => string '' (length=0)

parse should also produce this output.

Note: I had to remove the white spaces before and after the regex because I couldn't get it tested otherwise (using PHP 7.1)

peterpostmann avatar Oct 29 '17 17:10 peterpostmann

Hi,

thanks for your feedback. Yes, I think it can be simplified, but it doesn't add a slash to every file uri which doesn't start with a slash: It adds only a slash if it matches \w: lile "C:", etc. I would even expand this to match \w:/ ("C:")

if ( isset($result['scheme']) && $result['scheme']==='file' && 
     isset($result['path']) && preg_match("#^(\w:)\/#", $result['path']) ) {
  $result['path'] = '/' + $result['path'];
  $result['host'] = '';
}

or without regex:

if ( isset($result['scheme']) && $result['scheme']==='file' && 
     isset($result['path']) && ctype_alpha($result['path'][0]) && $result['path'][1] ===':' && $result['path'][2] === '/' ) {
  $result['path'] = '/' + $result['path'];
  $result['host'] = '';
}

Which version do you think is better?

Sorry for the bad comment. I'll be more descriptive when I update the PR.

peterpostmann avatar Oct 29 '17 18:10 peterpostmann

Hi, I just updated the PR with the discussed changes

peterpostmann avatar Nov 05 '17 10:11 peterpostmann

This PR will fix issues https://github.com/sabre-io/uri/issues/31 and https://github.com/sabre-io/uri/issues/32

mlambley avatar Apr 28 '18 06:04 mlambley

Sorry for the slow responses here, but I'm down with merging this once the conflicts are resolved. Sorry for being over a year late, but thank you for making this change.

evert avatar Jul 09 '19 19:07 evert

tried to resolve the merge-conflict... lets see

staabm avatar Jul 10 '19 08:07 staabm

Rebased and adjusted code and merged in PR #71 - thanks @peterpostmann

phil-davis avatar Aug 17 '22 08:08 phil-davis