mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-15 09:14:08 +00:00
Support internationalized domain names (IDN) in email validation
Add IdnEmail validation rule that converts IDN domains to Punycode via idn_to_ascii() before validating with FILTER_VALIDATE_EMAIL. Applied to all email fields: customers, members, profiles, admin users, customer portal profiles, and mail configuration. Includes unit tests for standard emails, IDN emails, and invalid inputs. Fixes #388
This commit is contained in:
67
tests/Unit/Rules/IdnEmailTest.php
Normal file
67
tests/Unit/Rules/IdnEmailTest.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
use App\Rules\IdnEmail;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
test('accepts standard email addresses', function () {
|
||||
$validator = Validator::make(
|
||||
['email' => 'user@example.com'],
|
||||
['email' => [new IdnEmail]]
|
||||
);
|
||||
|
||||
expect($validator->passes())->toBeTrue();
|
||||
});
|
||||
|
||||
test('accepts IDN email with accented domain', function () {
|
||||
$validator = Validator::make(
|
||||
['email' => 'michel@exempleé.fr'],
|
||||
['email' => [new IdnEmail]]
|
||||
);
|
||||
|
||||
expect($validator->passes())->toBeTrue();
|
||||
});
|
||||
|
||||
test('accepts IDN email with umlaut domain', function () {
|
||||
$validator = Validator::make(
|
||||
['email' => 'user@münchen.de'],
|
||||
['email' => [new IdnEmail]]
|
||||
);
|
||||
|
||||
expect($validator->passes())->toBeTrue();
|
||||
});
|
||||
|
||||
test('rejects invalid email without at sign', function () {
|
||||
$validator = Validator::make(
|
||||
['email' => 'notanemail'],
|
||||
['email' => [new IdnEmail]]
|
||||
);
|
||||
|
||||
expect($validator->passes())->toBeFalse();
|
||||
});
|
||||
|
||||
test('rejects email with multiple at signs', function () {
|
||||
$validator = Validator::make(
|
||||
['email' => 'user@@example.com'],
|
||||
['email' => [new IdnEmail]]
|
||||
);
|
||||
|
||||
expect($validator->passes())->toBeFalse();
|
||||
});
|
||||
|
||||
test('accepts empty string without failing', function () {
|
||||
$validator = Validator::make(
|
||||
['email' => ''],
|
||||
['email' => ['nullable', new IdnEmail]]
|
||||
);
|
||||
|
||||
expect($validator->passes())->toBeTrue();
|
||||
});
|
||||
|
||||
test('accepts null without failing', function () {
|
||||
$validator = Validator::make(
|
||||
['email' => null],
|
||||
['email' => ['nullable', new IdnEmail]]
|
||||
);
|
||||
|
||||
expect($validator->passes())->toBeTrue();
|
||||
});
|
||||
Reference in New Issue
Block a user