1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-29 02:02:41 +01:00

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
This commit is contained in:
epriestley 2021-07-26 10:55:52 -07:00
parent dbe2fb466f
commit c7550dbee9
3 changed files with 11 additions and 3 deletions

View file

@ -61,7 +61,7 @@ final class PhabricatorPhrictionApplication extends PhabricatorApplication {
'new/' => 'PhrictionNewController', 'new/' => 'PhrictionNewController',
'move/(?P<id>[1-9]\d*)/' => 'PhrictionMoveController', 'move/(?P<id>[1-9]\d*)/' => 'PhrictionMoveController',
'preview/(?P<slug>.*/)' => 'PhrictionMarkupPreviewController', 'preview/' => 'PhrictionMarkupPreviewController',
'diff/(?P<id>[1-9]\d*)/' => 'PhrictionDiffController', 'diff/(?P<id>[1-9]\d*)/' => 'PhrictionDiffController',
$this->getEditRoutePattern('document/edit/') $this->getEditRoutePattern('document/edit/')

View file

@ -316,9 +316,17 @@ final class PhrictionEditController
->setBackground(PHUIObjectBoxView::WHITE_CONFIG) ->setBackground(PHUIObjectBoxView::WHITE_CONFIG)
->setForm($form); ->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()) $preview = id(new PHUIRemarkupPreviewPanel())
->setHeader($content->getTitle()) ->setHeader($content->getTitle())
->setPreviewURI('/phriction/preview/'.$document->getSlug()) ->setPreviewURI($preview_uri)
->setControlID('document-textarea') ->setControlID('document-textarea')
->setPreviewType(PHUIRemarkupPreviewPanel::DOCUMENT); ->setPreviewType(PHUIRemarkupPreviewPanel::DOCUMENT);

View file

@ -8,7 +8,7 @@ final class PhrictionMarkupPreviewController
$viewer = $request->getUser(); $viewer = $request->getUser();
$text = $request->getStr('text'); $text = $request->getStr('text');
$slug = $request->getURIData('slug'); $slug = $request->getStr('slug');
$output = PhabricatorMarkupEngine::renderOneObject( $output = PhabricatorMarkupEngine::renderOneObject(
id(new PhabricatorMarkupOneOff()) id(new PhabricatorMarkupOneOff())