From c7550dbee9b1979cf7728e7f87827d7b6e3166f6 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 26 Jul 2021 10:55:52 -0700 Subject: [PATCH] Fix Phriction document previews for the root document ("/") with Apache option "MergeSlashes On" Summary: Ref T13662. I ran into this while trying to reproduce the mention issue discussed there. Currently, the root document (with slug "/") attempts to preview using the URI `/phriction/preview//` (with two `//` at the end). This is collapsed into "/phriction/preview/" by Apache if "MergeSlashes On" is configured, which is the default behavior. The route then 404s. Instead, just use "/phriction/preview/?slug=/" so this endpoint functions properly regardless of the "MergeSlashes" configuration. Test Plan: - Configured Apache with "MergeSlashes On" (which is the default behavior). - Tried to preview a content edit of the root document in Phriction, which didn't work and generated 404s for "/phriction/preview//" in the console log. - Applied patch. - Previwed content in Phriction (which now worked properly). - Accessed `/a//b///c////` and similar with "MergeSlashes On" and "MergeSlashes Off", confirmed that this option controls whether PHP receives a URI with or without merged slashes in "__path__" after rewriting. Reviewers: 0 Reviewed By: 0 Maniphest Tasks: T13662 Differential Revision: https://secure.phabricator.com/D21708 --- .../application/PhabricatorPhrictionApplication.php | 2 +- .../phriction/controller/PhrictionEditController.php | 10 +++++++++- .../controller/PhrictionMarkupPreviewController.php | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/applications/phriction/application/PhabricatorPhrictionApplication.php b/src/applications/phriction/application/PhabricatorPhrictionApplication.php index 02f285aef3..edb035a63b 100644 --- a/src/applications/phriction/application/PhabricatorPhrictionApplication.php +++ b/src/applications/phriction/application/PhabricatorPhrictionApplication.php @@ -61,7 +61,7 @@ final class PhabricatorPhrictionApplication extends PhabricatorApplication { 'new/' => 'PhrictionNewController', 'move/(?P[1-9]\d*)/' => 'PhrictionMoveController', - 'preview/(?P.*/)' => 'PhrictionMarkupPreviewController', + 'preview/' => 'PhrictionMarkupPreviewController', 'diff/(?P[1-9]\d*)/' => 'PhrictionDiffController', $this->getEditRoutePattern('document/edit/') diff --git a/src/applications/phriction/controller/PhrictionEditController.php b/src/applications/phriction/controller/PhrictionEditController.php index d86fa1e05b..e6dea7f0ad 100644 --- a/src/applications/phriction/controller/PhrictionEditController.php +++ b/src/applications/phriction/controller/PhrictionEditController.php @@ -316,9 +316,17 @@ final class PhrictionEditController ->setBackground(PHUIObjectBoxView::WHITE_CONFIG) ->setForm($form); + $preview_uri = '/phriction/preview/'; + $preview_uri = new PhutilURI( + $preview_uri, + array( + 'slug' => $document->getSlug(), + )); + $preview_uri = phutil_string_cast($preview_uri); + $preview = id(new PHUIRemarkupPreviewPanel()) ->setHeader($content->getTitle()) - ->setPreviewURI('/phriction/preview/'.$document->getSlug()) + ->setPreviewURI($preview_uri) ->setControlID('document-textarea') ->setPreviewType(PHUIRemarkupPreviewPanel::DOCUMENT); diff --git a/src/applications/phriction/controller/PhrictionMarkupPreviewController.php b/src/applications/phriction/controller/PhrictionMarkupPreviewController.php index b5c97e5c64..7e56436dbb 100644 --- a/src/applications/phriction/controller/PhrictionMarkupPreviewController.php +++ b/src/applications/phriction/controller/PhrictionMarkupPreviewController.php @@ -8,7 +8,7 @@ final class PhrictionMarkupPreviewController $viewer = $request->getUser(); $text = $request->getStr('text'); - $slug = $request->getURIData('slug'); + $slug = $request->getStr('slug'); $output = PhabricatorMarkupEngine::renderOneObject( id(new PhabricatorMarkupOneOff())