Hello!
I'm using league/json-reference library for json validation, and this library uses sabre/uri for resolving external references in json-schema.
Everything works fine on Linux machines, but not on Windows.
For example if function Sabre\Uri\resolve
being called with parameters
$basePath = 'file://D:/development/projects/markirovka/storage/app/jsonSchemas/undefined_order.json';
$newPath = './types/turnover_type.json';
result will be
file://D/development/projects/markirovka/storage/app/jsonSchemas/types/turnover_type.json
The comma after disk partition letter will be missed, and it couse an error.
I've being debugging a bit, and I think it can be fixed with minor changes in lib/functions
.
Function for Windows detection:
/**
* This function returns true if aplication run in Windows environment
* @return bool
*/
function isWindows() {
return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
}
And changes in build function:
function build(array $parts) {
$uri = '';
$authority = '';
if (!empty($parts['host'])) {
$authority = $parts['host'];
if (!empty($parts['user'])) {
$authority = $parts['user'] . '@' . $authority;
}
if (!empty($parts['port'])) {
$authority = $authority . ':' . $parts['port'];
}
}
// ============= add this ===============
/**
* on Windows systems for local URIs $parts['host'] will be a partition letter,
* and we must add colon after it
*/
if (isWindows() && !empty($parts['scheme']) && $parts['scheme'] == 'file') {
$authority .= ':';
}
// ==================================
if (!empty($parts['scheme'])) {
// If there's a scheme, there's also a host.
$uri = $parts['scheme'] . ':';
}
if ($authority || (!empty($parts['scheme']) && $parts['scheme'] === 'file')) {
// No scheme, but there is a host.
$uri .= '//' . $authority;
}
if (!empty($parts['path'])) {
$uri .= $parts['path'];
}
if (!empty($parts['query'])) {
$uri .= '?' . $parts['query'];
}
if (!empty($parts['fragment'])) {
$uri .= '#' . $parts['fragment'];
}
return $uri;
}
What do you think about this suggestion?
And excuse my english, it's not my native language.
question