diff --git a/src/infrastructure/markup/markuprule/PhutilRemarkupDocumentLinkRule.php b/src/infrastructure/markup/markuprule/PhutilRemarkupDocumentLinkRule.php --- a/src/infrastructure/markup/markuprule/PhutilRemarkupDocumentLinkRule.php +++ b/src/infrastructure/markup/markuprule/PhutilRemarkupDocumentLinkRule.php @@ -45,11 +45,11 @@ $engine = $this->getEngine(); $is_anchor = false; - if (strncmp($link, '/', 1) == 0) { + if ($this->isURIRelativePath($link)) { $base = phutil_string_cast($engine->getConfig('uri.base')); $base = rtrim($base, '/'); $link = $base.$link; - } else if (strncmp($link, '#', 1) == 0) { + } else if ($this->isURIAnchor($link)) { $here = $engine->getConfig('uri.here'); $link = $here.$link; diff --git a/src/infrastructure/markup/markuprule/PhutilRemarkupRule.php b/src/infrastructure/markup/markuprule/PhutilRemarkupRule.php --- a/src/infrastructure/markup/markuprule/PhutilRemarkupRule.php +++ b/src/infrastructure/markup/markuprule/PhutilRemarkupRule.php @@ -106,4 +106,28 @@ return (strpos($text, PhutilRemarkupBlockStorage::MAGIC_BYTE) === false); } + /** + * Check whenever an URI is an anchor + * + * @param string $uri + * @return bool + */ + protected function isURIAnchor($uri) { + return strncmp($uri, '#', 1) == 0; + } + + /** + * Is this URI a relative pathname + * + * @param string $uri Example '/path' etc. + * @return string + */ + protected function isURIRelativePath($uri) { + // NOTE: This was the original check, but at + // the moment '/' is assumed as relative but + // './' is assumed as not relative, and this + // may be confusing and may deserve a future update + return strncmp($uri, '/', 1) == 0; + } + }