]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/Strings.php
Merge pull request #7184 from annando/add-tag
[friendica.git] / src / Util / Strings.php
index d6583b9c61c0eb29993ee350d2eb2683e3592c3a..3f8990d6c124ee268b0de9b10becd1e35adba9d5 100644 (file)
@@ -355,24 +355,40 @@ class Strings
         */
        public static function autoLinkRegEx()
        {
-               return '@(?xi)
+               return '@
 (?<![=\'\]"/])          # Not preceded by [, =, \', ], ", /
 \b
 (                              # Capture 1: entire matched URL
   https?://                            # http or https protocol
   (?:
-    [^/\s`!()\[\]{};:\'",<>?«»“”‘’.]    # Domain can\'t start with a . 
-    [^/\s`!()\[\]{};:\'",<>?«»“”‘’]+    # Domain can\'t end with a .
+    [^/\s\xA0`!()\[\]{};:\'",<>?«»“”‘’.]    # Domain can\'t start with a . 
+    [^/\s\xA0`!()\[\]{};:\'",<>?«»“”‘’]+    # Domain can\'t end with a .
     \.
-    [^/\s`!()\[\]{};:\'".,<>?«»“”‘’]+/? # Followed by a slash
+    [^/\s\xA0`!()\[\]{};:\'".,<>?«»“”‘’]+/? # Followed by a slash
   )
   (?:                                  # One or more:
-    [^\s()<>]+                         # Run of non-space, non-()<>
+    [^\s\xA0()<>]+                         # Run of non-space, non-()<>
     |                                  #   or
-    \(([^\s()<>]+|(\([^\s()<>]+\)))*\) # balanced parens, up to 2 levels
+    \(([^\s\xA0()<>]+|(\([^\s()<>]+\)))*\) # balanced parens, up to 2 levels
     |                                  #   or
-    [^\s`!()\[\]{};:\'".,<>?«»“”‘’]    # not a space or one of these punct chars
+    [^\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;
        }
 }