From 043e04f484c1fbaf4444454ba08b2c769ca2761c Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 9 Sep 2020 00:12:36 -0400 Subject: [PATCH 1/5] Remove confirm template obsolete uses (except for contacts) - Remove obsolete explode_querystring() function - Remove $extra_inputs template variable --- boot.php | 32 ------------------------ mod/item.php | 36 ++------------------------- mod/message.php | 30 ---------------------- mod/photos.php | 2 -- mod/settings.php | 20 --------------- src/Content/Pager.php | 2 +- src/Core/Addon.php | 2 -- src/Module/Contact.php | 14 +---------- view/templates/confirm.tpl | 3 --- view/theme/frio/templates/confirm.tpl | 3 --- 10 files changed, 4 insertions(+), 140 deletions(-) diff --git a/boot.php b/boot.php index 95a9ff13d0..24e7559515 100644 --- a/boot.php +++ b/boot.php @@ -382,38 +382,6 @@ function is_site_admin() return local_user() && $admin_email && in_array($a->user['email'] ?? '', $adminlist); } -function explode_querystring($query) -{ - $arg_st = strpos($query, '?'); - if ($arg_st !== false) { - $base = substr($query, 0, $arg_st); - $arg_st += 1; - } else { - $base = ''; - $arg_st = 0; - } - - $args = explode('&', substr($query, $arg_st)); - foreach ($args as $k => $arg) { - /// @TODO really compare type-safe here? - if ($arg === '') { - unset($args[$k]); - } - } - $args = array_values($args); - - if (!$base) { - $base = $args[0]; - unset($args[0]); - $args = array_values($args); - } - - return [ - 'base' => $base, - 'args' => $args, - ]; -} - /** * Returns the complete URL of the current page, e.g.: http(s)://something.com/network * diff --git a/mod/item.php b/mod/item.php index 3474bea90c..911a9530c9 100644 --- a/mod/item.php +++ b/mod/item.php @@ -904,40 +904,8 @@ function drop_item(int $id, string $return = '') } if ((local_user() == $item['uid']) || $contact_id) { - // Check if we should do HTML-based delete confirmation - if (!empty($_REQUEST['confirm'])) { - //
can't take arguments in its "action" parameter - // so add any arguments as hidden inputs - $query = explode_querystring(DI::args()->getQueryString()); - $inputs = []; - - foreach ($query['args'] as $arg) { - if (strpos($arg, 'confirm=') === false) { - $arg_parts = explode('=', $arg); - $inputs[] = ['name' => $arg_parts[0], 'value' => $arg_parts[1]]; - } - } - - return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [ - '$method' => 'get', - '$message' => DI::l10n()->t('Do you really want to delete this item?'), - '$extra_inputs' => $inputs, - '$confirm' => DI::l10n()->t('Yes'), - '$confirm_url' => $query['base'], - '$confirm_name' => 'confirmed', - '$cancel' => DI::l10n()->t('Cancel'), - ]); - } - // Now check how the user responded to the confirmation query - if (!empty($_REQUEST['canceled'])) { - DI::baseUrl()->redirect('display/' . $item['guid']); - } - - $is_comment = $item['gravity'] == GRAVITY_COMMENT; - $parentitem = null; if (!empty($item['parent'])) { - $fields = ['guid']; - $parentitem = Item::selectFirstForUser(local_user(), $fields, ['id' => $item['parent']]); + $parentitem = Item::selectFirstForUser(local_user(), ['guid'], ['id' => $item['parent']]); } // delete the item @@ -949,7 +917,7 @@ function drop_item(int $id, string $return = '') $return_url = str_replace("update_", "", $return_url); // Check if delete a comment - if ($is_comment) { + if ($item['gravity'] == GRAVITY_COMMENT) { // Return to parent guid if (!empty($parentitem)) { DI::baseUrl()->redirect('display/' . $parentitem['guid']); diff --git a/mod/message.php b/mod/message.php index 6326bb9ea5..4f680aa0b7 100644 --- a/mod/message.php +++ b/mod/message.php @@ -141,36 +141,6 @@ function message_content(App $a) return; } - // Check if we should do HTML-based delete confirmation - if (!empty($_REQUEST['confirm'])) { - // can't take arguments in its "action" parameter - // so add any arguments as hidden inputs - $query = explode_querystring(DI::args()->getQueryString()); - $inputs = []; - foreach ($query['args'] as $arg) { - if (strpos($arg, 'confirm=') === false) { - $arg_parts = explode('=', $arg); - $inputs[] = ['name' => $arg_parts[0], 'value' => $arg_parts[1]]; - } - } - - //DI::page()['aside'] = ''; - return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [ - '$method' => 'get', - '$message' => DI::l10n()->t('Do you really want to delete this message?'), - '$extra_inputs' => $inputs, - '$confirm' => DI::l10n()->t('Yes'), - '$confirm_url' => $query['base'], - '$confirm_name' => 'confirmed', - '$cancel' => DI::l10n()->t('Cancel'), - ]); - } - - // Now check how the user responded to the confirmation query - if (!empty($_REQUEST['canceled'])) { - DI::baseUrl()->redirect('message'); - } - $cmd = $a->argv[1]; if ($cmd === 'drop') { $message = DBA::selectFirst('mail', ['convid'], ['id' => $a->argv[2], 'uid' => local_user()]); diff --git a/mod/photos.php b/mod/photos.php index f078473a95..3b2fa0c3a8 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -1039,7 +1039,6 @@ function photos_content(App $a) return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [ '$method' => 'post', '$message' => DI::l10n()->t('Do you really want to delete this photo album and all its photos?'), - '$extra_inputs' => [], '$confirm' => DI::l10n()->t('Delete Album'), '$confirm_url' => $drop_url, '$confirm_name' => 'dropalbum', @@ -1146,7 +1145,6 @@ function photos_content(App $a) return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [ '$method' => 'post', '$message' => DI::l10n()->t('Do you really want to delete this photo?'), - '$extra_inputs' => [], '$confirm' => DI::l10n()->t('Delete Photo'), '$confirm_url' => $drop_url, '$confirm_name' => 'delete', diff --git a/mod/settings.php b/mod/settings.php index 39667af92f..92a7bb461f 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -829,26 +829,6 @@ function settings_content(App $a) $stpl = Renderer::getMarkupTemplate('settings/settings.tpl'); - // Private/public post links for the non-JS ACL form - $private_post = 1; - if (!empty($_REQUEST['public']) && !$_REQUEST['public']) { - $private_post = 0; - } - - $query_str = DI::args()->getQueryString(); - if (strpos($query_str, 'public=1') !== false) { - $query_str = str_replace(['?public=1', '&public=1'], ['', ''], $query_str); - } - - // I think $a->query_string may never have ? in it, but I could be wrong - // It looks like it's from the index.php?q=[etc] rewrite that the web - // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61 - if (strpos($query_str, '?') === false) { - $public_post_link = '?public=1'; - } else { - $public_post_link = '&public=1'; - } - /* Installed langs */ $lang_choices = DI::l10n()->getAvailableLanguages(); diff --git a/src/Content/Pager.php b/src/Content/Pager.php index a5e61bbf9f..477e535aec 100644 --- a/src/Content/Pager.php +++ b/src/Content/Pager.php @@ -128,7 +128,7 @@ class Pager /** * Sets the base query string from a full query string. * - * Strips the 'page' parameter, and remove the 'q=' string for some reason. + * Strips the 'page' parameter * * @param string $queryString */ diff --git a/src/Core/Addon.php b/src/Core/Addon.php index 0462504e70..8b95af328c 100644 --- a/src/Core/Addon.php +++ b/src/Core/Addon.php @@ -229,8 +229,6 @@ class Addon */ public static function getInfo($addon) { - $a = DI::app(); - $addon = Strings::sanitizeFilePathItem($addon); $info = [ diff --git a/src/Module/Contact.php b/src/Module/Contact.php index 6e8778f179..03d67aa089 100644 --- a/src/Module/Contact.php +++ b/src/Module/Contact.php @@ -436,17 +436,6 @@ class Contact extends BaseModule if ($cmd === 'drop' && ($orig_record['uid'] != 0)) { // Check if we should do HTML-based delete confirmation if (!empty($_REQUEST['confirm'])) { - // can't take arguments in its 'action' parameter - // so add any arguments as hidden inputs - $query = explode_querystring(DI::args()->getQueryString()); - $inputs = []; - foreach ($query['args'] as $arg) { - if (strpos($arg, 'confirm=') === false) { - $arg_parts = explode('=', $arg); - $inputs[] = ['name' => $arg_parts[0], 'value' => $arg_parts[1]]; - } - } - DI::page()['aside'] = ''; return Renderer::replaceMacros(Renderer::getMarkupTemplate('contact_drop_confirm.tpl'), [ @@ -454,9 +443,8 @@ class Contact extends BaseModule '$contact' => self::getContactTemplateVars($orig_record), '$method' => 'get', '$message' => DI::l10n()->t('Do you really want to delete this contact?'), - '$extra_inputs' => $inputs, '$confirm' => DI::l10n()->t('Yes'), - '$confirm_url' => $query['base'], + '$confirm_url' => DI::args()->getCommand(), '$confirm_name' => 'confirmed', '$cancel' => DI::l10n()->t('Cancel'), ]); diff --git a/view/templates/confirm.tpl b/view/templates/confirm.tpl index 496724e3d9..ea50846990 100644 --- a/view/templates/confirm.tpl +++ b/view/templates/confirm.tpl @@ -3,9 +3,6 @@

{{$message}}

- {{foreach $extra_inputs as $input}} - - {{/foreach}} diff --git a/view/theme/frio/templates/confirm.tpl b/view/theme/frio/templates/confirm.tpl index 36072a56b1..d17b94d760 100644 --- a/view/theme/frio/templates/confirm.tpl +++ b/view/theme/frio/templates/confirm.tpl @@ -1,9 +1,6 @@
{{$message}}
- {{foreach $extra_inputs as $input}} - - {{/foreach}}
From e23f3a645a35097dcb361928cbf3b1b986080ad1 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 9 Sep 2020 00:13:11 -0400 Subject: [PATCH 2/5] Add profile page aliases to routes --- static/routes.config.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/static/routes.config.php b/static/routes.config.php index 8f59ecb7a6..6f48500063 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -30,6 +30,14 @@ use Friendica\App\Router as R; use Friendica\Module; +$profileRoutes = [ + '' => [Module\Profile\Index::class, [R::GET]], + '/profile' => [Module\Profile\Profile::class, [R::GET]], + '/contacts/common' => [Module\Profile\Common::class, [R::GET]], + '/contacts[/{type}]' => [Module\Profile\Contacts::class, [R::GET]], + '/status[/{category}[/{date1}[/{date2}]]]' => [Module\Profile\Status::class, [R::GET]], +]; + return [ '/' => [Module\Home::class, [R::GET]], @@ -250,13 +258,9 @@ return [ '/pretheme' => [Module\ThemeDetails::class, [R::GET]], '/probe' => [Module\Debug\Probe::class, [R::GET]], - '/profile' => [ - '/{nickname}' => [Module\Profile\Index::class, [R::GET]], - '/{nickname}/profile' => [Module\Profile\Profile::class, [R::GET]], - '/{nickname}/contacts/common' => [Module\Profile\Common::class, [R::GET]], - '/{nickname}/contacts[/{type}]' => [Module\Profile\Contacts::class, [R::GET]], - '/{nickname}/status[/{category}[/{date1}[/{date2}]]]' => [Module\Profile\Status::class, [R::GET]], - ], + '/profile/{nickname}' => $profileRoutes, + '/u/{nickname}' => $profileRoutes, + '/~{nickname}' => $profileRoutes, '/proxy' => [ '[/]' => [Module\Proxy::class, [R::GET]], From bbefc61a0cf36da6a02a3ed459b4434dfd3b0998 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 9 Sep 2020 00:15:25 -0400 Subject: [PATCH 3/5] Use Arguments->getCommand() where it makes more sense than getQueryString() - Remove a couple of intermediary query string variables --- include/api.php | 10 +++++----- include/conversation.php | 7 +------ mod/network.php | 4 +--- src/Module/BaseApi.php | 6 +++--- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/include/api.php b/include/api.php index 5ae4754b57..643f57b634 100644 --- a/include/api.php +++ b/include/api.php @@ -311,22 +311,22 @@ function api_call(App $a, App\Arguments $args = null) } $type = "json"; - if (strpos($args->getQueryString(), ".xml") > 0) { + if (strpos($args->getCommand(), ".xml") > 0) { $type = "xml"; } - if (strpos($args->getQueryString(), ".json") > 0) { + if (strpos($args->getCommand(), ".json") > 0) { $type = "json"; } - if (strpos($args->getQueryString(), ".rss") > 0) { + if (strpos($args->getCommand(), ".rss") > 0) { $type = "rss"; } - if (strpos($args->getQueryString(), ".atom") > 0) { + if (strpos($args->getCommand(), ".atom") > 0) { $type = "atom"; } try { foreach ($API as $p => $info) { - if (strpos($args->getQueryString(), $p) === 0) { + if (strpos($args->getCommand(), $p) === 0) { if (!api_check_method($info['method'])) { throw new MethodNotAllowedException(); } diff --git a/include/conversation.php b/include/conversation.php index 4afc7c699d..bd1e038229 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -1148,17 +1148,12 @@ function status_editor(App $a, $x, $notes_cid = 0, $popup = false) $jotplugins = ''; Hook::callAll('jot_tool', $jotplugins); - $query_str = DI::args()->getQueryString(); - if (strpos($query_str, 'public=1') !== false) { - $query_str = str_replace(['?public=1', '&public=1'], ['', ''], $query_str); - } - // $tpl = Renderer::replaceMacros($tpl,array('$jotplugins' => $jotplugins)); $tpl = Renderer::getMarkupTemplate("jot.tpl"); $o .= Renderer::replaceMacros($tpl,[ '$new_post' => DI::l10n()->t('New Post'), - '$return_path' => $query_str, + '$return_path' => DI::args()->getQueryString(), '$action' => 'item', '$share' => ($x['button'] ?? '') ?: DI::l10n()->t('Share'), '$loading' => DI::l10n()->t('Loading...'), diff --git a/mod/network.php b/mod/network.php index 48f250e44c..60bb409e32 100644 --- a/mod/network.php +++ b/mod/network.php @@ -635,9 +635,7 @@ function network_display_post($a, $pager, $mark_all, $update, $ordering, $items) $parents_str = implode(', ', $parents_arr); } - $query_string = DI::args()->getQueryString(); - - $pager->setQueryString($query_string); + $pager->setQueryString(DI::args()->getQueryString()); // We aren't going to try and figure out at the item, group, and page // level which items you've seen and which you haven't. If you're looking diff --git a/src/Module/BaseApi.php b/src/Module/BaseApi.php index 5a5326756d..75791e0eae 100644 --- a/src/Module/BaseApi.php +++ b/src/Module/BaseApi.php @@ -42,13 +42,13 @@ class BaseApi extends BaseModule { $arguments = DI::args(); - if (substr($arguments->getQueryString(), -4) === '.xml') { + if (substr($arguments->getCommand(), -4) === '.xml') { self::$format = 'xml'; } - if (substr($arguments->getQueryString(), -4) === '.rss') { + if (substr($arguments->getCommand(), -4) === '.rss') { self::$format = 'rss'; } - if (substr($arguments->getQueryString(), -4) === '.atom') { + if (substr($arguments->getCommand(), -4) === '.atom') { self::$format = 'atom'; } } From d1942afbca1c47e5e504b2ba4debfb9639009dc6 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 9 Sep 2020 00:21:04 -0400 Subject: [PATCH 4/5] Stop using q as a page parameter --- tests/legacy/ApiTest.php | 18 +++++++++--------- view/templates/install_checks.tpl | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/legacy/ApiTest.php b/tests/legacy/ApiTest.php index ddeb40192a..f6f23263e5 100644 --- a/tests/legacy/ApiTest.php +++ b/tests/legacy/ApiTest.php @@ -417,7 +417,7 @@ class ApiTest extends FixtureTest } ]; $_SERVER['REQUEST_METHOD'] = 'method'; - $_SERVER['QUERY_STRING'] = 'q=api_path'; + $_SERVER['QUERY_STRING'] = 'pagename=api_path'; $_GET['callback'] = 'callback_name'; $args = DI::args()->determine($_SERVER, $_GET); @@ -445,7 +445,7 @@ class ApiTest extends FixtureTest ]; $_SERVER['REQUEST_METHOD'] = 'method'; - $_SERVER['QUERY_STRING'] = 'q=api_path'; + $_SERVER['QUERY_STRING'] = 'pagename=api_path'; $args = DI::args()->determine($_SERVER, $_GET); @@ -481,7 +481,7 @@ class ApiTest extends FixtureTest } ]; $_SERVER['REQUEST_METHOD'] = 'method'; - $_SERVER['QUERY_STRING'] = 'q=api_path'; + $_SERVER['QUERY_STRING'] = 'pagename=api_path'; $args = DI::args()->determine($_SERVER, $_GET); @@ -521,7 +521,7 @@ class ApiTest extends FixtureTest } ]; $_SERVER['REQUEST_METHOD'] = 'method'; - $_SERVER['QUERY_STRING'] = 'q=api_path.json'; + $_SERVER['QUERY_STRING'] = 'pagename=api_path.json'; $args = DI::args()->determine($_SERVER, $_GET); @@ -547,7 +547,7 @@ class ApiTest extends FixtureTest } ]; $_SERVER['REQUEST_METHOD'] = 'method'; - $_SERVER['QUERY_STRING'] = 'q=api_path.xml'; + $_SERVER['QUERY_STRING'] = 'pagename=api_path.xml'; $args = DI::args()->determine($_SERVER, $_GET); @@ -573,7 +573,7 @@ class ApiTest extends FixtureTest } ]; $_SERVER['REQUEST_METHOD'] = 'method'; - $_SERVER['QUERY_STRING'] = 'q=api_path.rss'; + $_SERVER['QUERY_STRING'] = 'pagename=api_path.rss'; $args = DI::args()->determine($_SERVER, $_GET); @@ -600,7 +600,7 @@ class ApiTest extends FixtureTest } ]; $_SERVER['REQUEST_METHOD'] = 'method'; - $_SERVER['QUERY_STRING'] = 'q=api_path.atom'; + $_SERVER['QUERY_STRING'] = 'pagename=api_path.atom'; $args = DI::args()->determine($_SERVER, $_GET); @@ -622,7 +622,7 @@ class ApiTest extends FixtureTest global $API; $API['api_path'] = ['method' => 'method']; - $_SERVER['QUERY_STRING'] = 'q=api_path'; + $_SERVER['QUERY_STRING'] = 'pagename=api_path'; $args = DI::args()->determine($_SERVER, $_GET); @@ -647,7 +647,7 @@ class ApiTest extends FixtureTest ]; $_SESSION['authenticated'] = false; $_SERVER['REQUEST_METHOD'] = 'method'; - $_SERVER['QUERY_STRING'] = 'q=api_path'; + $_SERVER['QUERY_STRING'] = 'pagename=api_path'; $args = DI::args()->determine($_SERVER, $_GET); diff --git a/view/templates/install_checks.tpl b/view/templates/install_checks.tpl index e8b4522eb0..49ca670599 100644 --- a/view/templates/install_checks.tpl +++ b/view/templates/install_checks.tpl @@ -1,7 +1,7 @@

{{$title}}

{{$pass}}

- + {{foreach $checks as $check}}
{{$check.title nofilter}} From 1b681222a44bed72c2cbca53fcd1583d89ff3dcc Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 9 Sep 2020 00:24:44 -0400 Subject: [PATCH 5/5] Ensure query parameters are URL encoded in Arguments - Simplify Arguments->determine - Remove stripZRLs and stripQueryParam Arguments methods - Updated tests --- src/App/Arguments.php | 89 +++++++-------------------- tests/legacy/ApiTest.php | 2 +- tests/src/App/ArgumentsTest.php | 106 ++++++++++++++++---------------- 3 files changed, 74 insertions(+), 123 deletions(-) diff --git a/src/App/Arguments.php b/src/App/Arguments.php index e2f60b1956..de3fecf9ed 100644 --- a/src/App/Arguments.php +++ b/src/App/Arguments.php @@ -47,7 +47,7 @@ class Arguments */ private $argc; - public function __construct(string $queryString = '', string $command = '', array $argv = [Module::DEFAULT], int $argc = 1) + public function __construct(string $queryString = '', string $command = '', array $argv = [], int $argc = 0) { $this->queryString = $queryString; $this->command = $command; @@ -56,7 +56,7 @@ class Arguments } /** - * @return string The whole query string of this call + * @return string The whole query string of this call with url-encoded query parameters */ public function getQueryString() { @@ -121,50 +121,27 @@ class Arguments */ public function determine(array $server, array $get) { - $queryString = ''; + // removing leading / - maybe a nginx problem + $server['QUERY_STRING'] = ltrim($server['QUERY_STRING'] ?? '', '/'); - if (!empty($server['QUERY_STRING']) && strpos($server['QUERY_STRING'], 'pagename=') === 0) { - $queryString = urldecode(substr($server['QUERY_STRING'], 9)); - } elseif (!empty($server['QUERY_STRING']) && strpos($server['QUERY_STRING'], 'q=') === 0) { - $queryString = urldecode(substr($server['QUERY_STRING'], 2)); - } - - // eventually strip ZRL - $queryString = $this->stripZRLs($queryString); - - // eventually strip OWT - $queryString = $this->stripQueryParam($queryString, 'owt'); - - // removing trailing / - maybe a nginx problem - $queryString = ltrim($queryString, '/'); + $queryParameters = []; + parse_str($server['QUERY_STRING'], $queryParameters); if (!empty($get['pagename'])) { $command = trim($get['pagename'], '/\\'); + } elseif (!empty($queryParameters['pagename'])) { + $command = trim($queryParameters['pagename'], '/\\'); } elseif (!empty($get['q'])) { + // Legacy page name parameter, now conflicts with the search query parameter $command = trim($get['q'], '/\\'); } else { - $command = Module::DEFAULT; + $command = ''; } - - // fix query_string - if (!empty($command)) { - $queryString = str_replace( - $command . '&', - $command . '?', - $queryString - ); - } - - // unix style "homedir" - if (substr($command, 0, 1) === '~') { - $command = 'profile/' . substr($command, 1); - } - - // Diaspora style profile url - if (substr($command, 0, 2) === 'u/') { - $command = 'profile/' . substr($command, 2); - } + // Remove generated and one-time use parameters + unset($queryParameters['pagename']); + unset($queryParameters['zrl']); + unset($queryParameters['owt']); /* * Break the URL path into C style argc/argv style arguments for our @@ -173,41 +150,17 @@ class Arguments * [0] => 'module' * [1] => 'arg1' * [2] => 'arg2' - * - * - * There will always be one argument. If provided a naked domain - * URL, $this->argv[0] is set to "home". */ + if ($command) { + $argv = explode('/', $command); + } else { + $argv = []; + } - $argv = explode('/', $command); $argc = count($argv); + $queryString = $command . ($queryParameters ? '?' . http_build_query($queryParameters) : ''); return new Arguments($queryString, $command, $argv, $argc); } - - /** - * Strip zrl parameter from a string. - * - * @param string $queryString The input string. - * - * @return string The zrl. - */ - public function stripZRLs(string $queryString) - { - return preg_replace('/[?&]zrl=(.*?)(&|$)/ism', '$2', $queryString); - } - - /** - * Strip query parameter from a string. - * - * @param string $queryString The input string. - * @param string $param - * - * @return string The query parameter. - */ - public function stripQueryParam(string $queryString, string $param) - { - return preg_replace('/[?&]' . $param . '=(.*?)(&|$)/ism', '$2', $queryString); - } -} \ No newline at end of file +} diff --git a/tests/legacy/ApiTest.php b/tests/legacy/ApiTest.php index f6f23263e5..1ff66efb6a 100644 --- a/tests/legacy/ApiTest.php +++ b/tests/legacy/ApiTest.php @@ -75,7 +75,7 @@ class ApiTest extends FixtureTest $this->app = DI::app(); $this->app->argc = 1; - $this->app->argv = ['home']; + $this->app->argv = ['']; // User data that the test database is populated with $this->selfUser = [ diff --git a/tests/src/App/ArgumentsTest.php b/tests/src/App/ArgumentsTest.php index a7ef451d98..9a1b5bdad8 100644 --- a/tests/src/App/ArgumentsTest.php +++ b/tests/src/App/ArgumentsTest.php @@ -45,8 +45,8 @@ class ArgumentsTest extends TestCase $this->assertArguments([ 'queryString' => '', 'command' => '', - 'argv' => ['home'], - 'argc' => 1, + 'argv' => [], + 'argc' => 0, ], $arguments); } @@ -55,34 +55,6 @@ class ArgumentsTest extends TestCase { return [ 'withPagename' => [ - 'assert' => [ - 'queryString' => 'profile/test/it?arg1=value1&arg2=value2', - 'command' => 'profile/test/it', - 'argv' => ['profile', 'test', 'it'], - 'argc' => 3, - ], - 'server' => [ - 'QUERY_STRING' => 'pagename=profile/test/it?arg1=value1&arg2=value2', - ], - 'get' => [ - 'pagename' => 'profile/test/it', - ], - ], - 'withQ' => [ - 'assert' => [ - 'queryString' => 'profile/test/it?arg1=value1&arg2=value2', - 'command' => 'profile/test/it', - 'argv' => ['profile', 'test', 'it'], - 'argc' => 3, - ], - 'server' => [ - 'QUERY_STRING' => 'q=profile/test/it?arg1=value1&arg2=value2', - ], - 'get' => [ - 'q' => 'profile/test/it', - ], - ], - 'withWrongDelimiter' => [ 'assert' => [ 'queryString' => 'profile/test/it?arg1=value1&arg2=value2', 'command' => 'profile/test/it', @@ -99,12 +71,12 @@ class ArgumentsTest extends TestCase 'withUnixHomeDir' => [ 'assert' => [ 'queryString' => '~test/it?arg1=value1&arg2=value2', - 'command' => 'profile/test/it', - 'argv' => ['profile', 'test', 'it'], - 'argc' => 3, + 'command' => '~test/it', + 'argv' => ['~test', 'it'], + 'argc' => 2, ], 'server' => [ - 'QUERY_STRING' => 'pagename=~test/it?arg1=value1&arg2=value2', + 'QUERY_STRING' => 'pagename=~test/it&arg1=value1&arg2=value2', ], 'get' => [ 'pagename' => '~test/it', @@ -113,12 +85,12 @@ class ArgumentsTest extends TestCase 'withDiasporaHomeDir' => [ 'assert' => [ 'queryString' => 'u/test/it?arg1=value1&arg2=value2', - 'command' => 'profile/test/it', - 'argv' => ['profile', 'test', 'it'], + 'command' => 'u/test/it', + 'argv' => ['u', 'test', 'it'], 'argc' => 3, ], 'server' => [ - 'QUERY_STRING' => 'pagename=u/test/it?arg1=value1&arg2=value2', + 'QUERY_STRING' => 'pagename=u/test/it&arg1=value1&arg2=value2', ], 'get' => [ 'pagename' => 'u/test/it', @@ -126,13 +98,13 @@ class ArgumentsTest extends TestCase ], 'withTrailingSlash' => [ 'assert' => [ - 'queryString' => 'profile/test/it?arg1=value1&arg2=value2/', + 'queryString' => 'profile/test/it?arg1=value1&arg2=value2%2F', 'command' => 'profile/test/it', 'argv' => ['profile', 'test', 'it'], 'argc' => 3, ], 'server' => [ - 'QUERY_STRING' => 'pagename=profile/test/it?arg1=value1&arg2=value2/', + 'QUERY_STRING' => 'pagename=profile/test/it&arg1=value1&arg2=value2/', ], 'get' => [ 'pagename' => 'profile/test/it', @@ -140,14 +112,13 @@ class ArgumentsTest extends TestCase ], 'withWrongQueryString' => [ 'assert' => [ - // empty query string?! - 'queryString' => '', + 'queryString' => 'profile/test/it?wrong=profile%2Ftest%2Fit&arg1=value1&arg2=value2%2F', 'command' => 'profile/test/it', 'argv' => ['profile', 'test', 'it'], 'argc' => 3, ], 'server' => [ - 'QUERY_STRING' => 'wrong=profile/test/it?arg1=value1&arg2=value2/', + 'QUERY_STRING' => 'wrong=profile/test/it&arg1=value1&arg2=value2/', ], 'get' => [ 'pagename' => 'profile/test/it', @@ -155,17 +126,44 @@ class ArgumentsTest extends TestCase ], 'withMissingPageName' => [ 'assert' => [ - 'queryString' => 'notvalid/it?arg1=value1&arg2=value2/', - 'command' => App\Module::DEFAULT, - 'argv' => [App\Module::DEFAULT], - 'argc' => 1, + 'queryString' => 'notvalid/it?arg1=value1&arg2=value2%2F', + 'command' => 'notvalid/it', + 'argv' => ['notvalid', 'it'], + 'argc' => 2, ], 'server' => [ - 'QUERY_STRING' => 'pagename=notvalid/it?arg1=value1&arg2=value2/', + 'QUERY_STRING' => 'pagename=notvalid/it&arg1=value1&arg2=value2/', ], 'get' => [ ], ], + 'withNothing' => [ + 'assert' => [ + 'queryString' => '?arg1=value1&arg2=value2%2F', + 'command' => '', + 'argv' => [], + 'argc' => 0, + ], + 'server' => [ + 'QUERY_STRING' => 'arg1=value1&arg2=value2/', + ], + 'get' => [ + ], + ], + 'withFileExtension' => [ + 'assert' => [ + 'queryString' => 'api/call.json', + 'command' => 'api/call.json', + 'argv' => ['api', 'call.json'], + 'argc' => 2, + ], + 'server' => [ + 'QUERY_STRING' => 'pagename=api/call.json', + ], + 'get' => [ + 'pagename' => 'api/call.json' + ], + ], ]; } @@ -207,27 +205,27 @@ class ArgumentsTest extends TestCase return [ 'strippedZRLFirst' => [ 'assert' => '?arg1=value1', - 'input' => '?zrl=nope&arg1=value1', + 'input' => '&zrl=nope&arg1=value1', ], 'strippedZRLLast' => [ 'assert' => '?arg1=value1', - 'input' => '?arg1=value1&zrl=nope', + 'input' => '&arg1=value1&zrl=nope', ], 'strippedZTLMiddle' => [ 'assert' => '?arg1=value1&arg2=value2', - 'input' => '?arg1=value1&zrl=nope&arg2=value2', + 'input' => '&arg1=value1&zrl=nope&arg2=value2', ], 'strippedOWTFirst' => [ 'assert' => '?arg1=value1', - 'input' => '?owt=test&arg1=value1', + 'input' => '&owt=test&arg1=value1', ], 'strippedOWTLast' => [ 'assert' => '?arg1=value1', - 'input' => '?arg1=value1&owt=test', + 'input' => '&arg1=value1&owt=test', ], 'strippedOWTMiddle' => [ 'assert' => '?arg1=value1&arg2=value2', - 'input' => '?arg1=value1&owt=test&arg2=value2', + 'input' => '&arg1=value1&owt=test&arg2=value2', ], ]; } @@ -242,7 +240,7 @@ class ArgumentsTest extends TestCase $command = 'test/it'; $arguments = (new App\Arguments()) - ->determine(['QUERY_STRING' => 'q=' . $command . $input,], ['pagename' => $command]); + ->determine(['QUERY_STRING' => 'pagename=' . $command . $input,], ['pagename' => $command]); $this->assertEquals($command . $assert, $arguments->getQueryString()); }