Skip to content

Commit

Permalink
Merge pull request #16 from overblog/master
Browse files Browse the repository at this point in the history
Wrong signature when there is no commands
  • Loading branch information
harto committed Dec 12, 2014
2 parents 5b1d495 + d295793 commit 99890bb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/Thumbor/Url.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,20 @@ public function __construct($server, $secret, $original, $commands)
*/
public function stringify($server, $secret, $original, $commands)
{
$commandPath = implode('/', $commands);
$signature = $secret ? self::sign("$commandPath/$original", $secret) : 'unsafe';
if (count($commands) > 0) {
$commandPath = implode('/', $commands);
$imgPath = sprintf('%s/%s', $commandPath, $original);
} else {
$imgPath = $original;
}

$signature = $secret ? self::sign($imgPath, $secret) : 'unsafe';

return sprintf(
'%s/%s/%s/%s',
'%s/%s/%s',
$server,
$signature,
$commandPath,
$original
$imgPath
);
}

Expand Down
15 changes: 15 additions & 0 deletions tests/Thumbor/UrlTest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,19 @@ public function testToString()
"$url"
);
}

public function testToStringWithoutCommand()
{
$url = new Url(
'http://thumbor-server:8888',
'MY_SECURE_KEY',
'my/big/image.jpg',
array()
);

$this->assertEquals(
'http://thumbor-server:8888/V2bYe7DAKqngbtv2GFxCcllDYWw=/my/big/image.jpg',
"$url"
);
}
}

0 comments on commit 99890bb

Please sign in to comment.