Skip to content
This repository has been archived by the owner on Jul 6, 2020. It is now read-only.

Commit

Permalink
better specify yt url
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernhard Posselt committed Sep 22, 2014
1 parent 19910df commit 785a085
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion articleenhancer/globalarticleenhancer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function enhance(Item $item) {
// src needs to be matched against regex to prevent false positives
// and because theres no XPath matches function available
$src = $element->getAttribute('src');
$regex = '%^(http://|https://|//)(www\.)?youtube.com/.*autoplay=1.*%i';
$regex = '%^(http://|https://|//)(www\.)?youtube.com/.*\?.*autoplay=1.*%i';

if (preg_match($regex, $src)) {
$replaced = str_replace('autoplay=1', 'autoplay=0', $src);
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/articleenhancer/GlobalArticleEnhancerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ protected function setUp() {


public function testNoReplaceYoutubeAutoplay() {
$body = '<iframe width="728" height="410" src="//www.youtube.com/embed/AWE6UpXQoGU?autoplay=0" frameborder="0" allowfullscreen=""></iframe>';
$expected = '<iframe width="728" height="410" src="//www.youtube.com/embed/AWE6UpXQoGU?autoplay=0" frameborder="0" allowfullscreen=""></iframe>';
$body = '<iframe width="728" height="410" src="//www.youtube.com/embed/autoplay=1/AWE6UpXQoGU" frameborder="0" allowfullscreen=""></iframe>';
$expected = '<iframe width="728" height="410" src="//www.youtube.com/embed/autoplay=1/AWE6UpXQoGU" frameborder="0" allowfullscreen=""></iframe>';
$item = new Item();
$item->setBody($body);

Expand Down

0 comments on commit 785a085

Please sign in to comment.