From 0c47f5a8d426efbe9761021ff8b2cb5b5c29677d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Bechyn=C4=9B?= Date: Fri, 21 Jul 2017 14:49:42 +0200 Subject: [PATCH] RelativePathResolver did not work correctly for ../directories --- src/BeSimple/SoapClient/Xml/Path/RelativePathResolver.php | 8 ++++---- .../SoapClient/Xml/Path/RelativePathResolverTest.php | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/BeSimple/SoapClient/Xml/Path/RelativePathResolver.php b/src/BeSimple/SoapClient/Xml/Path/RelativePathResolver.php index 2417478..7d29221 100644 --- a/src/BeSimple/SoapClient/Xml/Path/RelativePathResolver.php +++ b/src/BeSimple/SoapClient/Xml/Path/RelativePathResolver.php @@ -19,16 +19,16 @@ class RelativePathResolver public function resolveRelativePathInUrl($base, $relative) { $urlParts = parse_url($base); - $isRelativePathAbsolute = 0 === strpos($relative, '/') || 0 === strpos($relative, '..'); + $pathIsSet = true === isset($urlParts['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 /) $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 $path = $urlParts['path'].$relative; - } elseif (isset($urlParts['path'])) { + } elseif (true === $pathIsSet) { // strip filename from base path $path = substr($urlParts['path'], 0, strrpos($urlParts['path'], '/')).'/'.$relative; } else { diff --git a/tests/BeSimple/SoapClient/Xml/Path/RelativePathResolverTest.php b/tests/BeSimple/SoapClient/Xml/Path/RelativePathResolverTest.php index 728554e..07d487b 100644 --- a/tests/BeSimple/SoapClient/Xml/Path/RelativePathResolverTest.php +++ b/tests/BeSimple/SoapClient/Xml/Path/RelativePathResolverTest.php @@ -30,6 +30,11 @@ class RelativePathResolverTest extends PHPUnit_Framework_TestCase public function providePathInfo() { 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/', 'Document1.xsd',