Skip to content

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Aug 3, 2017
2 parents 10cf403 + b830057 commit b7e74b0
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ public function saveMany($models, array $pivotAttributes = [])
* @param bool $touch
* @return \Illuminate\Database\Eloquent\Model
*/
public function create(array $attributes = [], array $joining = [], $touch = true)
public function create(array $attributes, array $joining = [], $touch = true)
{
$instance = $this->related->newInstance($attributes);

Expand Down
8 changes: 5 additions & 3 deletions src/Illuminate/Filesystem/FilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,12 +392,14 @@ public function temporaryUrl($path, $expiration, array $options = [])
{
$adapter = $this->driver->getAdapter();

$client = $adapter->getClient();

if (! $adapter instanceof AwsS3Adapter) {
if (method_exists($adapter, 'getTemporaryUrl')) {
return $adapter->getTemporaryUrl($path, $expiration, $options);
} elseif (! $adapter instanceof AwsS3Adapter) {
throw new RuntimeException('This driver does not support creating temporary URLs.');
}

$client = $adapter->getClient();

$command = $client->getCommand('GetObject', array_merge([
'Bucket' => $adapter->getBucket(),
'Key' => $adapter->getPathPrefix().$path,
Expand Down
8 changes: 4 additions & 4 deletions src/Illuminate/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,10 @@ public function put($key, $value)
*/
public function random($amount = null)
{
if ($amount === 0) {
return new static;
}

if (($requested = $amount ?: 1) > ($count = $this->count())) {
throw new InvalidArgumentException(
"You requested {$requested} items, but there are only {$count} items in the collection."
Expand All @@ -1163,10 +1167,6 @@ public function random($amount = null)
return Arr::random($this->items);
}

if ($amount === 0) {
return new static;
}

return new static(Arr::random($this->items, $amount));
}

Expand Down
18 changes: 9 additions & 9 deletions src/Illuminate/Support/Facades/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
namespace Illuminate\Support\Facades;

/**
* @method static \Illuminate\Routing\Route get(string $uri, \Closure|array|string $action)
* @method static \Illuminate\Routing\Route post(string $uri, \Closure|array|string $action)
* @method static \Illuminate\Routing\Route put(string $uri, \Closure|array|string $action)
* @method static \Illuminate\Routing\Route delete(string $uri, \Closure|array|string $action)
* @method static \Illuminate\Routing\Route patch(string $uri, \Closure|array|string $action)
* @method static \Illuminate\Routing\Route options(string $uri, \Closure|array|string $action)
* @method static \Illuminate\Routing\Route any(string $uri, \Closure|array|string $action)
* @method static \Illuminate\Routing\Route match(array|string $methods, string $uri, \Closure|array|string $action)
* @method static \Illuminate\Routing\Route get(string $uri, \Closure|array|string|null $action = null)
* @method static \Illuminate\Routing\Route post(string $uri, \Closure|array|string|null $action = null)
* @method static \Illuminate\Routing\Route put(string $uri, \Closure|array|string|null $action = null)
* @method static \Illuminate\Routing\Route delete(string $uri, \Closure|array|string|null $action = null)
* @method static \Illuminate\Routing\Route patch(string $uri, \Closure|array|string|null $action = null)
* @method static \Illuminate\Routing\Route options(string $uri, \Closure|array|string|null $action = null)
* @method static \Illuminate\Routing\Route any(string $uri, \Closure|array|string|null $action = null)
* @method static \Illuminate\Routing\Route match(array|string $methods, string $uri, \Closure|array|string|null $action = null)
* @method static \Illuminate\Routing\Route prefix(string $prefix)
* @method static void resource(string $name, string $controller, array $options = [])
* @method static void apiResource(string $name, string $controller, array $options = [])
* @method static void group(array $attributes, \Closure $callback)
* @method static void group(array $attributes, \Closure|string $callback)
* @method static \Illuminate\Routing\Route middleware(array|string|null $middleware)
* @method static \Illuminate\Routing\Route substituteBindings(\Illuminate\Routing\Route $route)
* @method static void substituteImplicitBindings(\Illuminate\Routing\Route $route)
Expand Down
26 changes: 26 additions & 0 deletions src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,10 @@ public function validateMimes($attribute, $value, $parameters)
return false;
}

if ($this->shouldBlockPhpUpload($value, $parameters)) {
return false;
}

return $value->getPath() !== '' && in_array($value->guessExtension(), $parameters);
}

Expand All @@ -934,11 +938,33 @@ public function validateMimetypes($attribute, $value, $parameters)
return false;
}

if ($this->shouldBlockPhpUpload($value, $parameters)) {
return false;
}

return $value->getPath() !== '' &&
(in_array($value->getMimeType(), $parameters) ||
in_array(explode('/', $value->getMimeType())[0].'/*', $parameters));
}

/**
* Check if PHP uploads are explicitly allowed.
*
* @param mixed $value
* @param array $parameters
* @return bool
*/
protected function shouldBlockPhpUpload($value, $parameters)
{
if (in_array('php', $parameters)) {
return false;
}

return ($value instanceof UploadedFile)
? strtolower($value->getClientOriginalExtension()) === 'php'
: strtolower($value->getExtension()) === 'php';
}

/**
* Validate the size of an attribute is greater than a minimum value.
*
Expand Down
9 changes: 9 additions & 0 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,15 @@ public function testRandom()
$this->assertCount(3, $random);
}

public function testRandomOnEmptyCollection()
{
$data = new Collection();

$random = $data->random(0);
$this->assertInstanceOf(Collection::class, $random);
$this->assertCount(0, $random);
}

public function testRandomWithoutArgument()
{
$data = new Collection([1, 2, 3, 4, 5, 6]);
Expand Down
69 changes: 52 additions & 17 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1954,37 +1954,55 @@ public function testValidateImage()
$trans = $this->getIlluminateArrayTranslator();
$uploadedFile = [__FILE__, '', null, null, null, true];

$file = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')->setMethods(['guessExtension'])->setConstructorArgs($uploadedFile)->getMock();
$file = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')->setMethods(['guessExtension', 'getClientOriginalExtension'])->setConstructorArgs($uploadedFile)->getMock();
$file->expects($this->any())->method('guessExtension')->will($this->returnValue('php'));
$file->expects($this->any())->method('getClientOriginalExtension')->will($this->returnValue('php'));
$v = new Validator($trans, ['x' => $file], ['x' => 'Image']);
$this->assertFalse($v->passes());

$file2 = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')->setMethods(['guessExtension'])->setConstructorArgs($uploadedFile)->getMock();
$file2 = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')->setMethods(['guessExtension', 'getClientOriginalExtension'])->setConstructorArgs($uploadedFile)->getMock();
$file2->expects($this->any())->method('guessExtension')->will($this->returnValue('jpeg'));
$file2->expects($this->any())->method('getClientOriginalExtension')->will($this->returnValue('jpeg'));
$v = new Validator($trans, ['x' => $file2], ['x' => 'Image']);
$this->assertTrue($v->passes());

$file3 = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')->setMethods(['guessExtension'])->setConstructorArgs($uploadedFile)->getMock();
$file3 = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')->setMethods(['guessExtension', 'getClientOriginalExtension'])->setConstructorArgs($uploadedFile)->getMock();
$file3->expects($this->any())->method('guessExtension')->will($this->returnValue('gif'));
$file3->expects($this->any())->method('getClientOriginalExtension')->will($this->returnValue('gif'));
$v = new Validator($trans, ['x' => $file3], ['x' => 'Image']);
$this->assertTrue($v->passes());

$file4 = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')->setMethods(['guessExtension'])->setConstructorArgs($uploadedFile)->getMock();
$file4 = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')->setMethods(['guessExtension', 'getClientOriginalExtension'])->setConstructorArgs($uploadedFile)->getMock();
$file4->expects($this->any())->method('guessExtension')->will($this->returnValue('bmp'));
$file4->expects($this->any())->method('getClientOriginalExtension')->will($this->returnValue('bmp'));
$v = new Validator($trans, ['x' => $file4], ['x' => 'Image']);
$this->assertTrue($v->passes());

$file5 = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')->setMethods(['guessExtension'])->setConstructorArgs($uploadedFile)->getMock();
$file5 = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')->setMethods(['guessExtension', 'getClientOriginalExtension'])->setConstructorArgs($uploadedFile)->getMock();
$file5->expects($this->any())->method('guessExtension')->will($this->returnValue('png'));
$file5->expects($this->any())->method('getClientOriginalExtension')->will($this->returnValue('png'));
$v = new Validator($trans, ['x' => $file5], ['x' => 'Image']);
$this->assertTrue($v->passes());

$file6 = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')->setMethods(['guessExtension'])->setConstructorArgs($uploadedFile)->getMock();
$file6 = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')->setMethods(['guessExtension', 'getClientOriginalExtension'])->setConstructorArgs($uploadedFile)->getMock();
$file6->expects($this->any())->method('guessExtension')->will($this->returnValue('svg'));
$file6->expects($this->any())->method('getClientOriginalExtension')->will($this->returnValue('svg'));
$v = new Validator($trans, ['x' => $file6], ['x' => 'Image']);
$this->assertTrue($v->passes());
}

public function testValidateImageDoesNotAllowPhpExtensionsOnImageMime()
{
$trans = $this->getIlluminateArrayTranslator();
$uploadedFile = [__FILE__, '', null, null, null, true];

$file = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')->setMethods(['guessExtension', 'getClientOriginalExtension'])->setConstructorArgs($uploadedFile)->getMock();
$file->expects($this->any())->method('guessExtension')->will($this->returnValue('jpeg'));
$file->expects($this->any())->method('getClientOriginalExtension')->will($this->returnValue('php'));
$v = new Validator($trans, ['x' => $file], ['x' => 'Image']);
$this->assertFalse($v->passes());
}

/**
* @group dimension
*/
Expand Down Expand Up @@ -2066,16 +2084,14 @@ public function testValidateImageDimensions()
/**
* @requires extension fileinfo
*/
public function testValidateMimetypes()
public function testValidatePhpMimetypes()
{
$trans = $this->getIlluminateArrayTranslator();
$uploadedFile = [__FILE__, '', null, null, null, true];

$file = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')->setMethods(['guessExtension'])->setConstructorArgs($uploadedFile)->getMock();
$file->expects($this->any())->method('guessExtension')->will($this->returnValue('php'));

$v = new Validator($trans, ['x' => $file], ['x' => 'mimetypes:text/x-php']);
$this->assertTrue($v->passes());
$file = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')->setMethods(['guessExtension', 'getClientOriginalExtension'])->setConstructorArgs($uploadedFile)->getMock();
$file->expects($this->any())->method('guessExtension')->will($this->returnValue('rtf'));
$file->expects($this->any())->method('getClientOriginalExtension')->will($this->returnValue('rtf'));

$v = new Validator($trans, ['x' => $file], ['x' => 'mimetypes:text/*']);
$this->assertTrue($v->passes());
Expand All @@ -2086,18 +2102,37 @@ public function testValidateMime()
$trans = $this->getIlluminateArrayTranslator();
$uploadedFile = [__FILE__, '', null, null, null, true];

$file = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')->setMethods(['guessExtension'])->setConstructorArgs($uploadedFile)->getMock();
$file->expects($this->any())->method('guessExtension')->will($this->returnValue('php'));
$v = new Validator($trans, ['x' => $file], ['x' => 'mimes:php']);
$file = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')->setMethods(['guessExtension', 'getClientOriginalExtension'])->setConstructorArgs($uploadedFile)->getMock();
$file->expects($this->any())->method('guessExtension')->will($this->returnValue('pdf'));
$file->expects($this->any())->method('getClientOriginalExtension')->will($this->returnValue('pdf'));
$v = new Validator($trans, ['x' => $file], ['x' => 'mimes:pdf']);
$this->assertTrue($v->passes());

$file2 = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')->setMethods(['guessExtension', 'isValid'])->setConstructorArgs($uploadedFile)->getMock();
$file2->expects($this->any())->method('guessExtension')->will($this->returnValue('php'));
$file2->expects($this->any())->method('guessExtension')->will($this->returnValue('pdf'));
$file2->expects($this->any())->method('isValid')->will($this->returnValue(false));
$v = new Validator($trans, ['x' => $file2], ['x' => 'mimes:php']);
$v = new Validator($trans, ['x' => $file2], ['x' => 'mimes:pdf']);
$this->assertFalse($v->passes());
}

public function testValidateMimeEnforcesPhpCheck()
{
$trans = $this->getIlluminateArrayTranslator();
$uploadedFile = [__FILE__, '', null, null, null, true];

$file = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')->setMethods(['guessExtension', 'getClientOriginalExtension'])->setConstructorArgs($uploadedFile)->getMock();
$file->expects($this->any())->method('guessExtension')->will($this->returnValue('pdf'));
$file->expects($this->any())->method('getClientOriginalExtension')->will($this->returnValue('php'));
$v = new Validator($trans, ['x' => $file], ['x' => 'mimes:pdf']);
$this->assertFalse($v->passes());

$file2 = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')->setMethods(['guessExtension', 'getClientOriginalExtension'])->setConstructorArgs($uploadedFile)->getMock();
$file2->expects($this->any())->method('guessExtension')->will($this->returnValue('php'));
$file2->expects($this->any())->method('getClientOriginalExtension')->will($this->returnValue('php'));
$v = new Validator($trans, ['x' => $file2], ['x' => 'mimes:pdf,php']);
$this->assertTrue($v->passes());
}

/**
* @requires extension fileinfo
*/
Expand Down

0 comments on commit b7e74b0

Please sign in to comment.