Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/Runtime/Paths/ServiceOperationPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,33 @@ function ($key, $value) {

private static function escapeValue($value)
{
if (is_string($value))
if (is_string($value)) {
/**
* Given value that is a path, like `/sites/Site/O'Reilly`, needs to be enclosed within quotes:
* ```
* GET https://{site_url}/_api/web/GetFolderByServerRelativeUrl('/sites/Site/O'Reilly')/Files
* ```
* because the quote within the name of the folder `O'Reilly` is messing up where the argument ends,
* it needs to be escaped, like so:
* ```
* GET https://{site_url}/_api/web/GetFolderByServerRelativeUrl('/sites/Site/O''Reilly')/Files
* ```
* before sending it to the API.
*
*
* `rawurlencode`ing it doesn't solve the issue, the URL is decoded before it is evaluated by the API it seems.
*
*
* Sources:
* - https://sharepoint.stackexchange.com/questions/154590/getfilebyserverrelativeurl-fails-when-the-filename-contains-a-quote
* - https://web.archive.org/web/20230325070719/http://www.sharepointnadeem.com/2012/06/special-characters-in-rest-query-filter.html
*/
$value = str_replace('%27', '%27%27', $value);
$value = str_replace("'", "''", $value);
$value = "'" . $value . "'";
elseif (is_bool($value))
} elseif (is_bool($value)) {
$value = var_export($value, true);
}
return $value;
}

Expand Down