Skip to content

Commit

Permalink
fix parsing comments not prefixed by a space
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Sep 18, 2020
1 parent e6f16d8 commit 50f080d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Inline.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public static function parse($value, $flags = 0, $references = [])
}

// some comments are allowed at the end
if (preg_replace('/\s+#.*$/A', '', substr($value, $i))) {
if (preg_replace('/\s*#.*$/A', '', substr($value, $i))) {
throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value, $i)), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
}

Expand Down
10 changes: 10 additions & 0 deletions Tests/InlineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -860,4 +860,14 @@ public function testParseNegativeOctalNumberContainingInvalidDigits()
{
self::assertSame('-0123456789', Inline::parse('-0123456789'));
}

public function testParseCommentNotPrefixedBySpaces()
{
self::assertSame('foo', Inline::parse('"foo"#comment'));
}

public function testParseUnquotedStringContainingHashTagNotPrefixedBySpace()
{
self::assertSame('foo#nocomment', Inline::parse('foo#nocomment'));
}
}

0 comments on commit 50f080d

Please sign in to comment.