From 10ef973735b2369d6737d0d012ad704b3a5164d5 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 18 Jan 2016 07:36:28 -0800 Subject: [PATCH] Allow older, invalid project tags to continue to function Summary: Ref T10168. Around October 12, T9551 made project hashtags stricter and prevented them from containing characters like comma (`,`). Around December 27, D14888 changed how hashtags queries work so that the query does normalization instead of requiring the caller to normalize. After the Dec 27 change, projects from before Oct 12 with now-invalid hashtags will no longer load when queried directly by hashtag, because the page queries for `old,[silly]hash,,tag` or whatever, it gets normalized into `old_silly_hash_tag`, and then there are no hits. Instead, at least for now, query by both the exact raw text and the normalized hashtag. This should keep older stuff working until we can give users more support for migrating forward. Test Plan: - Forced a project to have a bogus hahstag. - Before patch: clicking its tag 404'd. - After patch: clicking its tag now works. - Visited a project by alternate hashtag. - Visited a project by denormalized hashtag and alternate hashtag (e.g., capital letters instead of lowercase letters), saw it redirect/normalize properly. Reviewers: chad Reviewed By: chad Maniphest Tasks: T10168 Differential Revision: https://secure.phabricator.com/D15047 --- .../project/query/PhabricatorProjectQuery.php | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/src/applications/project/query/PhabricatorProjectQuery.php b/src/applications/project/query/PhabricatorProjectQuery.php index bc14e93a88..e2d678e7d7 100644 --- a/src/applications/project/query/PhabricatorProjectQuery.php +++ b/src/applications/project/query/PhabricatorProjectQuery.php @@ -9,6 +9,7 @@ final class PhabricatorProjectQuery private $slugs; private $slugNormals; private $slugMap; + private $allSlugs; private $names; private $nameTokens; private $icons; @@ -169,10 +170,19 @@ final class PhabricatorProjectQuery protected function willExecute() { $this->slugMap = array(); $this->slugNormals = array(); + $this->allSlugs = array(); if ($this->slugs) { foreach ($this->slugs as $slug) { - $normal = PhabricatorSlug::normalizeProjectSlug($slug); - $this->slugNormals[$slug] = $normal; + if (PhabricatorSlug::isValidProjectSlug($slug)) { + $normal = PhabricatorSlug::normalizeProjectSlug($slug); + $this->slugNormals[$slug] = $normal; + $this->allSlugs[$normal] = $normal; + } + + // NOTE: At least for now, we query for the normalized slugs but also + // for the slugs exactly as entered. This allows older projects with + // slugs that are no longer valid to continue to work. + $this->allSlugs[$slug] = $slug; } } } @@ -380,7 +390,7 @@ final class PhabricatorProjectQuery $where[] = qsprintf( $conn, 'slug.slug IN (%Ls)', - $this->slugNormals); + $this->allSlugs); } if ($this->names !== null) { @@ -625,13 +635,17 @@ final class PhabricatorProjectQuery // else. $unknown = $this->slugNormals; foreach ($unknown as $input => $normal) { - if (!isset($primary_map[$normal])) { + if (isset($primary_map[$input])) { + $match = $input; + } else if (isset($primary_map[$normal])) { + $match = $normal; + } else { continue; } $this->slugMap[$input] = array( - 'slug' => $normal, - 'projectPHID' => $primary_map[$normal]->getPHID(), + 'slug' => $match, + 'projectPHID' => $primary_map[$match]->getPHID(), ); unset($unknown[$input]); @@ -658,13 +672,17 @@ final class PhabricatorProjectQuery // Link up any slugs we were not able to link up earlier. $extra_map = mpull($slugs, 'getProjectPHID', 'getSlug'); foreach ($unknown as $input => $normal) { - if (!isset($extra_map[$normal])) { + if (isset($extra_map[$input])) { + $match = $input; + } else if (isset($extra_map[$normal])) { + $match = $normal; + } else { continue; } $this->slugMap[$input] = array( - 'slug' => $normal, - 'projectPHID' => $extra_map[$normal], + 'slug' => $match, + 'projectPHID' => $extra_map[$match], ); unset($unknown[$input]);