Skip to content

Commit 8f69213

Browse files
authored
Merge pull request #63 from shopware/fix-double-slash
fix: remove double slash from url
2 parents f420595 + 2c37881 commit 8f69213

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

src/EventListener/BeforeRegistrationStartsListener.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ public function __invoke(BeforeRegistrationStartsEvent $event): void
3333
}
3434

3535
$shop = $event->getShop();
36+
$url = rtrim($shop->getShopUrl(), '/');
3637

3738
try {
38-
$this->httpClient->request('HEAD', sprintf("%s/api/_info/config", $shop->getShopUrl()), [
39+
$this->httpClient->request('HEAD', sprintf("%s/api/_info/config", $url), [
3940
'timeout' => 10,
4041
'max_redirects' => 0,
4142
]);
@@ -44,7 +45,7 @@ public function __invoke(BeforeRegistrationStartsEvent $event): void
4445
return;
4546
}
4647

47-
throw new ShopURLIsNotReachableException($shop->getShopUrl(), $e);
48+
throw new ShopURLIsNotReachableException($url, $e);
4849
}
4950
}
5051
}

tests/EventListener/BeforeRegistrationStartsListenerTest.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function testListenerMustThrowExceptionBecauseTheShopURLIsNotReachable():
9191

9292
$shop = $this->createMock(ShopInterface::class);
9393
$shop
94-
->expects(self::exactly(2))
94+
->expects(self::once())
9595
->method('getShopUrl')
9696
->willReturn('https://shop-url.com');
9797

@@ -124,7 +124,7 @@ public function testListenerMustThrowExceptionBecauseTheShopURLRedirectsToAnothe
124124

125125
$shop = $this->createMock(ShopInterface::class);
126126
$shop
127-
->expects(self::exactly(2))
127+
->expects(self::once())
128128
->method('getShopUrl')
129129
->willReturn('https://shop-url.com');
130130

@@ -150,6 +150,35 @@ public function testListenerMustThrowExceptionBecauseTheShopURLRedirectsToAnothe
150150
);
151151
}
152152

153+
public function testRequestSentWithoutDoubleBackslash()
154+
{
155+
$shop = $this->createMock(ShopInterface::class);
156+
$shop
157+
->expects(self::once())
158+
->method('getShopUrl')
159+
->willReturn('https://shop-url.com/');
160+
161+
$this->httpClient
162+
->expects(self::once())
163+
->method('request')
164+
->with('HEAD', 'https://shop-url.com/api/_info/config', [
165+
'timeout' => 10,
166+
'max_redirects' => 0,
167+
]);
168+
169+
$listener = new BeforeRegistrationStartsListener(
170+
$this->httpClient,
171+
true
172+
);
173+
174+
$listener->__invoke(
175+
new BeforeRegistrationStartsEvent(
176+
$this->createMock(RequestInterface::class),
177+
$shop
178+
)
179+
);
180+
}
181+
153182
#[DataProvider('unauthorizedHttpExceptionProvider')]
154183
public function testListenerDoesNotThrowExceptionWhenTheExceptionCodeIsHTTPUnauthorized($exception): void
155184
{

0 commit comments

Comments
 (0)