diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -12668,7 +12668,7 @@
'PhutilRemarkupDelRule' => 'PhutilRemarkupRule',
'PhutilRemarkupDocumentLinkRule' => 'PhutilRemarkupRule',
'PhutilRemarkupEngine' => 'PhutilMarkupEngine',
- 'PhutilRemarkupEngineTestCase' => 'PhutilTestCase',
+ 'PhutilRemarkupEngineTestCase' => 'PhabricatorTestCase',
'PhutilRemarkupEscapeRemarkupRule' => 'PhutilRemarkupRule',
'PhutilRemarkupEvalRule' => 'PhutilRemarkupRule',
'PhutilRemarkupHeaderBlockRule' => 'PhutilRemarkupBlockRule',
diff --git a/src/infrastructure/env/PhabricatorEnv.php b/src/infrastructure/env/PhabricatorEnv.php
--- a/src/infrastructure/env/PhabricatorEnv.php
+++ b/src/infrastructure/env/PhabricatorEnv.php
@@ -11,7 +11,7 @@
* The primary role of this class is to provide an API for reading
* Phabricator configuration, @{method:getEnvConfig}:
*
- * $value = PhabricatorEnv::getEnvConfig('some.key', $default);
+ * $value = PhabricatorEnv::getEnvConfig('some.key');
*
* The class also handles some URI construction based on configuration, via
* the methods @{method:getURI}, @{method:getProductionURI},
@@ -428,14 +428,28 @@
}
+ /**
+ * Check whenever an URI points to this very same Phorge installation.
+ * @param string $raw_uri
+ * @return bool True, if this URI points to Phorge itself.
+ */
public static function isSelfURI($raw_uri) {
$uri = new PhutilURI($raw_uri);
+ // Relative paths always are self-URIs.
$host = $uri->getDomain();
- if (!phutil_nonempty_string($host)) {
+ $prot = $uri->getProtocol();
+ $empty_host = !phutil_nonempty_string($host);
+ $empty_prot = !phutil_nonempty_string($prot);
+ if ($empty_host && $empty_prot) {
return true;
}
+ // Probably this is a mailto.
+ if ($empty_host) {
+ return false;
+ }
+
$host = phutil_utf8_strtolower($host);
$self_map = self::getSelfURIMap();
diff --git a/src/infrastructure/markup/remarkup/__tests__/PhutilRemarkupEngineTestCase.php b/src/infrastructure/markup/remarkup/__tests__/PhutilRemarkupEngineTestCase.php
--- a/src/infrastructure/markup/remarkup/__tests__/PhutilRemarkupEngineTestCase.php
+++ b/src/infrastructure/markup/remarkup/__tests__/PhutilRemarkupEngineTestCase.php
@@ -2,10 +2,12 @@
/**
* Test cases for @{class:PhutilRemarkupEngine}.
+ * This needs to be a PhabricatorTestCase since it may want
+ * to access some Phorge URI configurations.
* @TODO: This unit is not always triggered when you need it.
* https://we.phorge.it/T15500
*/
-final class PhutilRemarkupEngineTestCase extends PhutilTestCase {
+final class PhutilRemarkupEngineTestCase extends PhabricatorTestCase {
public function testEngine() {
$root = dirname(__FILE__).'/remarkup/';
diff --git a/src/infrastructure/markup/remarkup/__tests__/remarkup/link-brackets.txt b/src/infrastructure/markup/remarkup/__tests__/remarkup/link-brackets.txt
--- a/src/infrastructure/markup/remarkup/__tests__/remarkup/link-brackets.txt
+++ b/src/infrastructure/markup/remarkup/__tests__/remarkup/link-brackets.txt
@@ -1,5 +1,5 @@
~~~~~~~~~~
-
+
~~~~~~~~~~
http://www.zany.com/omg/weird_url,,,
diff --git a/src/infrastructure/markup/remarkup/__tests__/remarkup/link-edge-cases.txt b/src/infrastructure/markup/remarkup/__tests__/remarkup/link-edge-cases.txt
--- a/src/infrastructure/markup/remarkup/__tests__/remarkup/link-edge-cases.txt
+++ b/src/infrastructure/markup/remarkup/__tests__/remarkup/link-edge-cases.txt
@@ -10,17 +10,17 @@
Quick! http://www.example.com/!
~~~~~~~~~~
-
+
-()
+()
-
+
-
+
-(example )
+(example )
-Quick! !
+Quick! !
~~~~~~~~~~
http://www.example.com/
diff --git a/src/infrastructure/markup/remarkup/__tests__/remarkup/link-mailto.txt b/src/infrastructure/markup/remarkup/__tests__/remarkup/link-mailto.txt
--- a/src/infrastructure/markup/remarkup/__tests__/remarkup/link-mailto.txt
+++ b/src/infrastructure/markup/remarkup/__tests__/remarkup/link-mailto.txt
@@ -5,11 +5,11 @@
[[mailto:alincoln@example.com]]
~~~~~~~~~~
-
+
-
+
-
+
~~~~~~~~~~
mail me
diff --git a/src/infrastructure/markup/remarkup/__tests__/remarkup/link-mixed.txt b/src/infrastructure/markup/remarkup/__tests__/remarkup/link-mixed.txt
--- a/src/infrastructure/markup/remarkup/__tests__/remarkup/link-mixed.txt
+++ b/src/infrastructure/markup/remarkup/__tests__/remarkup/link-mixed.txt
@@ -5,11 +5,11 @@
~~~~~~~~~~
-()
+()
-()
+()
-< >
+< >
~~~~~~~~~~
Example (http://www.alternate.org/)
diff --git a/src/infrastructure/markup/remarkup/__tests__/remarkup/link-noreferrer.txt b/src/infrastructure/markup/remarkup/__tests__/remarkup/link-noreferrer.txt
--- a/src/infrastructure/markup/remarkup/__tests__/remarkup/link-noreferrer.txt
+++ b/src/infrastructure/markup/remarkup/__tests__/remarkup/link-noreferrer.txt
@@ -1,15 +1,27 @@
+I have no idea what should happen in this case.
+Technically it does not seem to be an external link.
+Browsers may make it external, though?
+But I guess that the TARGET attribute is not the important part here...
+
[[ /\evil.com ]]
[[ /
/evil.com ]]
~~~~~~~~~~
-
+I have no idea what should happen in this case.
+Technically it does not seem to be an external link.
+Browsers may make it external, though?
+But I guess that the TARGET attribute is not the important part here...
+
+
~~~~~~~~~~
+I have no idea what should happen in this case. Technically it does not seem to be an external link. Browsers may make it external, though? But I guess that the TARGET attribute is not the important part here...
+
/\evil.com
/
diff --git a/src/infrastructure/markup/remarkup/__tests__/remarkup/link-same-window.txt b/src/infrastructure/markup/remarkup/__tests__/remarkup/link-same-window.txt
--- a/src/infrastructure/markup/remarkup/__tests__/remarkup/link-same-window.txt
+++ b/src/infrastructure/markup/remarkup/__tests__/remarkup/link-same-window.txt
@@ -2,9 +2,9 @@
http://www.example.com/
~~~~~~~~~~
-
+
-
+
~~~~~~~~~~
http://www.example.com/
diff --git a/src/infrastructure/markup/remarkup/__tests__/remarkup/link-square.txt b/src/infrastructure/markup/remarkup/__tests__/remarkup/link-square.txt
--- a/src/infrastructure/markup/remarkup/__tests__/remarkup/link-square.txt
+++ b/src/infrastructure/markup/remarkup/__tests__/remarkup/link-square.txt
@@ -8,11 +8,11 @@
[[#anchor | Anchors ]]
~~~~~~~~~~
-
+
-
+
-
+
diff --git a/src/infrastructure/markup/remarkup/__tests__/remarkup/link-tel.txt b/src/infrastructure/markup/remarkup/__tests__/remarkup/link-tel.txt
--- a/src/infrastructure/markup/remarkup/__tests__/remarkup/link-tel.txt
+++ b/src/infrastructure/markup/remarkup/__tests__/remarkup/link-tel.txt
@@ -5,11 +5,11 @@
[[tel:18005555555]]
~~~~~~~~~~
-
+
-
+
-
+
~~~~~~~~~~
call me <18005555555>
diff --git a/src/infrastructure/markup/remarkup/__tests__/remarkup/link-with-punctuation.txt b/src/infrastructure/markup/remarkup/__tests__/remarkup/link-with-punctuation.txt
--- a/src/infrastructure/markup/remarkup/__tests__/remarkup/link-with-punctuation.txt
+++ b/src/infrastructure/markup/remarkup/__tests__/remarkup/link-with-punctuation.txt
@@ -2,8 +2,8 @@
http://www.example.com/..
http://www.example.com/!!!
~~~~~~~~~~
-,
-..
-!!!
+,
+..
+!!!
~~~~~~~~~~
http://www.example.com/, http://www.example.com/.. http://www.example.com/!!!
diff --git a/src/infrastructure/markup/remarkup/__tests__/remarkup/link-with-tilde.txt b/src/infrastructure/markup/remarkup/__tests__/remarkup/link-with-tilde.txt
--- a/src/infrastructure/markup/remarkup/__tests__/remarkup/link-with-tilde.txt
+++ b/src/infrastructure/markup/remarkup/__tests__/remarkup/link-with-tilde.txt
@@ -1,5 +1,5 @@
http://www.example.com/~~
~~~~~~~~~~
-
+
~~~~~~~~~~
http://www.example.com/~~
diff --git a/src/infrastructure/markup/remarkup/__tests__/remarkup/link.txt b/src/infrastructure/markup/remarkup/__tests__/remarkup/link.txt
--- a/src/infrastructure/markup/remarkup/__tests__/remarkup/link.txt
+++ b/src/infrastructure/markup/remarkup/__tests__/remarkup/link.txt
@@ -1,5 +1,5 @@
http://www.example.com/
~~~~~~~~~~
-
+
~~~~~~~~~~
http://www.example.com/
diff --git a/src/infrastructure/markup/remarkup/__tests__/remarkup/percent-block-multiline.txt b/src/infrastructure/markup/remarkup/__tests__/remarkup/percent-block-multiline.txt
--- a/src/infrastructure/markup/remarkup/__tests__/remarkup/percent-block-multiline.txt
+++ b/src/infrastructure/markup/remarkup/__tests__/remarkup/percent-block-multiline.txt
@@ -10,7 +10,7 @@
- second
- third
-
+
~~~~~~~~~~
**foo**
diff --git a/src/infrastructure/markup/remarkup/__tests__/remarkup/simple-table-with-link.txt b/src/infrastructure/markup/remarkup/__tests__/remarkup/simple-table-with-link.txt
--- a/src/infrastructure/markup/remarkup/__tests__/remarkup/simple-table-with-link.txt
+++ b/src/infrastructure/markup/remarkup/__tests__/remarkup/simple-table-with-link.txt
@@ -1,7 +1,7 @@
| [[ http://example.com | name ]] | [x] |
~~~~~~~~~~
~~~~~~~~~~
| name | [x] |
diff --git a/src/infrastructure/markup/remarkup/__tests__/remarkup/toc.txt b/src/infrastructure/markup/remarkup/__tests__/remarkup/toc.txt
--- a/src/infrastructure/markup/remarkup/__tests__/remarkup/toc.txt
+++ b/src/infrastructure/markup/remarkup/__tests__/remarkup/toc.txt
@@ -13,11 +13,11 @@
http://www.example.com
-
+
-
+
~~~~~~~~~~
[[ http://www.example.com/ | link_name ]]
=========================================
diff --git a/src/infrastructure/parser/__tests__/PhutilURIHelperTestCase.php b/src/infrastructure/parser/__tests__/PhutilURIHelperTestCase.php
--- a/src/infrastructure/parser/__tests__/PhutilURIHelperTestCase.php
+++ b/src/infrastructure/parser/__tests__/PhutilURIHelperTestCase.php
@@ -4,6 +4,12 @@
public function testPhutilURIHelper() {
+ // Set a test environment.
+ // This is useful to don't rely on your local config.
+ $base = 'https://phorge.localhost';
+ $env = PhabricatorEnv::beginScopedEnv();
+ $env->overrideEnvConfig('phabricator.base-uri', $base);
+
// Every row is a test. Every column is:
// - 0: name of the test
// - 1: test input value
@@ -20,16 +26,14 @@
array('internal root dir', '/#asd', true, false, true),
array('external', 'https://gnu.org/', false, false, false),
array('external anchor', 'https://gnu.org/#asd', false, false, false),
+ array('mail', 'mailto:info@wikipedia.org', false, false, false),
+ array('tel', 'tel:+555555555', false, false, false),
+ array('alien protocol', 'foo://whatever', false, false, false),
+ array('base uri', $base, true, false, false),
+ array('base uri anchor', "{$base}#asd", true, false, false),
+ array('base uri path', "$base/something", true, false, false),
);
- // Add additional self-tests if base URI is available.
- $base = PhabricatorEnv::getEnvConfigIfExists('phabricator.base-uri');
- if ($base) {
- $domain = id(new PhutilURI($base))->getDomain();
- $tests[] = array('base uri', $base, true, false, false);
- $tests[] = array('base uri anchor', "{$base}#asd", true, false, false);
- }
-
foreach ($tests as $test) {
$name = $test[0];
$uri = $test[1];