Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
Fixed a bug where blob/file name '0' can not be created.
Browse files Browse the repository at this point in the history
  • Loading branch information
katmsft authored and vinjiang committed Mar 22, 2019
1 parent 3357c7d commit f729f60
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion azure-storage-blob/src/Blob/BlobRestProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ private function getCopyBlobSourceName(
*/
private function createPath($container, $blob = '')
{
if (empty($blob)) {
if (empty($blob) && ($blob != '0')) {
return empty($container) ? '/' : $container;
}
$encodedBlob = urlencode($blob);
Expand Down
2 changes: 1 addition & 1 deletion azure-storage-common/src/Common/Internal/Validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static function isBoolean($var)
*/
public static function notNullOrEmpty($var, $name)
{
if (is_null($var) || empty($var)) {
if (is_null($var) || (empty($var) && $var != '0')) {
throw new \InvalidArgumentException(
sprintf(Resources::NULL_OR_EMPTY_MSG, $name)
);
Expand Down
2 changes: 1 addition & 1 deletion azure-storage-file/src/File/FileRestProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public static function createFileService(
*/
private function createPath($share, $directory = '')
{
if (empty($directory)) {
if (empty($directory) && ($directory != '0')) {
return empty($share) ? '/' : $share;
}
$encodedFile = urlencode($directory);
Expand Down
11 changes: 11 additions & 0 deletions tests/Functional/File/FileServiceFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1655,6 +1655,17 @@ public function testPutListClearRanges()
$this->safeDeleteShare($share);
}

public function testCreateFileWithNameIsZero()
{
$share = FileServiceFunctionalTestData::getInterestingShareName();
$this->safeCreateShare($share);
$file = '0';
$this->restProxy->createFile($share, $file, 2048);
$res = $this->restProxy->getFileProperties($share, $file);
$this->assertEquals(2048, $res->getContentLength());
$this->safeDeleteShare($share);
}

private function putListClearRangesWorker(
$share,
$file,
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/Common/Internal/ValidateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public function testIsDateWithNonDate()
public function testNotNullOrEmptyWithNonEmpty()
{
Validate::notNullOrEmpty(1234, 'not null');
Validate::notNullOrEmpty('0', 'not null');

$this->assertTrue(true);
}
Expand Down

0 comments on commit f729f60

Please sign in to comment.