Skip to content

Commit

Permalink
Merge pull request #719 from fruux/fix-broken-uriencoding
Browse files Browse the repository at this point in the history
Fix broken uriencoding
  • Loading branch information
evert committed Sep 15, 2015
2 parents 8d98bd5 + 03fb8ed commit afb7b9d
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lib/DAV/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,12 @@ function getRequestUri() {
}

/**
* Calculates the uri for a request, making sure that the base uri is stripped out
* Turns a URI such as the REQUEST_URI into a local path.
*
* This method:
* * strips off the base path
* * normalizes the path
* * uri-decodes the path
*
* @param string $uri
* @throws Exception\Forbidden A permission denied exception is thrown whenever there was an attempt to supply a uri outside of the base uri
Expand Down
2 changes: 1 addition & 1 deletion lib/DAV/Xml/Element/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function xmlSerialize(Writer $writer) {
if ($status = $this->getHTTPStatus()) {
$writer->writeElement('{DAV:}status', 'HTTP/1.1 ' . $status . ' ' . \Sabre\HTTP\Response::$statusCodes[$status]);
}
$writer->writeElement('{DAV:}href', $writer->contextUri . $this->getHref());
$writer->writeElement('{DAV:}href', $writer->contextUri . \Sabre\HTTP\encodePath($this->getHref()));
foreach ($this->getResponseProperties() as $status => $properties) {

// Skipping empty lists
Expand Down
2 changes: 1 addition & 1 deletion lib/DAV/Xml/Property/Href.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function xmlSerialize(Writer $writer) {

foreach ($this->getHrefs() as $href) {
if ($this->autoPrefix) {
$href = $writer->contextUri . $href;
$href = $writer->contextUri . \Sabre\HTTP\encodePath($href);
}
$writer->writeElement('{DAV:}href', $href);
}
Expand Down
32 changes: 32 additions & 0 deletions tests/Sabre/DAV/Xml/Element/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,38 @@ function testDeserializeComplexProperty() {

}

/**
* @depends testSimple
*/
function testSerializeUrlencoding() {

$innerProps = [
200 => [
'{DAV:}displayname' => 'my file',
],
];

$property = new Response('space here', $innerProps);

$xml = $this->write(['{DAV:}root' => ['{DAV:}response' => $property]]);

$this->assertXmlStringEqualsXmlString(
'<?xml version="1.0"?>
<d:root xmlns:d="DAV:">
<d:response>
<d:href>/space%20here</d:href>
<d:propstat>
<d:prop>
<d:displayname>my file</d:displayname>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
</d:response>
</d:root>
', $xml);

}

/**
* In the case of {DAV:}prop, a deserializer should never get called, if
* the property element is empty.
Expand Down
15 changes: 15 additions & 0 deletions tests/Sabre/DAV/Xml/Property/HrefTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ function testSerialize() {
$this->assertXmlStringEqualsXmlString(
'<?xml version="1.0"?>
<d:anything xmlns:d="DAV:"><d:href>/bla/path</d:href></d:anything>
', $xml);

}
function testSerializeSpace() {

$href = new Href('path alsopath');
$this->assertEquals('path alsopath', $href->getHref());

$this->contextUri = '/bla/';

$xml = $this->write(['{DAV:}anything' => $href]);

$this->assertXmlStringEqualsXmlString(
'<?xml version="1.0"?>
<d:anything xmlns:d="DAV:"><d:href>/bla/path%20alsopath</d:href></d:anything>
', $xml);

}
Expand Down

0 comments on commit afb7b9d

Please sign in to comment.