original_string: public static function validatePath($path, $normalizeOnly = false)
      {
          $path = str_replace('\\', '/', $path);
          $path = '/'.trim($path, '/');
  
          if ($normalizeOnly) {
              return $path;
          }
  
          /*
           * Validate folder names
           */
          $regexWhitelist = [
              '\w', // any word character
              preg_quote('@', '/'),
              preg_quote('.', '/'),
              '\s', // whitespace character
              preg_quote('-', '/'),
              preg_quote('_', '/'),
              preg_quote('/', '/'),
              preg_quote('(', '/'),
              preg_quote(')', '/'),
              preg_quote('[', '/'),
              preg_quote(']', '/'),
              preg_quote(',', '/'),
              preg_quote('=', '/'),
          ];
  
          if (!preg_match('/^[' . implode('', $regexWhitelist) . ']+$/iu', $path)) {
              throw new ApplicationException(Lang::get('system::lang.media.invalid_path', compact('path')));
          }
  
          $regexDirectorySeparator = preg_quote('/', '#');
          $regexDot = preg_quote('.', '#');
          $regex = [
              // Beginning of path
              '(^'.$regexDot.'+?'.$regexDirectorySeparator.')',
  
              // Middle of path
              '('.$regexDirectorySeparator.$regexDot.'+?'.$regexDirectorySeparator.')',
  
              // End of path
              '('.$regexDirectorySeparator.$regexDot.'+?$)',
          ];
  
          /*
           * Validate invalid paths
           */
          $regex = '#'.implode('|', $regex).'#';
          if (preg_match($regex, $path) !== 0 || strpos($path, '//') !== false) {
              throw new ApplicationException(Lang::get('system::lang.media.invalid_path', compact('path')));
          }
  
          return $path;
      }
code: public static function validatePath($path, $normalizeOnly = false)
      {
          $path = str_replace('\\', '/', $path);
          $path = '/'.trim($path, '/');
  
          if ($normalizeOnly) {
              return $path;
          }
  
          /*
           * Validate folder names
           */
          $regexWhitelist = [
              '\w', // any word character
              preg_quote('@', '/'),
              preg_quote('.', '/'),
              '\s', // whitespace character
              preg_quote('-', '/'),
              preg_quote('_', '/'),
              preg_quote('/', '/'),
              preg_quote('(', '/'),
              preg_quote(')', '/'),
              preg_quote('[', '/'),
              preg_quote(']', '/'),
              preg_quote(',', '/'),
              preg_quote('=', '/'),
          ];
  
          if (!preg_match('/^[' . implode('', $regexWhitelist) . ']+$/iu', $path)) {
              throw new ApplicationException(Lang::get('system::lang.media.invalid_path', compact('path')));
          }
  
          $regexDirectorySeparator = preg_quote('/', '#');
          $regexDot = preg_quote('.', '#');
          $regex = [
              // Beginning of path
              '(^'.$regexDot.'+?'.$regexDirectorySeparator.')',
  
              // Middle of path
              '('.$regexDirectorySeparator.$regexDot.'+?'.$regexDirectorySeparator.')',
  
              // End of path
              '('.$regexDirectorySeparator.$regexDot.'+?$)',
          ];
  
          /*
           * Validate invalid paths
           */
          $regex = '#'.implode('|', $regex).'#';
          if (preg_match($regex, $path) !== 0 || strpos($path, '//') !== false) {
              throw new ApplicationException(Lang::get('system::lang.media.invalid_path', compact('path')));
          }
  
          return $path;
      }
code_tokens: public static function validatePath ( $ path , $ normalizeOnly = false ) { $ path = str_replace ( '\\' , '/' , $ path ) ; $ path = '/' . trim ( $ path , '/' ) ; if ( $ normalizeOnly ) { return $ path ; } /*
           * Validate folder names
           */ $ regexWhitelist = [ '\w' , // any word character preg_quote ( '@' , '/' ) , preg_quote ( '.' , '/' ) , '\s' , // whitespace character preg_quote ( '-' , '/' ) , preg_quote ( '_' , '/' ) , preg_quote ( '/' , '/' ) , preg_quote ( '(' , '/' ) , preg_quote ( ')' , '/' ) , preg_quote ( '[' , '/' ) , preg_quote ( ']' , '/' ) , preg_quote ( ',' , '/' ) , preg_quote ( '=' , '/' ) , ] ; if ( ! preg_match ( '/^[' . implode ( '' , $ regexWhitelist ) . ']+$/iu' , $ path ) ) { throw new ApplicationException ( Lang :: get ( 'system::lang.media.invalid_path' , compact ( 'path' ) ) ) ; } $ regexDirectorySeparator = preg_quote ( '/' , '#' ) ; $ regexDot = preg_quote ( '.' , '#' ) ; $ regex = [ // Beginning of path '(^' . $ regexDot . '+?' . $ regexDirectorySeparator . ')' , // Middle of path '(' . $ regexDirectorySeparator . $ regexDot . '+?' . $ regexDirectorySeparator . ')' , // End of path '(' . $ regexDirectorySeparator . $ regexDot . '+?$)' , ] ; /*
           * Validate invalid paths
           */ $ regex = '#' . implode ( '|' , $ regex ) . '#' ; if ( preg_match ( $ regex , $ path ) !== 0 || strpos ( $ path , '//' ) !== false ) { throw new ApplicationException ( Lang :: get ( 'system::lang.media.invalid_path' , compact ( 'path' ) ) ) ; } return $ path ; }
docstring: Checks if file path doesn't contain any substrings that would pose a security threat.
  Throws an exception if the path is not valid.
  @param string $path Specifies the path.
  @param boolean $normalizeOnly Specifies if only the normalization, without validation should be performed.
  @return string Returns a normalized path.
docstring_tokens: Checks if file path doesn t contain any substrings that would pose a security threat . Throws an exception if the path is not valid .