Skip to content

Commit c2c0544

Browse files
committed
Added regex match check
1 parent 761aaa7 commit c2c0544

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

src/Inline/Parser/CodepenParser.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ public function parse(InlineParserContext $inlineContext): bool
3333
}
3434

3535
$matches = [];
36-
preg_match($regex, $validate, $matches);
36+
$exists = preg_match($regex, $validate, $matches);
37+
38+
if (!$exists) {
39+
return false;
40+
}
3741

3842
// Return the given codepen url to the renderer class
3943
$inlineContext->getContainer()->appendChild(new Codepen($matches[1]));

src/Inline/Parser/GistParser.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ public function parse(InlineParserContext $inlineContext): bool
3434
}
3535

3636
$matches = [];
37-
preg_match($regex, $validate, $matches);
37+
$exists = preg_match($regex, $validate, $matches);
38+
39+
if (!$exists) {
40+
return false;
41+
}
3842

3943
// Return the given gist url to the renderer class
4044
$inlineContext->getContainer()->appendChild(new Gist($matches[1]));

src/Inline/Parser/SoundCloudParser.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ public function parse(InlineParserContext $inlineContext): bool
3434
}
3535

3636
$matches = [];
37-
preg_match($regex, $validate, $matches);
37+
$exists = preg_match($regex, $validate, $matches);
38+
39+
if (!$exists) {
40+
return false;
41+
}
3842

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

src/Inline/Parser/YouTubeParser.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,20 @@ public function parse(InlineParserContext $inlineContext): bool
3838
$videoMatches = [];
3939
$timeMatches = [];
4040
$timeContinueMatches = [];
41-
preg_match($videoRegex, $validate, $videoMatches);
42-
preg_match($timeRegex, $validate, $timeMatches);
43-
preg_match($timeContinueRegex, $validate, $timeContinueMatches);
41+
$videoExists = preg_match($videoRegex, $validate, $videoMatches);
42+
$timeMatchesExist = preg_match($timeRegex, $validate, $timeMatches);
43+
$timeContinueMatchesExist = preg_match($timeContinueRegex, $validate, $timeContinueMatches);
44+
45+
if (!$videoExists) {
46+
return false;
47+
}
48+
4449
$videoId = $videoMatches[1];
4550
$startTime = '';
4651

47-
if ($timeMatches) {
52+
if ($timeMatchesExist) {
4853
$startTime = "?start={$timeMatches[1]}";
49-
} elseif ($timeContinueMatches) {
54+
} elseif ($timeContinueMatchesExist) {
5055
$startTime = "?start={$timeContinueMatches[1]}";
5156
}
5257

tests/Elements/Inline/YouTubeTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public function failedStrings()
5252
[':youtube .youtube.com/watch?v=USL6P8haroY', '<p>:youtube .youtube.com/watch?v=USL6P8haroY</p>'],
5353
[':youtube .com/watch?v=USL6P8haroY', '<p>:youtube .com/watch?v=USL6P8haroY</p>'],
5454
[':youtube poop.com/watch?v=USL6P8haroY', '<p>:youtube poop.com/watch?v=USL6P8haroY</p>'],
55+
[':youtube poop.com/watch?v=', '<p>:youtube poop.com/watch?v=</p>'],
5556
];
5657
}
5758

0 commit comments

Comments
 (0)