Skip to content

Commit bae44ea

Browse files
fix: Ensure consistency with unicode characters
1 parent 5fc1850 commit bae44ea

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

src/UrlBuilder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public function buildUrl(string $sourceUrl, ?Options $options = null): string
4747
*/
4848
protected function generateSignature(string $path): string
4949
{
50+
$path = urldecode($path);
51+
5052
// We always want to generate a signature for a path that exludes the signature param and value
5153
$path = preg_replace('/&?signature=[^&]*/', '', $path);
5254

tests/Unit/UrlBuilderTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,20 @@
253253

254254
expect($url)->toBe('https://images.example.com/t/images/image.jpg?border=5,ff0000,overlay&q=80&fm=png&signature=hE2e5tLayrNP0pgSaxJLFOMfi0PES2erIzhNYR7QqQ');
255255
});
256+
257+
test('generates signature with unicode characters', function (): void {
258+
$options = createOptions()
259+
->setOrigin('main')
260+
->setFormat('avif')
261+
->setQuality(90)
262+
->setWidth(600)
263+
->setHeight(600)
264+
->setFit(\smallpics\smallpics\enums\Fit::CONTAIN);
265+
266+
$secret = 'my-secret-value';
267+
268+
$builder = new UrlBuilder('https://images.example.com', $secret);
269+
$url = $builder->buildUrl('images/unicode-%E9%BD%90%E8%89%B2-0.png', $options);
270+
271+
expect($url)->toBe('https://images.example.com/t/images/unicode-%E9%BD%90%E8%89%B2-0.png?origin=main&fm=avif&q=90&w=600&h=600&fit=contain&signature=YjnlgXrNQXqmrfa2qPxXhbmSqgQMvwMjGoQH9YBQxs');
272+
});

0 commit comments

Comments
 (0)