]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/Strings.php
Revert PR 7158 since it breaks umlauts
[friendica.git] / src / Util / Strings.php
index 3edc9ba90683959fcd685208a62b24b6c18bdfab..b2b710d96f2c59ca86e9a545bb342b88849868d7 100644 (file)
@@ -358,18 +358,37 @@ class Strings
                return '@(?xi)
 (?<![=\'\]"/])          # Not preceded by [, =, \', ], ", /
 \b
-(                       # Capture 1: entire matched URL
-  https?://                 # http or https protocol
+(                              # Capture 1: entire matched URL
+  https?://                            # http or https protocol
   (?:
-    [^/.][^/]+[.][^/]+/?    # looks like domain name followed by a slash
+    [^/\s`!()\[\]{};:\'",<>?«»“”‘’.]    # Domain can\'t start with a . 
+    [^/\s`!()\[\]{};:\'",<>?«»“”‘’]+    # Domain can\'t end with a .
+    \.
+    [^/\s`!()\[\]{};:\'".,<>?«»“”‘’]+/? # 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()<>]+                         # 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
   )*
 )@';
        }
+
+       /**
+        * 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;
+       }
 }