X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FUtil%2FStrings.php;h=88dd1d39f81edd151151dac1ba6b7449528dd871;hb=a61ce4fed0eba0c1cee3b96e81be6fa89e96c9f9;hp=3edc9ba90683959fcd685208a62b24b6c18bdfab;hpb=61fe82ad20fa61e441df5a4bf4e9bb2b7f23411a;p=friendica.git diff --git a/src/Util/Strings.php b/src/Util/Strings.php index 3edc9ba906..88dd1d39f8 100644 --- a/src/Util/Strings.php +++ b/src/Util/Strings.php @@ -31,6 +31,18 @@ class Strings return $return; } + /** + * Checks, if the given string is a valid hexadecimal code + * + * @param string $hexCode + * + * @return bool + */ + public static function isHex($hexCode) + { + return !empty($hexCode) ? @preg_match("/^[a-f0-9]{2,}$/i", $hexCode) && !(strlen($hexCode) & 1) : false; + } + /** * @brief This is our primary input filter. * @@ -355,21 +367,40 @@ class Strings */ public static function autoLinkRegEx() { - return '@(?xi) + return '@ (??«»“”‘’.] # Domain can\'t start with a . + [^/\s\xA0`!()\[\]{};:\'",<>?«»“”‘’]+ # Domain can\'t end with a . + \. + [^/\s\xA0`!()\[\]{};:\'".,<>?«»“”‘’]+/? # Followed by a slash ) - (?: # One or more: - [^\s()<>]+ # Run of non-space, non-()<> - | # or - \(([^\s()<>]+|(\([^\s()<>]+\)))*\) # balanced parens, up to 2 levels - | # or - [^\s`!()\[\]{};:\'".,<>?«»“”‘’] # not a space or one of these punct chars + (?: # One or more: + [^\s\xA0()<>]+ # Run of non-space, non-()<> + | # or + \(([^\s\xA0()<>]+|(\([^\s()<>]+\)))*\) # balanced parens, up to 2 levels + | # or + [^\s\xA0`!()\[\]{};:\'".,<>?«»“”‘’] # not a space or one of these punct chars )* -)@'; +)@xiu'; + } + + /** + * Ensures a single path item doesn't contain any path-traversing characters + * + * @see https://stackoverflow.com/a/46097713 + * @param string $pathItem + * @return string + */ + public static function sanitizeFilePathItem($pathItem) + { + $pathItem = str_replace('/', '_', $pathItem); + $pathItem = str_replace('\\', '_', $pathItem); + $pathItem = str_replace(DIRECTORY_SEPARATOR, '_', $pathItem); // In case it does not equal the standard values + + return $pathItem; } }