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:
parent
5a9052fa18
commit
13779e760e
@ -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 = '!';
|
||||
|
@ -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',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user