Changeset View
Changeset View
Standalone View
Standalone View
src/utils/utils.php
Show First 20 Lines • Show All 1,881 Lines • ▼ Show 20 Lines | |||||
* In this case, any '/' characters in the string will not be escaped, so you | * In this case, any '/' characters in the string will not be escaped, so you | ||||
* will not be able to distinguish between the string and the suffix (unless | * will not be able to distinguish between the string and the suffix (unless | ||||
* you have more information, like you know the format of the suffix). For infix | * you have more information, like you know the format of the suffix). For infix | ||||
* URI components, use @{function:phutil_escape_uri_path_component} instead. | * URI components, use @{function:phutil_escape_uri_path_component} instead. | ||||
* | * | ||||
* @param string Some string. | * @param string Some string. | ||||
* @return string URI encoded string, except for '/'. | * @return string URI encoded string, except for '/'. | ||||
*/ | */ | ||||
function phutil_escape_uri($string) { | function phutil_escape_uri($string) { | ||||
if ($string === null) { | |||||
return ''; | |||||
} | |||||
return str_replace('%2F', '/', rawurlencode($string)); | return str_replace('%2F', '/', rawurlencode($string)); | ||||
} | } | ||||
valerio.bozzolan: Since this is a low-level function it's probably better to just check the exact `null` value… | |||||
/** | /** | ||||
* Escape text for inclusion as an infix URI substring. See discussion at | * Escape text for inclusion as an infix URI substring. See discussion at | ||||
* @{function:phutil_escape_uri}. This function covers an unusual special case; | * @{function:phutil_escape_uri}. This function covers an unusual special case; | ||||
* @{function:phutil_escape_uri} is usually the correct function to use. | * @{function:phutil_escape_uri} is usually the correct function to use. | ||||
* | * | ||||
* This function will escape a string into a format which is safe to put into | * This function will escape a string into a format which is safe to put into | ||||
▲ Show 20 Lines • Show All 321 Lines • Show Last 20 Lines |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0
Since this is a low-level function it's probably better to just check the exact null value and exclude that.
Also, since this function always returned a string, it's probably better to just return a string.