Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2671184
D25847.1734111778.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
20 KB
Referenced Files
None
Subscribers
None
D25847.1734111778.diff
View Options
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,,,>
~~~~~~~~~~
-<p><a href="http://www.zany.com/omg/weird_url,,," class="remarkup-link" target="_blank" rel="noreferrer">http://www.zany.com/omg/weird_url,,,</a></p>
+<p><a href="http://www.zany.com/omg/weird_url,,," class="remarkup-link remarkup-link-ext" target="_blank" rel="noreferrer">http://www.zany.com/omg/weird_url,,,</a></p>
~~~~~~~~~~
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/!
~~~~~~~~~~
-<p><a href="http://www.example.com/" class="remarkup-link" target="_blank" rel="noreferrer">http://www.example.com/</a></p>
+<p><a href="http://www.example.com/" class="remarkup-link remarkup-link-ext" target="_blank" rel="noreferrer">http://www.example.com/</a></p>
-<p>(<a href="http://www.example.com/" class="remarkup-link" target="_blank" rel="noreferrer">http://www.example.com/</a>)</p>
+<p>(<a href="http://www.example.com/" class="remarkup-link remarkup-link-ext" target="_blank" rel="noreferrer">http://www.example.com/</a>)</p>
-<p><a href="http://www.example.com/" class="remarkup-link" target="_blank" rel="noreferrer">http://www.example.com/</a></p>
+<p><a href="http://www.example.com/" class="remarkup-link remarkup-link-ext" target="_blank" rel="noreferrer">http://www.example.com/</a></p>
-<p><a href="http://www.example.com/wiki/example_(disambiguation)" class="remarkup-link" target="_blank" rel="noreferrer">http://www.example.com/wiki/example_(disambiguation)</a></p>
+<p><a href="http://www.example.com/wiki/example_(disambiguation)" class="remarkup-link remarkup-link-ext" target="_blank" rel="noreferrer">http://www.example.com/wiki/example_(disambiguation)</a></p>
-<p>(example <a href="http://www.example.com/" class="remarkup-link" target="_blank" rel="noreferrer">http://www.example.com/</a>)</p>
+<p>(example <a href="http://www.example.com/" class="remarkup-link remarkup-link-ext" target="_blank" rel="noreferrer">http://www.example.com/</a>)</p>
-<p>Quick! <a href="http://www.example.com/" class="remarkup-link" target="_blank" rel="noreferrer">http://www.example.com/</a>!</p>
+<p>Quick! <a href="http://www.example.com/" class="remarkup-link remarkup-link-ext" target="_blank" rel="noreferrer">http://www.example.com/</a>!</p>
~~~~~~~~~~
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]]
~~~~~~~~~~
-<p><a href="mailto:alincoln@example.com" class="remarkup-link" target="_blank" rel="noreferrer">mail me</a></p>
+<p><a href="mailto:alincoln@example.com" class="remarkup-link remarkup-link-ext" target="_blank" rel="noreferrer">mail me</a></p>
-<p><a href="mailto:alincoln@example.com" class="remarkup-link" target="_blank" rel="noreferrer">mail me</a></p>
+<p><a href="mailto:alincoln@example.com" class="remarkup-link remarkup-link-ext" target="_blank" rel="noreferrer">mail me</a></p>
-<p><a href="mailto:alincoln@example.com" class="remarkup-link" target="_blank" rel="noreferrer">alincoln@example.com</a></p>
+<p><a href="mailto:alincoln@example.com" class="remarkup-link remarkup-link-ext" target="_blank" rel="noreferrer">alincoln@example.com</a></p>
~~~~~~~~~~
mail me <alincoln@example.com>
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 @@
<http://www.example.com/ [[http://www.example.net/ | Example]]>
~~~~~~~~~~
-<p><a href="http://www.example.com/" class="remarkup-link" target="_blank" rel="noreferrer">Example</a>(<a href="http://www.alternate.org/" class="remarkup-link" target="_blank" rel="noreferrer">http://www.alternate.org/</a>)</p>
+<p><a href="http://www.example.com/" class="remarkup-link remarkup-link-ext" target="_blank" rel="noreferrer">Example</a>(<a href="http://www.alternate.org/" class="remarkup-link remarkup-link-ext" target="_blank" rel="noreferrer">http://www.alternate.org/</a>)</p>
-<p>(<a href="http://www.alternate.org/" class="remarkup-link" target="_blank" rel="noreferrer">http://www.alternate.org/</a>)<a href="http://www.example.com/" class="remarkup-link" target="_blank" rel="noreferrer">Example</a></p>
+<p>(<a href="http://www.alternate.org/" class="remarkup-link remarkup-link-ext" target="_blank" rel="noreferrer">http://www.alternate.org/</a>)<a href="http://www.example.com/" class="remarkup-link remarkup-link-ext" target="_blank" rel="noreferrer">Example</a></p>
-<p><<a href="http://www.example.com/" class="remarkup-link" target="_blank" rel="noreferrer">http://www.example.com/</a> <a href="http://www.example.net/" class="remarkup-link" target="_blank" rel="noreferrer">Example</a>></p>
+<p><<a href="http://www.example.com/" class="remarkup-link remarkup-link-ext" target="_blank" rel="noreferrer">http://www.example.com/</a> <a href="http://www.example.net/" class="remarkup-link remarkup-link-ext" target="_blank" rel="noreferrer">Example</a>></p>
~~~~~~~~~~
Example <http://www.example.com/>(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 ]]
~~~~~~~~~~
-<p><a href="/\evil.com" class="remarkup-link" target="_blank" rel="noreferrer">/\evil.com</a></p>
+<p>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...</p>
+
+<p><a href="/\evil.com" class="remarkup-link" rel="noreferrer">/\evil.com</a></p>
<p><a href="/
-/evil.com" class="remarkup-link" target="_blank" rel="noreferrer">/
+/evil.com" class="remarkup-link" rel="noreferrer">/
/evil.com</a></p>
~~~~~~~~~~
+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/
~~~~~~~~~~
-<p><a href="http://www.example.com/" class="remarkup-link" rel="noreferrer">http://www.example.com/</a></p>
+<p><a href="http://www.example.com/" class="remarkup-link remarkup-link-ext" rel="noreferrer">http://www.example.com/</a></p>
-<p><a href="http://www.example.com/" class="remarkup-link" rel="noreferrer">http://www.example.com/</a></p>
+<p><a href="http://www.example.com/" class="remarkup-link remarkup-link-ext" rel="noreferrer">http://www.example.com/</a></p>
~~~~~~~~~~
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 ]]
~~~~~~~~~~
-<p><a href="http://www.example.com/" class="remarkup-link" target="_blank" rel="noreferrer">http://www.example.com/</a></p>
+<p><a href="http://www.example.com/" class="remarkup-link remarkup-link-ext" target="_blank" rel="noreferrer">http://www.example.com/</a></p>
-<p><a href="http://www.example.com/" class="remarkup-link" target="_blank" rel="noreferrer">example.com</a></p>
+<p><a href="http://www.example.com/" class="remarkup-link remarkup-link-ext" target="_blank" rel="noreferrer">example.com</a></p>
-<p><a href="http://www.example.com/x/" class="remarkup-link" target="_blank" rel="noreferrer">http://www.example.com/x/</a></p>
+<p><a href="http://www.example.com/x/" class="remarkup-link" rel="noreferrer">http://www.example.com/x/</a></p>
<p><a href="http://www.example.com/page/#anchor" class="remarkup-link" rel="noreferrer">http://www.example.com/page/#anchor</a></p>
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]]
~~~~~~~~~~
-<p><a href="tel:18005555555" class="remarkup-link" target="_blank" rel="noreferrer">call me</a></p>
+<p><a href="tel:18005555555" class="remarkup-link remarkup-link-ext" target="_blank" rel="noreferrer">call me</a></p>
-<p><a href="tel:18005555555" class="remarkup-link" target="_blank" rel="noreferrer">call me</a></p>
+<p><a href="tel:18005555555" class="remarkup-link remarkup-link-ext" target="_blank" rel="noreferrer">call me</a></p>
-<p><a href="tel:18005555555" class="remarkup-link" target="_blank" rel="noreferrer">18005555555</a></p>
+<p><a href="tel:18005555555" class="remarkup-link remarkup-link-ext" target="_blank" rel="noreferrer">18005555555</a></p>
~~~~~~~~~~
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/!!!
~~~~~~~~~~
-<p><a href="http://www.example.com/" class="remarkup-link" target="_blank" rel="noreferrer">http://www.example.com/</a>,
-<a href="http://www.example.com/" class="remarkup-link" target="_blank" rel="noreferrer">http://www.example.com/</a>..
-<a href="http://www.example.com/" class="remarkup-link" target="_blank" rel="noreferrer">http://www.example.com/</a>!!!</p>
+<p><a href="http://www.example.com/" class="remarkup-link remarkup-link-ext" target="_blank" rel="noreferrer">http://www.example.com/</a>,
+<a href="http://www.example.com/" class="remarkup-link remarkup-link-ext" target="_blank" rel="noreferrer">http://www.example.com/</a>..
+<a href="http://www.example.com/" class="remarkup-link remarkup-link-ext" target="_blank" rel="noreferrer">http://www.example.com/</a>!!!</p>
~~~~~~~~~~
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/~~
~~~~~~~~~~
-<p><a href="http://www.example.com/~" class="remarkup-link" target="_blank" rel="noreferrer">http://www.example.com/~</a></p>
+<p><a href="http://www.example.com/~" class="remarkup-link remarkup-link-ext" target="_blank" rel="noreferrer">http://www.example.com/~</a></p>
~~~~~~~~~~
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/
~~~~~~~~~~
-<p><a href="http://www.example.com/" class="remarkup-link" target="_blank" rel="noreferrer">http://www.example.com/</a></p>
+<p><a href="http://www.example.com/" class="remarkup-link remarkup-link-ext" target="_blank" rel="noreferrer">http://www.example.com/</a></p>
~~~~~~~~~~
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 @@
<br />- second
<br />- third</p>
-<p><a href="http://hello" class="remarkup-link" target="_blank" rel="noreferrer">world</a></p>
+<p><a href="http://hello" class="remarkup-link remarkup-link-ext" target="_blank" rel="noreferrer">world</a></p>
~~~~~~~~~~
**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] |
~~~~~~~~~~
<div class="remarkup-table-wrap"><table class="remarkup-table">
-<tr><td><a href="http://example.com" class="remarkup-link" target="_blank" rel="noreferrer">name</a></td><td>[x]</td></tr>
+<tr><td><a href="http://example.com" class="remarkup-link remarkup-link-ext" target="_blank" rel="noreferrer">name</a></td><td>[x]</td></tr>
</table></div>
~~~~~~~~~~
| name <http://example.com> | [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 @@
<li><a href="#http-www-example-com">http://www.example.com</a></li>
</ul>
-<h2 class="remarkup-header"><a name="link-name"></a><a href="http://www.example.com/" class="remarkup-link" target="_blank" rel="noreferrer">link_name</a></h2>
+<h2 class="remarkup-header"><a name="link-name"></a><a href="http://www.example.com/" class="remarkup-link remarkup-link-ext" target="_blank" rel="noreferrer">link_name</a></h2>
<h3 class="remarkup-header"><a name="bold"></a><strong>bold</strong></h3>
-<h2 class="remarkup-header"><a name="http-www-example-com"></a><a href="http://www.example.com" class="remarkup-link" target="_blank" rel="noreferrer">http://www.example.com</a></h2>
+<h2 class="remarkup-header"><a name="http-www-example-com"></a><a href="http://www.example.com" class="remarkup-link remarkup-link-ext" target="_blank" rel="noreferrer">http://www.example.com</a></h2>
~~~~~~~~~~
[[ 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];
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Dec 13, 17:42 (20 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1008386
Default Alt Text
D25847.1734111778.diff (20 KB)
Attached To
Mode
D25847: Fix regression in Remarkup unit tests and harden
Attached
Detach File
Event Timeline
Log In to Comment