From a66480626646ea3efa20779b790c18bbb55c9101 Mon Sep 17 00:00:00 2001 From: Jamie York Date: Wed, 19 Nov 2025 11:12:10 +0000 Subject: [PATCH 01/18] validate file encoding --- .../Validation/Concerns/ValidatesAttributes.php | 14 ++++++++++++++ src/Illuminate/Validation/Validator.php | 1 + 2 files changed, 15 insertions(+) diff --git a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php index 1e55e3f68a86..f4b3ea29f22e 100644 --- a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php +++ b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php @@ -1190,6 +1190,20 @@ protected function getExtraConditions(array $segments) return $extra; } + public function validateEncoding($attribute, $value, $parameters) + { + if (! $this->isValidFileInstance($value)) { + return false; + } + + try { + return @mb_check_encoding($value->getContent(), $parameters[0]); + } catch (ValueError) { + // An invalid encoding was given. + return false; + } + } + /** * Validate the extension of a file upload attribute is in a set of defined extensions. * diff --git a/src/Illuminate/Validation/Validator.php b/src/Illuminate/Validation/Validator.php index 5d18ceba448f..02e430894dab 100755 --- a/src/Illuminate/Validation/Validator.php +++ b/src/Illuminate/Validation/Validator.php @@ -196,6 +196,7 @@ class Validator implements ValidatorContract 'Mimetypes', 'Min', 'Size', + 'Encoding', ]; /** From 227db476a84b22d37194c42dbda7620ba9e63030 Mon Sep 17 00:00:00 2001 From: Jamie York Date: Wed, 19 Nov 2025 11:12:24 +0000 Subject: [PATCH 02/18] add method to file rule helper --- src/Illuminate/Validation/Rules/File.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Illuminate/Validation/Rules/File.php b/src/Illuminate/Validation/Rules/File.php index b7589853e9d2..b339c62ca9c3 100644 --- a/src/Illuminate/Validation/Rules/File.php +++ b/src/Illuminate/Validation/Rules/File.php @@ -45,6 +45,13 @@ class File implements Rule, DataAwareRule, ValidatorAwareRule */ protected $maximumFileSize = null; + /** + * The encoding that the file must be. + * + * @var null|string + */ + protected $encoding = null; + /** * An array of custom rules that will be merged into the validation rules. * @@ -205,6 +212,19 @@ public function max($size) return $this; } + /** + * Indicate that the uploaded file should be in the given encoding. + * + * @param string $encoding + * @return $this + */ + public function encoding($encoding) + { + $this->encoding = $encoding; + + return $this; + } + /** * Convert a potentially human-friendly file size to kilobytes. * @@ -291,6 +311,10 @@ protected function buildValidationRules() default => "size:{$this->minimumFileSize}", }; + if ($this->encoding) { + $rules[] = 'encoding:'.$this->encoding; + } + return array_merge(array_filter($rules), $this->customRules); } From a106b10b949ff474711777a88a29227219e26abf Mon Sep 17 00:00:00 2001 From: Jamie York Date: Wed, 19 Nov 2025 11:14:47 +0000 Subject: [PATCH 03/18] test file rule helper --- tests/Validation/ValidationFileRuleTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/Validation/ValidationFileRuleTest.php b/tests/Validation/ValidationFileRuleTest.php index 0d95bb2a8e66..043e28d60d8d 100644 --- a/tests/Validation/ValidationFileRuleTest.php +++ b/tests/Validation/ValidationFileRuleTest.php @@ -357,6 +357,20 @@ public function testMaxWithHumanReadableSizeAndMultipleValue() ); } + public function testEncoding() + { + $this->fails( + File::default()->encoding('UTF-8'), + UploadedFile::fake()->createWithContent('utf8.txt', "\xf0\x28\x8c\x28"), // Invalid 4 byte UTF-8 sequence. + ['validation.encoding'], + ); + + $this->passes( + File::default()->encoding('UTF-8'), + UploadedFile::fake()->createWithContent('utf8.txt', '✌️'), + ); + } + public function testMacro() { File::macro('toDocument', function () { From 3748ac3728c136d2b44fece537ecec47af391e41 Mon Sep 17 00:00:00 2001 From: Jamie York Date: Wed, 19 Nov 2025 11:15:02 +0000 Subject: [PATCH 04/18] add translation and replacements --- src/Illuminate/Translation/lang/en/validation.php | 1 + .../Validation/Concerns/ReplacesAttributes.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/Illuminate/Translation/lang/en/validation.php b/src/Illuminate/Translation/lang/en/validation.php index bd9cc110226b..995b89c78070 100644 --- a/src/Illuminate/Translation/lang/en/validation.php +++ b/src/Illuminate/Translation/lang/en/validation.php @@ -52,6 +52,7 @@ 'doesnt_end_with' => 'The :attribute field must not end with one of the following: :values.', 'doesnt_start_with' => 'The :attribute field must not start with one of the following: :values.', 'email' => 'The :attribute field must be a valid email address.', + 'encoding' => 'The :attribute file must be a valid :encoding file.', 'ends_with' => 'The :attribute field must end with one of the following: :values.', 'enum' => 'The selected :attribute is invalid.', 'exists' => 'The selected :attribute is invalid.', diff --git a/src/Illuminate/Validation/Concerns/ReplacesAttributes.php b/src/Illuminate/Validation/Concerns/ReplacesAttributes.php index ef9bfaf6bca3..62ebbfbb4b95 100644 --- a/src/Illuminate/Validation/Concerns/ReplacesAttributes.php +++ b/src/Illuminate/Validation/Concerns/ReplacesAttributes.php @@ -129,6 +129,20 @@ protected function replaceDigitsBetween($message, $attribute, $rule, $parameters return $this->replaceBetween($message, $attribute, $rule, $parameters); } + /** + * Replace all place-holders for the encoding rule. + * + * @param string $message + * @param string $attribute + * @param string $rule + * @param array $parameters + * @return string + */ + protected function replaceEncoding($message, $attribute, $rule, $parameters) + { + return str_replace(':encoding', $parameters[0], $message); + } + /** * Replace all place-holders for the extensions rule. * From 710c37da0f74d355742dd6242aa7a892742b9354 Mon Sep 17 00:00:00 2001 From: Jamie York Date: Wed, 19 Nov 2025 11:22:12 +0000 Subject: [PATCH 05/18] allow string or uploaded file --- src/Illuminate/Validation/Concerns/ValidatesAttributes.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php index f4b3ea29f22e..24e6cbec5874 100644 --- a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php +++ b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php @@ -1192,12 +1192,10 @@ protected function getExtraConditions(array $segments) public function validateEncoding($attribute, $value, $parameters) { - if (! $this->isValidFileInstance($value)) { - return false; - } + $this->requireParameterCount(1, $parameters, 'encoding'); try { - return @mb_check_encoding($value->getContent(), $parameters[0]); + return @mb_check_encoding($value instanceof File ? $value->getContent() : $value, $parameters[0]); } catch (ValueError) { // An invalid encoding was given. return false; From d5fe04733cf6099e3b86ada44fe26ec9767578d0 Mon Sep 17 00:00:00 2001 From: Jamie York Date: Wed, 19 Nov 2025 11:37:10 +0000 Subject: [PATCH 06/18] generic message for strings and files --- src/Illuminate/Translation/lang/en/validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Translation/lang/en/validation.php b/src/Illuminate/Translation/lang/en/validation.php index 995b89c78070..ffe6c1c0f76e 100644 --- a/src/Illuminate/Translation/lang/en/validation.php +++ b/src/Illuminate/Translation/lang/en/validation.php @@ -52,7 +52,7 @@ 'doesnt_end_with' => 'The :attribute field must not end with one of the following: :values.', 'doesnt_start_with' => 'The :attribute field must not start with one of the following: :values.', 'email' => 'The :attribute field must be a valid email address.', - 'encoding' => 'The :attribute file must be a valid :encoding file.', + 'encoding' => 'The :attribute field must be in :encoding encoding.', 'ends_with' => 'The :attribute field must end with one of the following: :values.', 'enum' => 'The selected :attribute is invalid.', 'exists' => 'The selected :attribute is invalid.', From c535c78e20e0f5dac67e870323bb4b55c374f631 Mon Sep 17 00:00:00 2001 From: Jamie York Date: Wed, 19 Nov 2025 12:53:54 +0000 Subject: [PATCH 07/18] handle invalid encoding parameter --- .../Validation/Concerns/ValidatesAttributes.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php index 24e6cbec5874..723dfd41db76 100644 --- a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php +++ b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php @@ -1194,12 +1194,11 @@ public function validateEncoding($attribute, $value, $parameters) { $this->requireParameterCount(1, $parameters, 'encoding'); - try { - return @mb_check_encoding($value instanceof File ? $value->getContent() : $value, $parameters[0]); - } catch (ValueError) { - // An invalid encoding was given. - return false; + if (! in_array(mb_strtolower($parameters[0]), array_map(mb_strtolower(...), mb_list_encodings()))) { + throw new InvalidArgumentException("Validation rule encoding parameter \"{$parameters[0]}\" is not a valid encoding."); } + + return @mb_check_encoding($value instanceof File ? $value->getContent() : $value, $parameters[0]); } /** From 07a9b88b8fca349933ecf7262102194f02ff200d Mon Sep 17 00:00:00 2001 From: Jamie York Date: Wed, 19 Nov 2025 12:54:04 +0000 Subject: [PATCH 08/18] test more scenarios --- tests/Validation/ValidationFileRuleTest.php | 23 ++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/Validation/ValidationFileRuleTest.php b/tests/Validation/ValidationFileRuleTest.php index 043e28d60d8d..e51be2493f0e 100644 --- a/tests/Validation/ValidationFileRuleTest.php +++ b/tests/Validation/ValidationFileRuleTest.php @@ -359,9 +359,17 @@ public function testMaxWithHumanReadableSizeAndMultipleValue() public function testEncoding() { + // ACSII file containing UTF-8. + $this->fails( + File::default()->encoding('ASCII'), + UploadedFile::fake()->createWithContent('utf8.txt', '✌️'), + ['validation.encoding'], + ); + + // UTF-8 file containing invalid UTF-8 byte sequence. $this->fails( File::default()->encoding('UTF-8'), - UploadedFile::fake()->createWithContent('utf8.txt', "\xf0\x28\x8c\x28"), // Invalid 4 byte UTF-8 sequence. + UploadedFile::fake()->createWithContent('utf8.txt', "\xf0\x28\x8c\x28"), ['validation.encoding'], ); @@ -371,6 +379,19 @@ public function testEncoding() ); } + public function testEncodingWithInvalidParameter() + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Validation rule encoding parameter "FOOBAR" is not a valid encoding.'); + + // Invalid encoding. + $this->fails( + File::default()->encoding('FOOBAR'), + UploadedFile::fake()->createWithContent('utf8.txt', ''), + ['validation.encoding'], + ); + } + public function testMacro() { File::macro('toDocument', function () { From 118cef86dc0ca0a4bae40737ee056983e12a40dc Mon Sep 17 00:00:00 2001 From: Jamie York Date: Wed, 19 Nov 2025 12:55:36 +0000 Subject: [PATCH 09/18] tidy grammar --- src/Illuminate/Translation/lang/en/validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Translation/lang/en/validation.php b/src/Illuminate/Translation/lang/en/validation.php index ffe6c1c0f76e..053eb3ae2afa 100644 --- a/src/Illuminate/Translation/lang/en/validation.php +++ b/src/Illuminate/Translation/lang/en/validation.php @@ -52,7 +52,7 @@ 'doesnt_end_with' => 'The :attribute field must not end with one of the following: :values.', 'doesnt_start_with' => 'The :attribute field must not start with one of the following: :values.', 'email' => 'The :attribute field must be a valid email address.', - 'encoding' => 'The :attribute field must be in :encoding encoding.', + 'encoding' => 'The :attribute field must encoded in :encoding.', 'ends_with' => 'The :attribute field must end with one of the following: :values.', 'enum' => 'The selected :attribute is invalid.', 'exists' => 'The selected :attribute is invalid.', From b0244e9f0054148e1af8e4c8368754f296001be3 Mon Sep 17 00:00:00 2001 From: Jamie York Date: Wed, 19 Nov 2025 14:11:14 +0000 Subject: [PATCH 10/18] no @ silencing --- src/Illuminate/Validation/Concerns/ValidatesAttributes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php index 723dfd41db76..8435f5078ade 100644 --- a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php +++ b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php @@ -1198,7 +1198,7 @@ public function validateEncoding($attribute, $value, $parameters) throw new InvalidArgumentException("Validation rule encoding parameter \"{$parameters[0]}\" is not a valid encoding."); } - return @mb_check_encoding($value instanceof File ? $value->getContent() : $value, $parameters[0]); + return mb_check_encoding($value instanceof File ? $value->getContent() : $value, $parameters[0]); } /** From 52126a97f569264539f20a0151b3b58127cab17e Mon Sep 17 00:00:00 2001 From: Jamie York Date: Wed, 19 Nov 2025 14:13:48 +0000 Subject: [PATCH 11/18] typo --- tests/Validation/ValidationFileRuleTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Validation/ValidationFileRuleTest.php b/tests/Validation/ValidationFileRuleTest.php index e51be2493f0e..cdc607ad497f 100644 --- a/tests/Validation/ValidationFileRuleTest.php +++ b/tests/Validation/ValidationFileRuleTest.php @@ -359,7 +359,7 @@ public function testMaxWithHumanReadableSizeAndMultipleValue() public function testEncoding() { - // ACSII file containing UTF-8. + // ASCII file containing UTF-8. $this->fails( File::default()->encoding('ASCII'), UploadedFile::fake()->createWithContent('utf8.txt', '✌️'), From fae3f0f04da139e9d9e7d0c0cd522acf3ec6b024 Mon Sep 17 00:00:00 2001 From: Jamie York Date: Wed, 19 Nov 2025 14:15:11 +0000 Subject: [PATCH 12/18] lowercase encodings --- tests/Validation/ValidationFileRuleTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Validation/ValidationFileRuleTest.php b/tests/Validation/ValidationFileRuleTest.php index cdc607ad497f..1288f2eff046 100644 --- a/tests/Validation/ValidationFileRuleTest.php +++ b/tests/Validation/ValidationFileRuleTest.php @@ -361,20 +361,20 @@ public function testEncoding() { // ASCII file containing UTF-8. $this->fails( - File::default()->encoding('ASCII'), + File::default()->encoding('ascii'), UploadedFile::fake()->createWithContent('utf8.txt', '✌️'), ['validation.encoding'], ); // UTF-8 file containing invalid UTF-8 byte sequence. $this->fails( - File::default()->encoding('UTF-8'), + File::default()->encoding('utf-8'), UploadedFile::fake()->createWithContent('utf8.txt', "\xf0\x28\x8c\x28"), ['validation.encoding'], ); $this->passes( - File::default()->encoding('UTF-8'), + File::default()->encoding('utf-8'), UploadedFile::fake()->createWithContent('utf8.txt', '✌️'), ); } From 7ec519cdffa82a4afb935e81caefe13fddc33e7e Mon Sep 17 00:00:00 2001 From: Jamie York Date: Wed, 19 Nov 2025 14:20:19 +0000 Subject: [PATCH 13/18] doc block --- .../Validation/Concerns/ValidatesAttributes.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php index 8435f5078ade..208c4d7a12d0 100644 --- a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php +++ b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php @@ -1190,6 +1190,14 @@ protected function getExtraConditions(array $segments) return $extra; } + /** + * Validate the encoding of an attribute. + * + * @param string $attribute + * @param mixed $value + * @param array $parameters + * @return bool + */ public function validateEncoding($attribute, $value, $parameters) { $this->requireParameterCount(1, $parameters, 'encoding'); From 062e914c4825661d716549b5f60f74a4e771ba23 Mon Sep 17 00:00:00 2001 From: Jamie York Date: Wed, 19 Nov 2025 14:26:29 +0000 Subject: [PATCH 14/18] ci --- src/Illuminate/Validation/Rules/File.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Validation/Rules/File.php b/src/Illuminate/Validation/Rules/File.php index b339c62ca9c3..f00b9a3a7c45 100644 --- a/src/Illuminate/Validation/Rules/File.php +++ b/src/Illuminate/Validation/Rules/File.php @@ -215,7 +215,7 @@ public function max($size) /** * Indicate that the uploaded file should be in the given encoding. * - * @param string $encoding + * @param string $encoding * @return $this */ public function encoding($encoding) From 91551d63413b99b77c3b6038de4b8f45d8b18ae2 Mon Sep 17 00:00:00 2001 From: Jamie York Date: Wed, 19 Nov 2025 14:31:20 +0000 Subject: [PATCH 15/18] alpha --- src/Illuminate/Validation/Validator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Validation/Validator.php b/src/Illuminate/Validation/Validator.php index 02e430894dab..064b04393dd7 100755 --- a/src/Illuminate/Validation/Validator.php +++ b/src/Illuminate/Validation/Validator.php @@ -188,6 +188,7 @@ class Validator implements ValidatorContract protected $fileRules = [ 'Between', 'Dimensions', + 'Encoding', 'Extensions', 'File', 'Image', @@ -196,7 +197,6 @@ class Validator implements ValidatorContract 'Mimetypes', 'Min', 'Size', - 'Encoding', ]; /** From e76b267d61230c14beb60e64aa7aa6d9f5233e83 Mon Sep 17 00:00:00 2001 From: Jamie York Date: Wed, 19 Nov 2025 14:36:14 +0000 Subject: [PATCH 16/18] test multiple --- tests/Validation/ValidationFileRuleTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/Validation/ValidationFileRuleTest.php b/tests/Validation/ValidationFileRuleTest.php index 1288f2eff046..a6e63ca9f02f 100644 --- a/tests/Validation/ValidationFileRuleTest.php +++ b/tests/Validation/ValidationFileRuleTest.php @@ -377,6 +377,14 @@ public function testEncoding() File::default()->encoding('utf-8'), UploadedFile::fake()->createWithContent('utf8.txt', '✌️'), ); + + $this->passes( + File::default()->encoding('utf-8'), + [ + UploadedFile::fake()->createWithContent('utf8-1.txt', '✌️'), + UploadedFile::fake()->createWithContent('utf8-2.txt', '👍'), + ] + ); } public function testEncodingWithInvalidParameter() From c94c188e3a04286a2e109573ef047384105df803 Mon Sep 17 00:00:00 2001 From: Jamie York Date: Wed, 19 Nov 2025 14:44:22 +0000 Subject: [PATCH 17/18] generic test filenames --- tests/Validation/ValidationFileRuleTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Validation/ValidationFileRuleTest.php b/tests/Validation/ValidationFileRuleTest.php index a6e63ca9f02f..5f036f2a0cb6 100644 --- a/tests/Validation/ValidationFileRuleTest.php +++ b/tests/Validation/ValidationFileRuleTest.php @@ -362,27 +362,27 @@ public function testEncoding() // ASCII file containing UTF-8. $this->fails( File::default()->encoding('ascii'), - UploadedFile::fake()->createWithContent('utf8.txt', '✌️'), + UploadedFile::fake()->createWithContent('foo.txt', '✌️'), ['validation.encoding'], ); // UTF-8 file containing invalid UTF-8 byte sequence. $this->fails( File::default()->encoding('utf-8'), - UploadedFile::fake()->createWithContent('utf8.txt', "\xf0\x28\x8c\x28"), + UploadedFile::fake()->createWithContent('foo.txt', "\xf0\x28\x8c\x28"), ['validation.encoding'], ); $this->passes( File::default()->encoding('utf-8'), - UploadedFile::fake()->createWithContent('utf8.txt', '✌️'), + UploadedFile::fake()->createWithContent('foo.txt', '✌️'), ); $this->passes( File::default()->encoding('utf-8'), [ - UploadedFile::fake()->createWithContent('utf8-1.txt', '✌️'), - UploadedFile::fake()->createWithContent('utf8-2.txt', '👍'), + UploadedFile::fake()->createWithContent('foo-1.txt', '✌️'), + UploadedFile::fake()->createWithContent('foo-2.txt', '👍'), ] ); } @@ -395,7 +395,7 @@ public function testEncodingWithInvalidParameter() // Invalid encoding. $this->fails( File::default()->encoding('FOOBAR'), - UploadedFile::fake()->createWithContent('utf8.txt', ''), + UploadedFile::fake()->createWithContent('foo.txt', ''), ['validation.encoding'], ); } From 3fe99fde5d478c0187529b0e564a502f127a7ea1 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 19 Nov 2025 10:43:38 -0600 Subject: [PATCH 18/18] formatting --- .../Concerns/ValidatesAttributes.php | 38 +++++++++---------- src/Illuminate/Validation/Rules/File.php | 4 +- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php index 208c4d7a12d0..854fcc831443 100644 --- a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php +++ b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php @@ -959,6 +959,25 @@ public function validateEmail($attribute, $value, $parameters) return $emailValidator->isValid($value, new MultipleValidationWithAnd($validations)); } + /** + * Validate the encoding of an attribute. + * + * @param string $attribute + * @param mixed $value + * @param array $parameters + * @return bool + */ + public function validateEncoding($attribute, $value, $parameters) + { + $this->requireParameterCount(1, $parameters, 'encoding'); + + if (! in_array(mb_strtolower($parameters[0]), array_map(mb_strtolower(...), mb_list_encodings()))) { + throw new InvalidArgumentException("Validation rule encoding parameter [{$parameters[0]}] is not a valid encoding."); + } + + return mb_check_encoding($value instanceof File ? $value->getContent() : $value, $parameters[0]); + } + /** * Validate the existence of an attribute value in a database table. * @@ -1190,25 +1209,6 @@ protected function getExtraConditions(array $segments) return $extra; } - /** - * Validate the encoding of an attribute. - * - * @param string $attribute - * @param mixed $value - * @param array $parameters - * @return bool - */ - public function validateEncoding($attribute, $value, $parameters) - { - $this->requireParameterCount(1, $parameters, 'encoding'); - - if (! in_array(mb_strtolower($parameters[0]), array_map(mb_strtolower(...), mb_list_encodings()))) { - throw new InvalidArgumentException("Validation rule encoding parameter \"{$parameters[0]}\" is not a valid encoding."); - } - - return mb_check_encoding($value instanceof File ? $value->getContent() : $value, $parameters[0]); - } - /** * Validate the extension of a file upload attribute is in a set of defined extensions. * diff --git a/src/Illuminate/Validation/Rules/File.php b/src/Illuminate/Validation/Rules/File.php index f00b9a3a7c45..83aa36e7b9b0 100644 --- a/src/Illuminate/Validation/Rules/File.php +++ b/src/Illuminate/Validation/Rules/File.php @@ -46,9 +46,9 @@ class File implements Rule, DataAwareRule, ValidatorAwareRule protected $maximumFileSize = null; /** - * The encoding that the file must be. + * The required file encoding. * - * @var null|string + * @var string|null */ protected $encoding = null;