diff --git a/CHANGELOG.md b/CHANGELOG.md index fa2dbd7ee..068c25701 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. ## v0.7.1 (Derelict Dermodactylus) ### Fixed * Fixes an exception when no token is entered on the 2-Factor enable/disable page and the form is submitted. +* Fixes an exception when trying to perform actions aganist a User model due to a validator that could not be cast to a string correctly. ## v0.7.0 (Derelict Dermodactylus) ### Fixed diff --git a/app/Rules/Username.php b/app/Rules/Username.php index 08d9baba0..335c3c186 100644 --- a/app/Rules/Username.php +++ b/app/Rules/Username.php @@ -6,6 +6,9 @@ use Illuminate\Contracts\Validation\Rule; class Username implements Rule { + /** + * Regex to use when validating usernames. + */ public const VALIDATION_REGEX = '/^[a-z0-9]([\w\.-]+)[a-z0-9]$/'; /** @@ -33,4 +36,15 @@ class Username implements Rule return 'The :attribute must start and end with alpha-numeric characters and contain only letters, numbers, dashes, underscores, and periods.'; } + + /** + * Convert the rule to a validation string. This is necessary to avoid + * issues with Eloquence which tries to use this rule as a string. + * + * @return string + */ + public function __toString() + { + return 'p_username'; + } } diff --git a/tests/Unit/Rules/UsernameTest.php b/tests/Unit/Rules/UsernameTest.php index fa21530af..7f7bdbb73 100644 --- a/tests/Unit/Rules/UsernameTest.php +++ b/tests/Unit/Rules/UsernameTest.php @@ -7,6 +7,14 @@ use Pterodactyl\Rules\Username; class UsernameTest extends TestCase { + /** + * Test that this rule can be cast to a string correctly. + */ + public function testRuleIsStringable() + { + $this->assertSame('p_username', (string) new Username); + } + /** * Test valid usernames. *