From fce6a7089cf36d08b90903c46348a641afee5d5c Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 15 Feb 2012 17:06:36 -0800 Subject: [PATCH] Fix production file links for some alt-domain configurations Summary: We sometimes call PhabricatorEnv::getProductionURI($file->getBestURI()) or similar, but this may currently cause us to construct a URI like this: http://domain.com/http://cdn-domain.com/file/data/xxx/yyy/name.jpg Instead, if the provided URI has a domain already, leave it unmodified. Test Plan: Attached a file to a task; got an email with a valid URI instead of an invalid URI. Reviewers: btrahan Reviewed By: btrahan CC: Makinde, aran, epriestley Differential Revision: https://secure.phabricator.com/D1622 --- src/infrastructure/env/PhabricatorEnv.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/infrastructure/env/PhabricatorEnv.php b/src/infrastructure/env/PhabricatorEnv.php index 4f91448eb9..eb8f22faa0 100644 --- a/src/infrastructure/env/PhabricatorEnv.php +++ b/src/infrastructure/env/PhabricatorEnv.php @@ -39,11 +39,19 @@ final class PhabricatorEnv { } public static function getProductionURI($path) { - $uri = self::getEnvConfig('phabricator.production-uri'); - if (!$uri) { - $uri = self::getEnvConfig('phabricator.base-uri'); + // If we're passed a URI which already has a domain, simply return it + // unmodified. In particular, files may have URIs which point to a CDN + // domain. + $uri = new PhutilURI($path); + if ($uri->getDomain()) { + return $path; } - return rtrim($uri, '/').$path; + + $production_domain = self::getEnvConfig('phabricator.production-uri'); + if (!$production_domain) { + $production_domain = self::getEnvConfig('phabricator.base-uri'); + } + return rtrim($production_domain, '/').$path; } public static function getCDNURI($path) {