Skip to content

Commit

Permalink
Allow empty string parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Dec 11, 2019
1 parent 3a7dd61 commit 79f3a5d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Psalm/Type.php
Expand Up @@ -812,7 +812,7 @@ public static function tokenize($string_type, $ignore_space = true)
}

if ($quote_char) {
if ($char === $quote_char && $i > 1 && !$escaped) {
if ($char === $quote_char && $i > 0 && !$escaped) {
$quote_char = null;

$type_tokens[$rtc][0] .= $char;
Expand Down
33 changes: 33 additions & 0 deletions tests/TypeParseTest.php
Expand Up @@ -834,6 +834,39 @@ public function testEnum()
$this->assertSame($resolved_type->getId(), $docblock_type->getId());
}

public function testEmptyString()
{
$docblock_type = Type::parseString('""|"admin"|"fun"');

$resolved_type = new Type\Union([
new Type\Atomic\TLiteralString(''),
new Type\Atomic\TLiteralString('admin'),
new Type\Atomic\TLiteralString('fun'),
]);

$this->assertSame($resolved_type->getId(), $docblock_type->getId());

$docblock_type = Type::parseString('"admin"|""|"fun"');

$resolved_type = new Type\Union([
new Type\Atomic\TLiteralString('admin'),
new Type\Atomic\TLiteralString(''),
new Type\Atomic\TLiteralString('fun'),
]);

$this->assertSame($resolved_type->getId(), $docblock_type->getId());

$docblock_type = Type::parseString('"admin"|"fun"|""');

$resolved_type = new Type\Union([
new Type\Atomic\TLiteralString('admin'),
new Type\Atomic\TLiteralString('fun'),
new Type\Atomic\TLiteralString(''),
]);

$this->assertSame($resolved_type->getId(), $docblock_type->getId());
}

/**
* @return void
*/
Expand Down

0 comments on commit 79f3a5d

Please sign in to comment.