mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 10:07:12 +00:00
Limit characters after tag name
Previously we allowed all characters after a tag name which made
it a bit fuzzy how tags are handled. Psr-5 is more strict about
the characters that are allowed in tags and those that are part of
the body. A tag name can now be followed by `(`, <space> and `{` all
other characters are forbidden. The first character of the body is
not restricted anymore.
fixes #165
This commit is contained in:
@@ -46,6 +46,7 @@ use function count;
|
||||
use function get_class;
|
||||
use function preg_match;
|
||||
use function strpos;
|
||||
use function trim;
|
||||
|
||||
/**
|
||||
* Creates a Tag object given the contents of a tag.
|
||||
@@ -147,13 +148,7 @@ final class StandardTagFactory implements TagFactory
|
||||
|
||||
[$tagName, $tagBody] = $this->extractTagParts($tagLine);
|
||||
|
||||
if ($tagBody !== '' && strpos($tagBody, '[') === 0) {
|
||||
throw new InvalidArgumentException(
|
||||
'The tag "' . $tagLine . '" does not seem to be wellformed, please check it for errors'
|
||||
);
|
||||
}
|
||||
|
||||
return $this->createTag($tagBody, $tagName, $context);
|
||||
return $this->createTag(trim($tagBody), $tagName, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -199,7 +194,7 @@ final class StandardTagFactory implements TagFactory
|
||||
private function extractTagParts(string $tagLine) : array
|
||||
{
|
||||
$matches = [];
|
||||
if (!preg_match('/^@(' . self::REGEX_TAGNAME . ')(?:\s*([^\s].*)|$)/us', $tagLine, $matches)) {
|
||||
if (!preg_match('/^@(' . self::REGEX_TAGNAME . ')((?:[\s\(\{:])\s*([^\s].*)|$)/us', $tagLine, $matches)) {
|
||||
throw new InvalidArgumentException(
|
||||
'The tag "' . $tagLine . '" does not seem to be wellformed, please check it for errors'
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user