public function testAbsoluteUrlWithSpecialCharacters() { //TODO: i thought the @ made it so everything before is a username... //This is valid $urlStr = "http://localhost/NorthwindService.svc/@/./!/Customers('ALFKI')/Orders?\$filter=OrderID eq 123"; $url = new Url($urlStr); $actual = $url->getSegments(); $expected = array('NorthwindService.svc', '@', '.', '!', "Customers('ALFKI')", "Orders"); $this->assertEquals($expected, $actual); }
/** * Sets the service url from which the OData URL is parsed * * @param string $serviceUri The service url, absolute or relative. * * @return void * * @throws ODataException If the base uri in the configuration is malformed. */ public function setServiceUri($serviceUri) { if (is_null($this->_absoluteServiceUri)) { $isAbsoluteServiceUri = strpos($serviceUri, 'http://') === 0 || strpos($serviceUri, 'https://') === 0; try { $this->_absoluteServiceUri = new Url($serviceUri, $isAbsoluteServiceUri); } catch (UrlFormatException $exception) { throw ODataException::createInternalServerError(Messages::hostMalFormedBaseUriInConfig()); } $segments = $this->_absoluteServiceUri->getSegments(); $lastSegment = $segments[count($segments) - 1]; $endsWithSvc = substr_compare($lastSegment, '.svc', -strlen('.svc'), strlen('.svc')) === 0; if (!$endsWithSvc || !is_null($this->_absoluteServiceUri->getQuery()) || !is_null($this->_absoluteServiceUri->getFragment())) { throw ODataException::createInternalServerError(Messages::hostMalFormedBaseUriInConfig(true)); } if (!$isAbsoluteServiceUri) { $requestUriSegments = $this->_absoluteRequestUri->getSegments(); $i = count($requestUriSegments) - 1; // Find index of segment in the request uri that end with .svc // There will be always a .svc segment in the request uri otherwise // uri redirection will not happen. for (; $i >= 0; $i--) { $endsWithSvc = substr_compare($requestUriSegments[$i], '.svc', -strlen('.svc'), strlen('.svc')) === 0; if ($endsWithSvc) { break; } } $j = count($segments) - 1; $k = $i; if ($j > $i) { throw ODataException::createBadRequestError(Messages::hostRequestUriIsNotBasedOnRelativeUriInConfig($this->_absoluteRequestUriAsString, $serviceUri)); } while ($j >= 0 && $requestUriSegments[$i] === $segments[$j]) { $i--; $j--; } if ($j != -1) { throw ODataException::createBadRequestError(Messages::hostRequestUriIsNotBasedOnRelativeUriInConfig($this->_absoluteRequestUriAsString, $serviceUri)); } $serviceUri = $this->_absoluteRequestUri->getScheme() . '://' . $this->_absoluteRequestUri->getHost() . ':' . $this->_absoluteRequestUri->getPort(); for ($l = 0; $l <= $k; $l++) { $serviceUri .= '/' . $requestUriSegments[$l]; } $this->_absoluteServiceUri = new Url($serviceUri); } $this->_absoluteServiceUriAsString = $serviceUri; } }