mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2026-07-17 16:39:40 +00:00
Merge pull request #1878 from TowyTowy/fix/yourls-shorturl-null-fallback
fix: handle YOURLS 200 response without shorturl gracefully
This commit is contained in:
commit
b6f4278e07
3 changed files with 15 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
|||
# PrivateBin version history
|
||||
|
||||
## 2.0.6 (not yet released)
|
||||
* FIXED: Gracefully handle YOURLS replies with a 200 status code but no shorturl, instead of raising a TypeError
|
||||
|
||||
## 2.0.5 (2026-07-11)
|
||||
* CHANGED: Show OS-specific copy hotkey hint (Cmd+c on Mac, Ctrl+c on others) (#1506)
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ class YourlsProxy extends AbstractProxy
|
|||
protected function _extractShortUrl(array $data): ?string
|
||||
{
|
||||
if ((int) ($data['statusCode'] ?? 0) === 200) {
|
||||
return $data['shorturl'] ?? 0;
|
||||
return $data['shorturl'] ?? null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,6 +135,19 @@ class YourlsProxyTest extends TestCase
|
|||
$this->assertEquals($yourls->getError(), 'Proxy error: Error parsing proxy response. This can be a configuration issue, like wrong or missing config keys.');
|
||||
}
|
||||
|
||||
public function testYourlsSuccessWithoutShortUrl()
|
||||
{
|
||||
// YOURLS may reply with statusCode 200 but without a shorturl field;
|
||||
// this must be handled gracefully as an error instead of raising a
|
||||
// TypeError (the method is declared to return ?string). YOURLS returns
|
||||
// the status code as a string, so mirror that here.
|
||||
file_put_contents($this->_mock_yourls_service, '{"statusCode":"200"}');
|
||||
|
||||
$yourls = new YourlsProxy($this->_conf, 'https://example.com/?foo#bar');
|
||||
$this->assertTrue($yourls->isError());
|
||||
$this->assertEquals($yourls->getError(), 'Proxy error: Error parsing proxy response. This can be a configuration issue, like wrong or missing config keys.');
|
||||
}
|
||||
|
||||
public function testServerError()
|
||||
{
|
||||
// simulate some other server error that results in a non-JSON reply
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue