Skip to content

Commit

Permalink
fix: handle trailing slash in Wallabag url
Browse files Browse the repository at this point in the history
Closes #2
  • Loading branch information
Joedmin committed Oct 24, 2024
1 parent 0bdfa23 commit ce1bfef
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
23 changes: 16 additions & 7 deletions Controllers/wallabagButtonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down Expand Up @@ -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();
Expand All @@ -169,7 +178,7 @@ private function getCurlBase(string $url, bool $with_token = false): \CurlHandle
/**
* @return array<string,mixed>
*/
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);
Expand Down Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 5 additions & 1 deletion phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 9
level: 6 # TODO: Increase to 9
fileExtensions:
- php
- phtml
Expand All @@ -10,7 +10,11 @@ parameters:
analyse:
- ../FreshRSS
- vendor/
- fresh_rss_data/
- wallabag_data/
analyseAndScan:
- .github/
- .vscode/
- .git/
- node_modules/
checkMissingOverrideMethodAttribute: true
Expand Down

0 comments on commit ce1bfef

Please sign in to comment.