From ce1bfeff8816352016731c49c3bcfcc352b209e2 Mon Sep 17 00:00:00 2001 From: Joedmin Date: Thu, 24 Oct 2024 13:35:24 +0200 Subject: [PATCH] fix: handle trailing slash in Wallabag url Closes #2 --- Controllers/wallabagButtonController.php | 23 ++++++++++++++++------- extension.php | 2 +- phpstan.dist.neon | 6 +++++- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Controllers/wallabagButtonController.php b/Controllers/wallabagButtonController.php index 468d1b5..f1cca26 100644 --- a/Controllers/wallabagButtonController.php +++ b/Controllers/wallabagButtonController.php @@ -36,7 +36,12 @@ public function requestAccessAction(): void $username = Minz_Request::paramString('username'); $password = Minz_Request::paramString('password'); - // TODO: handle leading slash in url + // Handle leading slash + if (substr($instance_url, -1) == '/') + { + $instance_url = substr($instance_url, 0, -1); + } + FreshRSS_Context::userConf()->_attribute('wallabag_instance_url', $instance_url); FreshRSS_Context::userConf()->_attribute('wallabag_username', $username); FreshRSS_Context::userConf()->_attribute('wallabag_client_id', $client_id); @@ -59,7 +64,11 @@ public function requestAccessAction(): void exit(); } - $url_redirect = array('c' => 'extension', 'a' => 'configure', 'params' => array('e' => 'Wallabag Button')); + $url_redirect = array( + 'c' => 'extension', + 'a' => 'configure', + 'params' => array('e' => 'Wallabag Button') + ); Minz_Request::bad(_t('ext.wallabagButton.notifications.request_access_failed', $result['status']), $url_redirect); } @@ -155,7 +164,7 @@ private function getRequestHeaders(bool $with_token = false): array ); } - private function getCurlBase(string $url, bool $with_token = false): \CurlHandle|false + private function getCurlBase(string $url, bool $with_token = false): \CurlHandle { $headers = $this->getRequestHeaders($with_token); $curl = curl_init(); @@ -169,7 +178,7 @@ private function getCurlBase(string $url, bool $with_token = false): \CurlHandle /** * @return array */ - private function curlGetRequest(string $endpoint, bool $with_token = false): array|false + private function curlGetRequest(string $endpoint, bool $with_token = false): array { $instance_url = FreshRSS_Context::userConf()->attributeString('wallabag_instance_url'); $curl = $this->getCurlBase($instance_url . $endpoint, $with_token); @@ -229,9 +238,9 @@ private function httpHeaderToArray(string $header): array } // Filter the beginning of the header which is the basic HTTP status code - if (strpos($header_part, ':')) { - $header_name = substr($header_part, 0, strpos($header_part, ':')); - $header_value = substr($header_part, strpos($header_part, ':') + 1); + if (strpos($header_part, ':') !== false) { + $header_name = substr($header_part, 0, intval(strpos($header_part, ':'))); + $header_value = substr($header_part, intval(strpos($header_part, ':')) + 1); $headers[$header_name] = trim($header_value); } } diff --git a/extension.php b/extension.php index 9b89163..85bc92b 100644 --- a/extension.php +++ b/extension.php @@ -9,7 +9,7 @@ public function init(): void Minz_View::appendScript($this->getFileUrl('script.js', 'js'), false, false, false); Minz_View::appendStyle($this->getFileUrl('style.css', 'css')); - Minz_View::appendScript(_url('wallabagButton', 'jsVars'), false, true, false); + Minz_View::appendScript(strval(_url('wallabagButton', 'jsVars')), false, true, false); $this->registerController('wallabagButton'); $this->registerViews(); diff --git a/phpstan.dist.neon b/phpstan.dist.neon index 3d1ee49..8676076 100644 --- a/phpstan.dist.neon +++ b/phpstan.dist.neon @@ -1,5 +1,5 @@ parameters: - level: 9 + level: 6 # TODO: Increase to 9 fileExtensions: - php - phtml @@ -10,7 +10,11 @@ parameters: analyse: - ../FreshRSS - vendor/ + - fresh_rss_data/ + - wallabag_data/ analyseAndScan: + - .github/ + - .vscode/ - .git/ - node_modules/ checkMissingOverrideMethodAttribute: true