[FirefoxAddonsBridge] Fix removal of link redirects (#3144)

* [FirefoxAddonsBridge] Fix removable of link redirects

* Update FirefoxAddonsBridge.php
This commit is contained in:
Joseph 2022-11-14 21:56:12 +00:00 committed by GitHub
parent 80f9871c9e
commit 734a5868b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -21,7 +21,7 @@ class FirefoxAddonsBridge extends BridgeAbstract
private $feedName = ''; private $feedName = '';
private $releaseDateRegex = '/Released ([\w, ]+) - ([\w. ]+)/'; private $releaseDateRegex = '/Released ([\w, ]+) - ([\w. ]+)/';
private $xpiFileRegex = '/([A-Za-z0-9_.-]+)\.xpi$/'; private $xpiFileRegex = '/([A-Za-z0-9_.-]+)\.xpi$/';
private $outgoingRegex = '/https:\/\/outgoing.prod.mozaws.net\/v1\/(?:[A-z0-9]+)\//'; private $outgoingRegex = '/https:\/\/prod.outgoing\.prod\.webservices\.mozgcp\.net\/v1\/(?:[A-z0-9]+)\//';
private $urlRegex = '/addons\.mozilla\.org\/(?:[\w-]+\/)?firefox\/addon\/([\w-]+)/'; private $urlRegex = '/addons\.mozilla\.org\/(?:[\w-]+\/)?firefox\/addon\/([\w-]+)/';
@ -66,7 +66,7 @@ class FirefoxAddonsBridge extends BridgeAbstract
$downloadlink = $li->find('a.Button.Button--action.AMInstallButton-button.Button--puffy', 0)->href; $downloadlink = $li->find('a.Button.Button--action.AMInstallButton-button.Button--puffy', 0)->href;
} }
$releaseNotes = $this->removeOutgoinglink($li->find('div.AddonVersionCard-releaseNotes', 0)); $releaseNotes = $this->removeLinkRedirects($li->find('div.AddonVersionCard-releaseNotes', 0));
if (preg_match($this->xpiFileRegex, $downloadlink, $match)) { if (preg_match($this->xpiFileRegex, $downloadlink, $match)) {
$xpiFilename = $match[0]; $xpiFilename = $match[0];
@ -105,7 +105,10 @@ EOD;
return parent::getName(); return parent::getName();
} }
private function removeOutgoinglink($html) /**
* Removes 'https://prod.outgoing.prod.webservices.mozgcp.net/v1/' from external links
*/
private function removeLinkRedirects($html)
{ {
foreach ($html->find('a') as $a) { foreach ($html->find('a') as $a) {
$a->href = urldecode(preg_replace($this->outgoingRegex, '', $a->href)); $a->href = urldecode(preg_replace($this->outgoingRegex, '', $a->href));