Differential D18076 Diff 43473 src/markup/engine/remarkup/markuprule/PhutilRemarkupDocumentLinkRule.php
Changeset View
Changeset View
Standalone View
Standalone View
src/markup/engine/remarkup/markuprule/PhutilRemarkupDocumentLinkRule.php
Show First 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | public function markupDocumentLink(array $matches) { | ||||
// If whatever is being linked to begins with "/" or "#", or has "://", | // If whatever is being linked to begins with "/" or "#", or has "://", | ||||
// or is "mailto:" or "tel:", treat it as a URI instead of a wiki page. | // or is "mailto:" or "tel:", treat it as a URI instead of a wiki page. | ||||
$is_uri = preg_match('@(^/)|(://)|(^#)|(^(?:mailto|tel):)@', $uri); | $is_uri = preg_match('@(^/)|(://)|(^#)|(^(?:mailto|tel):)@', $uri); | ||||
if ($is_uri && strncmp('/', $uri, 1) && strncmp('#', $uri, 1)) { | if ($is_uri && strncmp('/', $uri, 1) && strncmp('#', $uri, 1)) { | ||||
$protocols = $this->getEngine()->getConfig( | $protocols = $this->getEngine()->getConfig( | ||||
'uri.allowed-protocols', | 'uri.allowed-protocols', | ||||
array()); | array()); | ||||
try { | |||||
$protocol = id(new PhutilURI($uri))->getProtocol(); | $protocol = id(new PhutilURI($uri))->getProtocol(); | ||||
if (!idx($protocols, $protocol)) { | if (!idx($protocols, $protocol)) { | ||||
// Don't treat this as a URI if it's not an allowed protocol. | // Don't treat this as a URI if it's not an allowed protocol. | ||||
$is_uri = false; | $is_uri = false; | ||||
} | } | ||||
} catch (Exception $ex) { | |||||
// We can end up here if we try to parse an ambiguous URI, see | |||||
// T12796. | |||||
$is_uri = false; | |||||
} | |||||
} | } | ||||
if (!$is_uri) { | if (!$is_uri) { | ||||
return $matches[0]; | return $matches[0]; | ||||
} | } | ||||
return $this->getEngine()->storeText($this->renderHyperlink($uri, $name)); | return $this->getEngine()->storeText($this->renderHyperlink($uri, $name)); | ||||
} | } | ||||
} | } |