Skip to content

Commit d7f637c

Browse files
committed
Making the parser stateless
1 parent d7827c7 commit d7f637c

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Parser.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ public function parse(string $value, int $flags = 0)
9898
if (null !== $mbEncoding) {
9999
mb_internal_encoding($mbEncoding);
100100
}
101+
$this->refsBeingParsed = [];
102+
$this->offset = 0;
101103
$this->lines = [];
102104
$this->currentLine = '';
103105
$this->refs = [];

Tests/ParserTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,20 @@ public function invalidIndentation(): array
8484
];
8585
}
8686

87+
public function testParserIsStateless()
88+
{
89+
$yamlString = '# translations/messages.en.yaml
90+
91+
';
92+
$this->parser->parse($yamlString);
93+
$this->parser->parse($yamlString);
94+
95+
$this->expectException(ParseException::class);
96+
$this->expectExceptionMessage("A YAML file cannot contain tabs as indentation at line 2 (near \"\tabc\")");
97+
98+
$this->parser->parse("abc:\n\tabc");
99+
}
100+
87101
/**
88102
* @dataProvider validTokenSeparators
89103
*/

0 commit comments

Comments
 (0)