aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2024-03-05 20:52:16 +0100
committerHarald Eilertsen <haraldei@anduin.net>2024-05-01 20:57:56 +0200
commit630cecd740762cc6111468b46644fcae85a360b3 (patch)
treec478b6563a54f75c2b72838a70820f708d6793be
parentb6e6cecf70e4d91f00f190be7bd852beceefe803 (diff)
downloadvolse-hubzilla-630cecd740762cc6111468b46644fcae85a360b3.tar.gz
volse-hubzilla-630cecd740762cc6111468b46644fcae85a360b3.tar.bz2
volse-hubzilla-630cecd740762cc6111468b46644fcae85a360b3.zip
Libzot: get_rpost_path was broken for URL's with no port.
-rw-r--r--Zotlabs/Lib/Libzot.php9
-rw-r--r--tests/unit/Lib/ZotlibTest.php34
2 files changed, 41 insertions, 2 deletions
diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php
index 89157bf5e..bc944c97c 100644
--- a/Zotlabs/Lib/Libzot.php
+++ b/Zotlabs/Lib/Libzot.php
@@ -2569,9 +2569,14 @@ class Libzot {
if (!$observer)
return '';
- $parsed = parse_url($observer['xchan_url']);
+ $url = $observer['xchan_url'];
+ if (preg_match('|^https?://|', $url) === 0) {
+ $url = "https://{$url}";
+ }
+
+ $parsed = parse_url($url);
- return $parsed['scheme'] . '://' . $parsed['host'] . (($parsed['port']) ? ':' . $parsed['port'] : '') . '/rpost?f=';
+ return $parsed['scheme'] . '://' . $parsed['host'] . (isset($parsed['port']) ? ':' . $parsed['port'] : '') . '/rpost?f=';
}
/**
diff --git a/tests/unit/Lib/ZotlibTest.php b/tests/unit/Lib/ZotlibTest.php
new file mode 100644
index 000000000..05522678f
--- /dev/null
+++ b/tests/unit/Lib/ZotlibTest.php
@@ -0,0 +1,34 @@
+<?php
+class LibzotTest extends \Zotlabs\Tests\Unit\UnitTestCase {
+ /**
+ * Test the `get_rpost_path` function.
+ *
+ * @dataProvider get_rpost_path_provider
+ */
+ public function test_get_rpost_path(string $expected, string $xchan_url) : void {
+ $observer = [ 'xchan_url' => $xchan_url ];
+
+ $this->assertEquals($expected, \Zotlabs\Lib\Libzot::get_rpost_path($observer));
+ }
+
+ private function get_rpost_path_provider() : array {
+ return [
+ 'xchan_url without port' => [
+ 'https://example.com/rpost?f=',
+ 'https://example.com'
+ ],
+ 'xchan_url with port' => [
+ 'https://example.com:666/rpost?f=',
+ 'https://example.com:666'
+ ],
+ 'xchan_url ignores path and args' => [
+ 'https://example.com/rpost?f=',
+ 'https://example.com/path?arg1=balle'
+ ],
+ 'xchan_url with no scheme should default to https' => [
+ 'https://example.com/rpost?f=',
+ 'example.com',
+ ],
+ ];
+ }
+}