@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix ambiguous URI parsing in Youtube Remarkup rule

Summary:
Fixes T12867. Also:

- Simplify the code a little.
- Stop mutating this on text/mobile -- there's no inherent value in the "youtu.be" link so I think this just changes the text the user wrote unnecessarily.

Test Plan: {F5013804}

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T12867

Differential Revision: https://secure.phabricator.com/D18149

+17 -13
+17 -13
src/infrastructure/markup/rule/PhabricatorYoutubeRemarkupRule.php
··· 2 2 3 3 final class PhabricatorYoutubeRemarkupRule extends PhutilRemarkupRule { 4 4 5 - private $uri; 6 - 7 5 public function getPriority() { 8 6 return 350.0; 9 7 } 10 8 11 9 public function apply($text) { 12 - $this->uri = new PhutilURI($text); 10 + try { 11 + $uri = new PhutilURI($text); 12 + } catch (Exception $ex) { 13 + return $text; 14 + } 13 15 14 - if ($this->uri->getDomain() && 15 - preg_match('/(^|\.)youtube\.com$/', $this->uri->getDomain()) && 16 - idx($this->uri->getQueryParams(), 'v')) { 17 - return $this->markupYoutubeLink(); 16 + $domain = $uri->getDomain(); 17 + if (!preg_match('/(^|\.)youtube\.com\z/', $domain)) { 18 + return $text; 18 19 } 19 20 20 - return $text; 21 - } 21 + $params = $uri->getQueryParams(); 22 + $v_param = idx($params, 'v'); 23 + if (!strlen($v_param)) { 24 + return $text; 25 + } 22 26 23 - public function markupYoutubeLink() { 24 - $v = idx($this->uri->getQueryParams(), 'v'); 25 27 $text_mode = $this->getEngine()->isTextMode(); 26 28 $mail_mode = $this->getEngine()->isHTMLMailMode(); 27 29 28 30 if ($text_mode || $mail_mode) { 29 - return $this->getEngine()->storeText('http://youtu.be/'.$v); 31 + return $text; 30 32 } 31 33 32 - $youtube_src = 'https://www.youtube.com/embed/'.$v; 34 + $youtube_src = 'https://www.youtube.com/embed/'.$v_param; 35 + 33 36 $iframe = $this->newTag( 34 37 'div', 35 38 array( ··· 45 48 'frameborder' => 0, 46 49 ), 47 50 '')); 51 + 48 52 return $this->getEngine()->storeText($iframe); 49 53 } 50 54