Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Parser/RegularParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@

$this->beginBacktrack();
// @mago-expect analysis:possibly-invalid-argument
/** @psalm-suppress ArgumentTypeCoercion */
$contentMatchedShortcodes = $this->shortcode($names);
if(\is_string($contentMatchedShortcodes)) {
$closingName = $contentMatchedShortcodes;
Expand Down Expand Up @@ -414,6 +415,11 @@
return preg_quote((string)$text, '~');
};

// a character that starts an opening tag is text when another opening tag starts before it ends,
// so in a run like `[[[a]]` for `[[` the opening tag token is the last one, right before the name
$length = mb_strlen($syntax->getOpeningTag(), 'utf-8');

Check warning on line 420 in src/Parser/RegularParser.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "MBString": @@ @@ // a character that starts an opening tag is text when another opening tag starts before it ends, // so in a run like `[[[a]]` for `[[` the opening tag token is the last one, right before the name - $length = mb_strlen($syntax->getOpeningTag(), 'utf-8'); + $length = strlen($syntax->getOpeningTag()); $overlap = $length > 1 ? '|(?='.$quote($syntax->getOpeningTag()).').(?=.{0,'.($length - 2).'}'.$quote($syntax->getOpeningTag()).')' : ''; $rules = array(
$overlap = $length > 1 ? '|(?='.$quote($syntax->getOpeningTag()).').(?=.{0,'.($length - 2).'}'.$quote($syntax->getOpeningTag()).')' : '';

Check warning on line 421 in src/Parser/RegularParser.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "DecrementInteger": @@ @@ // a character that starts an opening tag is text when another opening tag starts before it ends, // so in a run like `[[[a]]` for `[[` the opening tag token is the last one, right before the name $length = mb_strlen($syntax->getOpeningTag(), 'utf-8'); - $overlap = $length > 1 ? '|(?='.$quote($syntax->getOpeningTag()).').(?=.{0,'.($length - 2).'}'.$quote($syntax->getOpeningTag()).')' : ''; + $overlap = $length > 1 ? '|(?='.$quote($syntax->getOpeningTag()).').(?=.{0,'.($length - 1).'}'.$quote($syntax->getOpeningTag()).')' : ''; $rules = array( '(?<string>\\\\.|(?:(?!'.implode('|', array(

Check warning on line 421 in src/Parser/RegularParser.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "GreaterThan": @@ @@ // a character that starts an opening tag is text when another opening tag starts before it ends, // so in a run like `[[[a]]` for `[[` the opening tag token is the last one, right before the name $length = mb_strlen($syntax->getOpeningTag(), 'utf-8'); - $overlap = $length > 1 ? '|(?='.$quote($syntax->getOpeningTag()).').(?=.{0,'.($length - 2).'}'.$quote($syntax->getOpeningTag()).')' : ''; + $overlap = $length >= 1 ? '|(?='.$quote($syntax->getOpeningTag()).').(?=.{0,'.($length - 2).'}'.$quote($syntax->getOpeningTag()).')' : ''; $rules = array( '(?<string>\\\\.|(?:(?!'.implode('|', array(

$rules = array(
'(?<string>\\\\.|(?:(?!'.implode('|', array(
$quote($syntax->getOpeningTag()),
Expand All @@ -423,7 +429,7 @@
$quote($syntax->getParameterValueDelimiter()),
'\\\\',
'\s+',
)).').)++)',
)).').'.$overlap.')++)',
'(?<ws>\s+)',
$group($syntax->getClosingTagMarker(), 'marker'),
$group($syntax->getParameterValueDelimiter(), 'delimiter'),
Expand Down
50 changes: 50 additions & 0 deletions tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,56 @@ public function testHybridParserSkipsEscapedTags()
}
}

/**
* @dataProvider provideRunsOfOpeningTags
*/
#[DataProvider('provideRunsOfOpeningTags')]
public function testParsersFindTagsInsideRunsOfOpeningTags(ParserInterface $parser, $code, array $expected)
{
$this->assertShortcodes($parser->parse($code), $expected);
}

public static function provideRunsOfOpeningTags()
{
$double = new Syntax('[[', ']]', '//', '==', '""');
$curly = new Syntax('{{', '}}', '/', '=', '"');
$cases = array(
array($double, '[[[a]]', array(
new ParsedShortcode(new Shortcode('a', array(), null, null), '[[a]]', 1),
)),
array($double, '[[a]][[[b]]', array(
new ParsedShortcode(new Shortcode('a', array(), null, null), '[[a]]', 0),
new ParsedShortcode(new Shortcode('b', array(), null, null), '[[b]]', 6),
)),
array($double, '[[a]]x[[[//a]]', array(
new ParsedShortcode(new Shortcode('a', array(), 'x[', null), '[[a]]x[[[//a]]', 0),
)),
array($double, '[[[[a]]', array(
new ParsedShortcode(new Shortcode('a', array(), null, null), '[[a]]', 2),
)),
array($curly, 'a{{{x}}', array(
new ParsedShortcode(new Shortcode('x', array(), null, null), '{{x}}', 2),
)),
array($curly, '{{x}}{{{/x}}', array(
new ParsedShortcode(new Shortcode('x', array(), '{', null), '{{x}}{{{/x}}', 0),
)),
array($curly, '{{a k="{{"}}', array(
new ParsedShortcode(new Shortcode('a', array('k' => '{{'), null, null), '{{a k="{{"}}', 0),
)),
array(new Syntax('««', '»»', '/', '=', '"'), 'ż«««x»»', array(
new ParsedShortcode(new Shortcode('x', array(), null, null), '««x»»', 2),
)),
);

$result = array();
foreach($cases as $case) {
$result[] = array(new RegularParser($case[0]), $case[1], $case[2]);
$result[] = array(new HybridParser($case[0]), $case[1], $case[2]);
}

return $result;
}

public function testIssue119()
{
$cases = array(
Expand Down
Loading