mirror of
https://github.com/wallabag/wallabag.git
synced 2025-01-03 05:18:40 +00:00
Remove FixupMondeDiplomatiqueUriSubscriber
This commit is contained in:
parent
0fda16e8ff
commit
698cf8a026
3 changed files with 0 additions and 129 deletions
|
@ -219,7 +219,6 @@ services:
|
||||||
Wallabag\Helper\HttpClientFactory:
|
Wallabag\Helper\HttpClientFactory:
|
||||||
calls:
|
calls:
|
||||||
- ['addSubscriber', ['@Wallabag\Guzzle\AuthenticatorSubscriber']]
|
- ['addSubscriber', ['@Wallabag\Guzzle\AuthenticatorSubscriber']]
|
||||||
- ['addSubscriber', ['@Wallabag\Guzzle\FixupMondeDiplomatiqueUriSubscriber']]
|
|
||||||
|
|
||||||
RulerZ\RulerZ:
|
RulerZ\RulerZ:
|
||||||
alias: rulerz
|
alias: rulerz
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Wallabag\Guzzle;
|
|
||||||
|
|
||||||
use GuzzleHttp\Event\CompleteEvent;
|
|
||||||
use GuzzleHttp\Event\SubscriberInterface;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fixes url encoding of a parameter guzzle fails with.
|
|
||||||
*/
|
|
||||||
class FixupMondeDiplomatiqueUriSubscriber implements SubscriberInterface
|
|
||||||
{
|
|
||||||
public function getEvents(): array
|
|
||||||
{
|
|
||||||
return ['complete' => [['fixUri', 500]]];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function fixUri(CompleteEvent $event)
|
|
||||||
{
|
|
||||||
$response = $event->getResponse();
|
|
||||||
|
|
||||||
if (!$response->hasHeader('Location')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$uri = $response->getHeader('Location');
|
|
||||||
if (false === ($badParameter = strstr($uri, 'retour=http://'))) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$response->setHeader('Location', str_replace($badParameter, urlencode($badParameter), $uri));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,95 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Wallabag\Guzzle;
|
|
||||||
|
|
||||||
use GuzzleHttp\Event\CompleteEvent;
|
|
||||||
use GuzzleHttp\Message\Response;
|
|
||||||
use GuzzleHttp\Stream\Stream;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use Wallabag\Guzzle\FixupMondeDiplomatiqueUriSubscriber;
|
|
||||||
|
|
||||||
class FixupMondeDiplomatiqueUriSubscriberTest extends TestCase
|
|
||||||
{
|
|
||||||
public function testGetEvents()
|
|
||||||
{
|
|
||||||
$subscriber = new FixupMondeDiplomatiqueUriSubscriber();
|
|
||||||
$events = $subscriber->getEvents();
|
|
||||||
|
|
||||||
$this->assertArrayHasKey('complete', $events);
|
|
||||||
$this->assertCount(2, $events['complete'][0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetEventsWithoutHeaderLocation()
|
|
||||||
{
|
|
||||||
$response = new Response(
|
|
||||||
200,
|
|
||||||
[
|
|
||||||
'content-type' => 'text/html',
|
|
||||||
],
|
|
||||||
Stream::factory('<html></html>')
|
|
||||||
);
|
|
||||||
|
|
||||||
$event = $this->getMockBuilder(CompleteEvent::class)
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
|
|
||||||
$event->expects($this->once())
|
|
||||||
->method('getResponse')
|
|
||||||
->willReturn($response);
|
|
||||||
|
|
||||||
$subscriber = new FixupMondeDiplomatiqueUriSubscriber();
|
|
||||||
$subscriber->fixUri($event);
|
|
||||||
|
|
||||||
$this->assertFalse($response->hasHeader('Location'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetEventsWithNotMachingHeaderLocation()
|
|
||||||
{
|
|
||||||
$response = new Response(
|
|
||||||
200,
|
|
||||||
[
|
|
||||||
'content-type' => 'text/html',
|
|
||||||
'Location' => 'http://example.com',
|
|
||||||
],
|
|
||||||
Stream::factory('<html></html>')
|
|
||||||
);
|
|
||||||
|
|
||||||
$event = $this->getMockBuilder(CompleteEvent::class)
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
|
|
||||||
$event->expects($this->once())
|
|
||||||
->method('getResponse')
|
|
||||||
->willReturn($response);
|
|
||||||
|
|
||||||
$subscriber = new FixupMondeDiplomatiqueUriSubscriber();
|
|
||||||
$subscriber->fixUri($event);
|
|
||||||
|
|
||||||
$this->assertSame('http://example.com', $response->getHeader('Location'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetEventsWithMachingHeaderLocation()
|
|
||||||
{
|
|
||||||
$response = new Response(
|
|
||||||
200,
|
|
||||||
[
|
|
||||||
'content-type' => 'text/html',
|
|
||||||
'Location' => 'http://example.com/?foo=bar&retour=http://example.com',
|
|
||||||
],
|
|
||||||
Stream::factory('<html></html>')
|
|
||||||
);
|
|
||||||
|
|
||||||
$event = $this->getMockBuilder(CompleteEvent::class)
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
|
|
||||||
$event->expects($this->once())
|
|
||||||
->method('getResponse')
|
|
||||||
->willReturn($response);
|
|
||||||
|
|
||||||
$subscriber = new FixupMondeDiplomatiqueUriSubscriber();
|
|
||||||
$subscriber->fixUri($event);
|
|
||||||
|
|
||||||
$this->assertSame('http://example.com/?foo=bar&retour%3Dhttp%3A%2F%2Fexample.com', $response->getHeader('Location'));
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue