1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

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
This commit is contained in:
epriestley 2016-06-08 13:09:42 -07:00
parent 78fab485b4
commit 72d554aa9b
2 changed files with 18 additions and 8 deletions

View file

@ -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();

View file

@ -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();