uri
uri copied to clipboard
Windows host handling
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)
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.
Hi, I just updated the PR with the discussed changes
This PR will fix issues https://github.com/sabre-io/uri/issues/31 and https://github.com/sabre-io/uri/issues/32
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.
tried to resolve the merge-conflict... lets see
Rebased and adjusted code and merged in PR #71 - thanks @peterpostmann