Skip to content

Commit c61c2bc

Browse files
committed
Fix User model validation behavior, closes pterodactyl#950
1 parent 50809ca commit c61c2bc

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
66
## v0.7.1 (Derelict Dermodactylus)
77
### Fixed
88
* Fixes an exception when no token is entered on the 2-Factor enable/disable page and the form is submitted.
9+
* 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.
910

1011
## v0.7.0 (Derelict Dermodactylus)
1112
### Fixed

app/Rules/Username.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
class Username implements Rule
88
{
9+
/**
10+
* Regex to use when validating usernames.
11+
*/
912
public const VALIDATION_REGEX = '/^[a-z0-9]([\w\.-]+)[a-z0-9]$/';
1013

1114
/**
@@ -33,4 +36,15 @@ public function message(): string
3336
return 'The :attribute must start and end with alpha-numeric characters and
3437
contain only letters, numbers, dashes, underscores, and periods.';
3538
}
39+
40+
/**
41+
* Convert the rule to a validation string. This is necessary to avoid
42+
* issues with Eloquence which tries to use this rule as a string.
43+
*
44+
* @return string
45+
*/
46+
public function __toString()
47+
{
48+
return 'p_username';
49+
}
3650
}

tests/Unit/Rules/UsernameTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77

88
class UsernameTest extends TestCase
99
{
10+
/**
11+
* Test that this rule can be cast to a string correctly.
12+
*/
13+
public function testRuleIsStringable()
14+
{
15+
$this->assertSame('p_username', (string) new Username);
16+
}
17+
1018
/**
1119
* Test valid usernames.
1220
*

0 commit comments

Comments
 (0)