diff --git a/include/zid.php b/include/zid.php index b74e82930..a48b2864c 100644 --- a/include/zid.php +++ b/include/zid.php @@ -150,28 +150,29 @@ function clean_query_string($s = '') { */ function drop_query_params($s, $p) { + $unescaped = unescape_tags($s); + $parsed = parse_url($unescaped); - $s = unescape_tags($s); - - $parsed = parse_url($s); - $query = ''; - $query_args = null; - - if(isset($parsed['query'])) { - parse_str($parsed['query'], $query_args); + if (empty($parsed['query'])) { + // No query parameters were found, return the original string + return $s; } - if(is_array($query_args)) { - foreach($query_args as $k => $v) { - if(in_array($k, $p)) - continue; - $query .= (($query) ? '&' : '') . urlencode($k) . '=' . urlencode($v); + $query_args = []; + + parse_str($parsed['query'], $query_args); + + foreach($query_args as $k => $v) { + if (in_array($k, $p)) { + unset($query_args[$k]); } } unset($parsed['query']); - if($query) { + $query = http_build_query($query_args, '', '&'); + + if ($query) { $parsed['query'] = $query; } diff --git a/tests/unit/includes/ZidTest.php b/tests/unit/includes/ZidTest.php new file mode 100644 index 000000000..f79bdbf0b --- /dev/null +++ b/tests/unit/includes/ZidTest.php @@ -0,0 +1,38 @@ + + * + * SPDX-License-Identifier: MIT + */ + +namespace Zotlabs\Tests\Unit; + +use PHPUnit\Framework\Attributes\Before; +use Zotlabs\Lib\Libzot; + +class ZidTest extends UnitTestCase { + + /** + * Test the drop_query_params function. + * + * @dataProvider drop_query_params_provider + */ + public function test_drop_query_params(string $url, array $drop_params, string $expected) : void { + $this->assertEquals(escape_tags($expected), drop_query_params($url, $drop_params)); + } + + public static function drop_query_params_provider() : array { + return [ + // Query params with array + ['https://www.example.net/en/pro/detail/some-detail?tx_news_pi1%5Bday%5D=15&tx_news_pi1%5Bmonth%5D=3&tx_news_pi1%5Byear%5D=2026&cHash=85200a0007de8fecd4cd55199146e19c', ['zid', 'f'], 'https://www.example.net/en/pro/detail/some-detail?tx_news_pi1%5Bday%5D=15&tx_news_pi1%5Bmonth%5D=3&tx_news_pi1%5Byear%5D=2026&cHash=85200a0007de8fecd4cd55199146e19c'], + // Query params with zid + ['https://www.example.net/channel/test?zid=test@example.net', ['zid', 'f'], 'https://www.example.net/channel/test'], + // Query params with zid and empty f + ['https://www.example.net/channel/test?f=&zid=test@example.net', ['zid', 'f'], 'https://www.example.net/channel/test'], + // Query params with zid and empty f encoded + ['https://www.example.net/channel/test?f=&zid=test@example.net', ['zid', 'f'], 'https://www.example.net/channel/test'], + ]; + } + +} diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index a478c50fc..571776eb4 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -1,9 +1,9 @@ array( 'name' => 'zotlabs/hubzilla', - 'pretty_version' => 'dev-master', - 'version' => 'dev-master', - 'reference' => '2fb816139a2dbd42a9a0e29804e363d8636ec22f', + 'pretty_version' => 'dev-11.2RC', + 'version' => 'dev-11.2RC', + 'reference' => '955ee217e30e12dec86bdcd936ce10abc3ed366a', 'type' => 'application', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -542,9 +542,9 @@ 'dev_requirement' => false, ), 'zotlabs/hubzilla' => array( - 'pretty_version' => 'dev-master', - 'version' => 'dev-master', - 'reference' => '2fb816139a2dbd42a9a0e29804e363d8636ec22f', + 'pretty_version' => 'dev-11.2RC', + 'version' => 'dev-11.2RC', + 'reference' => '955ee217e30e12dec86bdcd936ce10abc3ed366a', 'type' => 'application', 'install_path' => __DIR__ . '/../../', 'aliases' => array(),