RelativePathResolver did not work correctly for ../directories
This commit is contained in:
parent
75a0489cce
commit
0c47f5a8d4
|
@ -19,16 +19,16 @@ class RelativePathResolver
|
||||||
public function resolveRelativePathInUrl($base, $relative)
|
public function resolveRelativePathInUrl($base, $relative)
|
||||||
{
|
{
|
||||||
$urlParts = parse_url($base);
|
$urlParts = parse_url($base);
|
||||||
$isRelativePathAbsolute = 0 === strpos($relative, '/') || 0 === strpos($relative, '..');
|
$pathIsSet = true === isset($urlParts['path']);
|
||||||
|
|
||||||
// combine base path with relative path
|
// combine base path with relative path
|
||||||
if (isset($urlParts['path']) && mb_strlen($relative) > 0 && $isRelativePathAbsolute) {
|
if (true === $pathIsSet && 0 < mb_strlen($relative) && 0 === strpos($relative, '/')) {
|
||||||
// $relative is absolute path from domain (starts with /)
|
// $relative is absolute path from domain (starts with /)
|
||||||
$path = $relative;
|
$path = $relative;
|
||||||
} elseif (isset($urlParts['path']) && strrpos($urlParts['path'], '/') === (strlen($urlParts['path']) )) {
|
} elseif (true === $pathIsSet && strrpos($urlParts['path'], '/') === strlen($urlParts['path'])) {
|
||||||
// base path is directory
|
// base path is directory
|
||||||
$path = $urlParts['path'].$relative;
|
$path = $urlParts['path'].$relative;
|
||||||
} elseif (isset($urlParts['path'])) {
|
} elseif (true === $pathIsSet) {
|
||||||
// strip filename from base path
|
// strip filename from base path
|
||||||
$path = substr($urlParts['path'], 0, strrpos($urlParts['path'], '/')).'/'.$relative;
|
$path = substr($urlParts['path'], 0, strrpos($urlParts['path'], '/')).'/'.$relative;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -30,6 +30,11 @@ class RelativePathResolverTest extends PHPUnit_Framework_TestCase
|
||||||
public function providePathInfo()
|
public function providePathInfo()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
[
|
||||||
|
'http://anyendpoint.tld:9999/path/to/endpoint.wsdl',
|
||||||
|
'../Schemas/Common/SoapHeader.xsd',
|
||||||
|
'http://anyendpoint.tld:9999/path/Schemas/Common/SoapHeader.xsd',
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'http://endpoint-location.ltd/',
|
'http://endpoint-location.ltd/',
|
||||||
'Document1.xsd',
|
'Document1.xsd',
|
||||||
|
|
Loading…
Reference in New Issue