From 72d554aa9b67fff66cf683a5b9f16b76d3cc0a27 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 8 Jun 2016 13:09:42 -0700 Subject: [PATCH] Fix parsing of anchors in Phriction document link syntax Summary: Ref T4280. At some point (probably D15732) we started getting anchor parsing wrong. Just pop the anchor off before doing all the logic, then put it back on at the end. Test Plan: Tested various forms like: ``` [[ x ]] [[ x | z ]] [[ x#y | z ]] [[ ./x#y | z ]] ``` Reviewers: chad Reviewed By: chad Maniphest Tasks: T4280 Differential Revision: https://secure.phabricator.com/D16083 --- .../markup/PhrictionRemarkupRule.php | 24 +++++++++++++------ .../markup/PhabricatorMarkupEngine.php | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/applications/phriction/markup/PhrictionRemarkupRule.php b/src/applications/phriction/markup/PhrictionRemarkupRule.php index c3a795a524..9c5649bbbe 100644 --- a/src/applications/phriction/markup/PhrictionRemarkupRule.php +++ b/src/applications/phriction/markup/PhrictionRemarkupRule.php @@ -16,7 +16,15 @@ final class PhrictionRemarkupRule extends PhutilRemarkupRule { } public function markupDocumentLink(array $matches) { - $link = trim($matches[1]); + // If the link contains an anchor, separate that off first. + $parts = explode('#', trim($matches[1]), 2); + if (count($parts) == 2) { + $link = $parts[0]; + $anchor = $parts[1]; + } else { + $link = $parts[0]; + $anchor = null; + } // Handle relative links. if ((substr($link, 0, 2) === './') || (substr($link, 0, 3) === '../')) { @@ -67,6 +75,7 @@ final class PhrictionRemarkupRule extends PhutilRemarkupRule { $metadata[] = array( 'token' => $token, 'link' => $link, + 'anchor' => $anchor, 'explicitName' => $name, ); $engine->setTextMetadata(self::KEY_RULE_PHRICTION_LINK, $metadata); @@ -140,12 +149,13 @@ final class PhrictionRemarkupRule extends PhutilRemarkupRule { } } - $uri = new PhutilURI($link); - $slug = $uri->getPath(); - $fragment = $uri->getFragment(); - $slug = PhabricatorSlug::normalize($slug); - $slug = PhrictionDocument::getSlugURI($slug); - $href = (string)id(new PhutilURI($slug))->setFragment($fragment); + $uri = new PhutilURI($link); + $slug = $uri->getPath(); + $slug = PhabricatorSlug::normalize($slug); + $slug = PhrictionDocument::getSlugURI($slug); + + $anchor = idx($spec, 'anchor'); + $href = (string)id(new PhutilURI($slug))->setFragment($anchor); $text_mode = $this->getEngine()->isTextMode(); $mail_mode = $this->getEngine()->isHTMLMailMode(); diff --git a/src/infrastructure/markup/PhabricatorMarkupEngine.php b/src/infrastructure/markup/PhabricatorMarkupEngine.php index 7c19cac57f..bb13c1d763 100644 --- a/src/infrastructure/markup/PhabricatorMarkupEngine.php +++ b/src/infrastructure/markup/PhabricatorMarkupEngine.php @@ -42,7 +42,7 @@ final class PhabricatorMarkupEngine extends Phobject { private $objects = array(); private $viewer; private $contextObject; - private $version = 15; + private $version = 16; private $engineCaches = array(); private $auxiliaryConfig = array();