Forráskód Böngészése

Merge pull request #1854 from PrivateBin/fix-yourls-status-code

fix: cast statusCode to int before strict comparison in YourlsProxy
El RIDO 2 hónapja
szülő
commit
116b60060c
2 módosított fájl, 11 hozzáadás és 1 törlés
  1. 1 1
      lib/Proxy/YourlsProxy.php
  2. 10 0
      tst/YourlsProxyTest.php

+ 1 - 1
lib/Proxy/YourlsProxy.php

@@ -65,7 +65,7 @@ class YourlsProxy extends AbstractProxy
      */
      */
     protected function _extractShortUrl(array $data): ?string
     protected function _extractShortUrl(array $data): ?string
     {
     {
-        if (($data['statusCode'] ?? 0) === 200) {
+        if ((int) ($data['statusCode'] ?? 0) === 200) {
             return $data['shorturl'] ?? 0;
             return $data['shorturl'] ?? 0;
         }
         }
         return null;
         return null;

+ 10 - 0
tst/YourlsProxyTest.php

@@ -51,6 +51,16 @@ class YourlsProxyTest extends TestCase
         $this->assertEquals($yourls->getUrl(), 'https://example.com/1');
         $this->assertEquals($yourls->getUrl(), 'https://example.com/1');
     }
     }
 
 
+    public function testYourlsProxyWithStringStatusCode(): void
+    {
+        // YOURLS API returns statusCode as a string "200", not integer 200
+        file_put_contents($this->_mock_yourls_service, '{"shorturl":"https:\/\/example.com\/1","statusCode":"200"}');
+
+        $yourls = new YourlsProxy($this->_conf, 'https://example.com/?foo#bar');
+        $this->assertFalse($yourls->isError());
+        $this->assertEquals($yourls->getUrl(), 'https://example.com/1');
+    }
+
     /**
     /**
      * @dataProvider providerInvalidUrl
      * @dataProvider providerInvalidUrl
      */
      */