Skip to content

Commit

Permalink
Added regex match check
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyhuy committed Jun 3, 2020
1 parent 761aaa7 commit c2c0544
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/Inline/Parser/CodepenParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ public function parse(InlineParserContext $inlineContext): bool
}

$matches = [];
preg_match($regex, $validate, $matches);
$exists = preg_match($regex, $validate, $matches);

if (!$exists) {
return false;
}

// Return the given codepen url to the renderer class
$inlineContext->getContainer()->appendChild(new Codepen($matches[1]));
Expand Down
6 changes: 5 additions & 1 deletion src/Inline/Parser/GistParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ public function parse(InlineParserContext $inlineContext): bool
}

$matches = [];
preg_match($regex, $validate, $matches);
$exists = preg_match($regex, $validate, $matches);

if (!$exists) {
return false;
}

// Return the given gist url to the renderer class
$inlineContext->getContainer()->appendChild(new Gist($matches[1]));
Expand Down
6 changes: 5 additions & 1 deletion src/Inline/Parser/SoundCloudParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ public function parse(InlineParserContext $inlineContext): bool
}

$matches = [];
preg_match($regex, $validate, $matches);
$exists = preg_match($regex, $validate, $matches);

if (!$exists) {
return false;
}

$inlineContext->getContainer()->appendChild(new SoundCloud($matches[1]));

Expand Down
15 changes: 10 additions & 5 deletions src/Inline/Parser/YouTubeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,20 @@ public function parse(InlineParserContext $inlineContext): bool
$videoMatches = [];
$timeMatches = [];
$timeContinueMatches = [];
preg_match($videoRegex, $validate, $videoMatches);
preg_match($timeRegex, $validate, $timeMatches);
preg_match($timeContinueRegex, $validate, $timeContinueMatches);
$videoExists = preg_match($videoRegex, $validate, $videoMatches);
$timeMatchesExist = preg_match($timeRegex, $validate, $timeMatches);
$timeContinueMatchesExist = preg_match($timeContinueRegex, $validate, $timeContinueMatches);

if (!$videoExists) {
return false;
}

$videoId = $videoMatches[1];
$startTime = '';

if ($timeMatches) {
if ($timeMatchesExist) {
$startTime = "?start={$timeMatches[1]}";
} elseif ($timeContinueMatches) {
} elseif ($timeContinueMatchesExist) {
$startTime = "?start={$timeContinueMatches[1]}";
}

Expand Down
1 change: 1 addition & 0 deletions tests/Elements/Inline/YouTubeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function failedStrings()
[':youtube .youtube.com/watch?v=USL6P8haroY', '<p>:youtube .youtube.com/watch?v=USL6P8haroY</p>'],
[':youtube .com/watch?v=USL6P8haroY', '<p>:youtube .com/watch?v=USL6P8haroY</p>'],
[':youtube poop.com/watch?v=USL6P8haroY', '<p>:youtube poop.com/watch?v=USL6P8haroY</p>'],
[':youtube poop.com/watch?v=', '<p>:youtube poop.com/watch?v=</p>'],
];
}

Expand Down

0 comments on commit c2c0544

Please sign in to comment.