1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix #1736 - forbid | in @psalm-assert

This commit is contained in:
Matthew Brown 2019-06-05 00:46:55 -04:00
parent 5a9052fa18
commit 13779e760e
2 changed files with 37 additions and 0 deletions

View File

@ -1860,6 +1860,31 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
foreach ($docblock_info->assertions as $assertion) {
$assertion_type = $assertion['type'];
if (strpos($assertion_type, '|') !== false) {
if (IssueBuffer::accepts(
new InvalidDocblock(
'Docblock assertions cannot contain | characters',
new CodeLocation($this->file_scanner, $stmt, null, true)
)
)) {
}
continue;
}
if (strpos($assertion_type, '\'') !== false || strpos($assertion_type, '"') !== false) {
if (IssueBuffer::accepts(
new InvalidDocblock(
'Docblock assertions cannot contain quotes',
new CodeLocation($this->file_scanner, $stmt, null, true)
)
)) {
}
continue;
}
$prefix = '';
if ($assertion_type[0] === '!') {
$prefix = '!';

View File

@ -1204,6 +1204,18 @@ class AssertTest extends TestCase
}',
'error_message' => 'RedundantCondition',
],
'assertValueImpossible' => [
'<?php
/**
* @psalm-assert "foo"|"bar"|"foo-bar" $s
*/
function assertFooBar(string $s) : void {
}
$a = "";
assertFooBar($a);',
'error_message' => 'InvalidDocblock',
],
];
}
}