Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skipped annotation when line above contains double quote (v1.8.0) #307

Open
keksa opened this issue Feb 10, 2020 · 1 comment
Open

Skipped annotation when line above contains double quote (v1.8.0) #307

keksa opened this issue Feb 10, 2020 · 1 comment

Comments

@keksa
Copy link

keksa commented Feb 10, 2020

The second Regex annotation is ignored by annotation reader, if the line above contains a double quote ". See the very simplified example:

class

namespace AppBundle\Component;

use Symfony\Component\Validator\Constraints as Assert;

class Foo
{
    /**
     * @Assert\Regex(pattern="~[a-zA-Z]~")
     * "
     * @Assert\Regex(pattern="~[<>\\'""*]+~", match=false)
     */
    private $foo;
}

reader

$reflectionClass = new \ReflectionClass(\AppBundle\Component\Foo::class);
$property = $reflectionClass->getProperty('foo');

$reader = new \Doctrine\Common\Annotations\AnnotationReader();
$annotations = $reader->getPropertyAnnotations($property);
dump($annotations);

expected result

array:2 [▼
  0 => Regex^ {#1592 ▼
    +message: "This value is not valid."
    +pattern: "~[a-zA-Z]~"
    +htmlPattern: null
    +match: true
    +payload: null
  }
  1 => Regex^ {#1533 ▼
    +message: "This value is not valid."
    +pattern: "~[<>\\'"*]+~"
    +htmlPattern: null
    +match: false
    +payload: null
  }
]

actual result

array:1 [▼
  0 => Regex^ {#1592 ▼
    +message: "This value is not valid."
    +pattern: "~[a-zA-Z]~"
    +htmlPattern: null
    +match: true
    +payload: null
  }
]
@keksa
Copy link
Author

keksa commented Feb 10, 2020

To provide some more context, the following cases all work as expected:

/**
 * "
 * @Assert\Regex(pattern="~[a-zA-Z]~")
 * @Assert\Regex(pattern="~[<>\\'""*]+~", match=false)
 */
private $foo;
/**
 * "
 * @Assert\Regex(pattern="~[<>\\'""*]+~", match=false)
 */
private $foo;
/**
 * @Assert\Regex(pattern="~[a-zA-Z]~")
 * foo bar
 * @Assert\Regex(pattern="~[<>\\'""*]+~", match=false)
 */
private $foo;
/**
 * @Assert\Regex(pattern="~[a-zA-Z]~")
 * @Assert\Regex(pattern="~[<>\\'""*]+~", match=false)
 * "
 */
private $foo;
/**
 * "
 * @Assert\Regex(pattern="~[a-zA-Z]~")
 * @Assert\Regex(pattern="~[<>\\'""*]+~", match=false)
 * "
 */
private $foo;

@keksa keksa changed the title Skipped annotation when line above contains double quote Skipped annotation when line above contains double quote (v1.8.0) Feb 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant