Skip to content

Commit 970461e

Browse files
committed
Fixes issue with path and urlencode
1 parent 072412c commit 970461e

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/UrlHelper.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,25 @@ public function __construct($path, $params, $secret = null)
2121
$this->secret = $secret;
2222
}
2323

24+
private function getPath()
25+
{
26+
if(filter_var($this->path, FILTER_VALIDATE_URL)) {
27+
return urlencode($this->path);
28+
}
29+
30+
return $this->path;
31+
}
32+
2433
private function getQuery()
2534
{
26-
$query = '/' . urlencode($this->path);
35+
$query = '/' . $this->getPath();
2736

2837
if (count($this->params) > 0) {
2938
$query .= '?' . http_build_query($this->params);
3039
}
3140

3241
$signed = "s=" . md5($this->secret . $query);
3342

34-
35-
3643
return $query . (empty($this->secret) ? "" : (count($this->params) > 0 ? '&' : '?') . $signed);
3744
}
3845

tests/src/UrlTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,19 @@ public function testUnsignedURL()
6363
$this->assertEquals($expected, $url);
6464
}
6565

66+
public function testPath()
67+
{
68+
69+
$urlBuilder = $this->urlBuilder = new UrlBuilder('image.barnebys.sh');
70+
$urlBuilder->setPath('test/123/456');
71+
72+
73+
$url = (string) $urlBuilder;
74+
$expected = 'https://image.barnebys.sh/test/123/456';
75+
76+
$this->assertEquals($expected, $url);
77+
}
78+
6679
public function testToString()
6780
{
6881

0 commit comments

Comments
 (0)