diff --git a/src/markup/engine/__tests__/remarkup/link-with-angle-link-anchor.txt b/src/markup/engine/__tests__/remarkup/link-with-angle-link-anchor.txt new file mode 100644 --- /dev/null +++ b/src/markup/engine/__tests__/remarkup/link-with-angle-link-anchor.txt @@ -0,0 +1,5 @@ + +~~~~~~~~~~ +

<http://x.y#http://x.y#>

+~~~~~~~~~~ + diff --git a/src/markup/engine/__tests__/remarkup/link-with-link-anchor.txt b/src/markup/engine/__tests__/remarkup/link-with-link-anchor.txt new file mode 100644 --- /dev/null +++ b/src/markup/engine/__tests__/remarkup/link-with-link-anchor.txt @@ -0,0 +1,5 @@ +http://x.y#http://x.y# +~~~~~~~~~~ +

http://x.y#http://x.y#

+~~~~~~~~~~ +http://x.y#http://x.y# diff --git a/src/markup/engine/remarkup/markuprule/PhutilRemarkupHyperlinkRule.php b/src/markup/engine/remarkup/markuprule/PhutilRemarkupHyperlinkRule.php --- a/src/markup/engine/remarkup/markuprule/PhutilRemarkupHyperlinkRule.php +++ b/src/markup/engine/remarkup/markuprule/PhutilRemarkupHyperlinkRule.php @@ -32,11 +32,18 @@ } protected function markupHyperlink(array $matches) { + try { + $uri = new PhutilURI($matches[1]); + } catch (Exception $ex) { + return $matches[0]; + } + + $protocol = $uri->getProtocol(); + $protocols = $this->getEngine()->getConfig( 'uri.allowed-protocols', array()); - $protocol = id(new PhutilURI($matches[1]))->getProtocol(); if (!idx($protocols, $protocol)) { // If this URI doesn't use a whitelisted protocol, don't link it. This // is primarily intended to prevent javascript:// silliness. @@ -102,6 +109,12 @@ $match = substr($match, 0, -1); } + try { + $uri = new PhutilURI($match); + } catch (Exception $ex) { + return $matches[0]; + } + return hsprintf('%s%s', $this->markupHyperlink(array(null, $match)), $tail); }