Fix /tag/aa%20bb project URIs

Summary:
Ref T9551. To set things up:

  - Name a project `aa bb`. This will have the tag `aa_bb`.
  - Try to visit `/tag/aa%20bb`.

Here's what happens now:

  - You get an Aphront redirect error as it tries to add the trailing `/`. Add `phutil_escape_uri()` so that works again.
  - Then, you 404, even though this tag is reasonably equivalent to the real project tag and could be redirected. Add a fallback to lookup, resolve, and redirect if we can find a hit for the tag.

This also fixes stuff like `/tag/AA_BB/`.

Test Plan: Visited URIs like `/tag/aa%20bb`, `/tag/aa%20bb/`, `/tag/Aa_bB/`, etc. None of them worked before and now they all do.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9551

Differential Revision: https://secure.phabricator.com/D14260
This commit is contained in:
epriestley
2015-10-12 17:02:42 -07:00
parent 1bdf225354
commit 3ff5ca789a
4 changed files with 49 additions and 4 deletions

View File

@@ -26,10 +26,17 @@ final class PhabricatorProjectViewController
}
$project = $query->executeOne();
if (!$project) {
// If this request corresponds to a project but just doesn't have the
// slug quite right, redirect to the proper URI.
$uri = $this->getNormalizedURI($slug);
if ($uri !== null) {
return id(new AphrontRedirectResponse())->setURI($uri);
}
return new Aphront404Response();
}
$columns = id(new PhabricatorProjectColumnQuery())
->setViewer($viewer)
->withProjectPHIDs(array($project->getPHID()))
@@ -53,4 +60,31 @@ final class PhabricatorProjectViewController
return $this->delegateToController($controller_object);
}
private function getNormalizedURI($slug) {
if (!strlen($slug)) {
return null;
}
$normal = PhabricatorSlug::normalizeProjectSlug($slug);
if ($normal === $slug) {
return null;
}
$viewer = $this->getViewer();
// Do execute() instead of executeOne() here so we canonicalize before
// raising a policy exception. This is a little more polished than letting
// the user hit the error on any variant of the slug.
$projects = id(new PhabricatorProjectQuery())
->setViewer($viewer)
->withSlugs(array($normal))
->execute();
if (!$projects) {
return null;
}
return "/tag/{$normal}/";
}
}