From 1e375c97c594e029d8e796c3fa937a7522e3b42f Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 4 Aug 2014 16:55:22 -0700 Subject: [PATCH] Normalize project slugs before querying for them Summary: Fixes T5728. In particular: - `/tag/XYZ/` now works as an alias for `/tag/xyz/`. - `arc todo --project ASDF` now works as an alias for `arc todo --project asdf`. Test Plan: Called `project.query` and visited `/tag/LBHABLHBH/`. Reviewers: btrahan Reviewed By: btrahan Subscribers: aklapper, epriestley Maniphest Tasks: T5728 Differential Revision: https://secure.phabricator.com/D10144 --- .../project/conduit/ProjectQueryConduitAPIMethod.php | 3 ++- src/applications/project/query/PhabricatorProjectQuery.php | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/applications/project/conduit/ProjectQueryConduitAPIMethod.php b/src/applications/project/conduit/ProjectQueryConduitAPIMethod.php index d1e61640a8..f91401797a 100644 --- a/src/applications/project/conduit/ProjectQueryConduitAPIMethod.php +++ b/src/applications/project/conduit/ProjectQueryConduitAPIMethod.php @@ -97,8 +97,9 @@ final class ProjectQueryConduitAPIMethod extends ProjectConduitAPIMethod { // TODO: This is pretty hideous. $slug_map = array(); foreach ($slugs as $slug) { + $normal = rtrim(PhabricatorSlug::normalize($slug), '/'); foreach ($projects as $project) { - if (in_array($slug, $project['slugs'])) { + if (in_array($normal, $project['slugs'])) { $slug_map[$slug] = $project['phid']; } } diff --git a/src/applications/project/query/PhabricatorProjectQuery.php b/src/applications/project/query/PhabricatorProjectQuery.php index c0beaf2742..bb2d280ef3 100644 --- a/src/applications/project/query/PhabricatorProjectQuery.php +++ b/src/applications/project/query/PhabricatorProjectQuery.php @@ -266,10 +266,15 @@ final class PhabricatorProjectQuery } if ($this->slugs) { + $slugs = array(); + foreach ($this->slugs as $slug) { + $slugs[] = rtrim(PhabricatorSlug::normalize($slug), '/'); + } + $where[] = qsprintf( $conn_r, 'slug.slug IN (%Ls)', - $this->slugs); + $slugs); } if ($this->phrictionSlugs) {