Security update for Core, with self-updated composer
[yaffs-website] / vendor / doctrine / annotations / lib / Doctrine / Common / Annotations / DocParser.php
index db668460ee14e06ff41748b17ae8aa44ceae5979..eb7a457f504152c9198fe369d6a8d2e451699c33 100644 (file)
@@ -61,7 +61,7 @@ final class DocParser
     /**
      * Current target context.
      *
-     * @var string
+     * @var integer
      */
     private $target;
 
@@ -105,7 +105,7 @@ final class DocParser
     /**
      * An array of default namespaces if operating in simple mode.
      *
-     * @var array
+     * @var string[]
      */
     private $namespaces = array();
 
@@ -115,10 +115,18 @@ final class DocParser
      * The names must be the raw names as used in the class, not the fully qualified
      * class names.
      *
-     * @var array
+     * @var bool[] indexed by annotation name
      */
     private $ignoredAnnotationNames = array();
 
+    /**
+     * A list with annotations in namespaced format
+     * that are not causing exceptions when not resolved to an annotation class.
+     *
+     * @var bool[] indexed by namespace name
+     */
+    private $ignoredAnnotationNamespaces = array();
+
     /**
      * @var string
      */
@@ -242,7 +250,7 @@ final class DocParser
      * The names are supposed to be the raw names as used in the class, not the
      * fully qualified class names.
      *
-     * @param array $names
+     * @param bool[] $names indexed by annotation name
      *
      * @return void
      */
@@ -251,6 +259,18 @@ final class DocParser
         $this->ignoredAnnotationNames = $names;
     }
 
+    /**
+     * Sets the annotation namespaces that are ignored during the parsing process.
+     *
+     * @param bool[] $ignoredAnnotationNamespaces indexed by annotation namespace name
+     *
+     * @return void
+     */
+    public function setIgnoredAnnotationNamespaces($ignoredAnnotationNamespaces)
+    {
+        $this->ignoredAnnotationNamespaces = $ignoredAnnotationNamespaces;
+    }
+
     /**
      * Sets ignore on not-imported annotations.
      *
@@ -266,7 +286,7 @@ final class DocParser
     /**
      * Sets the default namespaces.
      *
-     * @param array $namespace
+     * @param string $namespace
      *
      * @return void
      *
@@ -347,8 +367,10 @@ final class DocParser
 
         // search for first valid annotation
         while (($pos = strpos($input, '@', $pos)) !== false) {
-            // if the @ is preceded by a space or * it is valid
-            if ($pos === 0 || $input[$pos - 1] === ' ' || $input[$pos - 1] === '*') {
+            $preceding = substr($input, $pos - 1, 1);
+
+            // if the @ is preceded by a space, a tab or * it is valid
+            if ($pos === 0 || $preceding === ' ' || $preceding === '*' || $preceding === "\t") {
                 return $pos;
             }
 
@@ -669,8 +691,10 @@ final class DocParser
         $originalName = $name;
 
         if ('\\' !== $name[0]) {
-            $alias = (false === $pos = strpos($name, '\\'))? $name : substr($name, 0, $pos);
+            $pos = strpos($name, '\\');
+            $alias = (false === $pos)? $name : substr($name, 0, $pos);
             $found = false;
+            $loweredAlias = strtolower($alias);
 
             if ($this->namespaces) {
                 foreach ($this->namespaces as $namespace) {
@@ -680,7 +704,7 @@ final class DocParser
                         break;
                     }
                 }
-            } elseif (isset($this->imports[$loweredAlias = strtolower($alias)])) {
+            } elseif (isset($this->imports[$loweredAlias])) {
                 $found = true;
                 $name  = (false !== $pos)
                     ? $this->imports[$loweredAlias] . substr($name, $pos)
@@ -696,7 +720,7 @@ final class DocParser
             }
 
             if ( ! $found) {
-                if ($this->ignoreNotImportedAnnotations || isset($this->ignoredAnnotationNames[$name])) {
+                if ($this->isIgnoredAnnotation($name)) {
                     return false;
                 }
 
@@ -704,6 +728,8 @@ final class DocParser
             }
         }
 
+        $name = ltrim($name,'\\');
+
         if ( ! $this->classExists($name)) {
             throw AnnotationException::semanticalError(sprintf('The annotation "@%s" in %s does not exist, or could not be auto-loaded.', $name, $this->context));
         }
@@ -720,7 +746,7 @@ final class DocParser
 
         // verify that the class is really meant to be an annotation and not just any ordinary class
         if (self::$annotationMetadata[$name]['is_annotation'] === false) {
-            if (isset($this->ignoredAnnotationNames[$originalName])) {
+            if ($this->ignoreNotImportedAnnotations || isset($this->ignoredAnnotationNames[$originalName])) {
                 return false;
             }
 
@@ -897,8 +923,10 @@ final class DocParser
         if ( ! defined($identifier) && false !== strpos($identifier, '::') && '\\' !== $identifier[0]) {
             list($className, $const) = explode('::', $identifier);
 
-            $alias = (false === $pos = strpos($className, '\\')) ? $className : substr($className, 0, $pos);
+            $pos = strpos($className, '\\');
+            $alias = (false === $pos) ? $className : substr($className, 0, $pos);
             $found = false;
+            $loweredAlias = strtolower($alias);
 
             switch (true) {
                 case !empty ($this->namespaces):
@@ -911,7 +939,7 @@ final class DocParser
                     }
                     break;
 
-                case isset($this->imports[$loweredAlias = strtolower($alias)]):
+                case isset($this->imports[$loweredAlias]):
                     $found     = true;
                     $className = (false !== $pos)
                         ? $this->imports[$loweredAlias] . substr($className, $pos)
@@ -1045,7 +1073,7 @@ final class DocParser
      * FieldAssignment ::= FieldName "=" PlainValue
      * FieldName ::= identifier
      *
-     * @return array
+     * @return \stdClass
      */
     private function FieldAssignment()
     {
@@ -1135,4 +1163,28 @@ final class DocParser
 
         return array(null, $this->Value());
     }
+
+    /**
+     * Checks whether the given $name matches any ignored annotation name or namespace
+     *
+     * @param string $name
+     *
+     * @return bool
+     */
+    private function isIgnoredAnnotation($name)
+    {
+        if ($this->ignoreNotImportedAnnotations || isset($this->ignoredAnnotationNames[$name])) {
+            return true;
+        }
+
+        foreach (array_keys($this->ignoredAnnotationNamespaces) as $ignoredAnnotationNamespace) {
+            $ignoredAnnotationNamespace = rtrim($ignoredAnnotationNamespace, '\\') . '\\';
+
+            if (0 === stripos(rtrim($name, '\\') . '\\', $ignoredAnnotationNamespace)) {
+                return true;
+            }
+        }
+
+        return false;
+    }
 }