#44107 closed defect (bug) (fixed)
wp_insert_user should return WP_Error if user_url's length is too long
| Reported by: | tszming | Owned by: | SergeyBiryukov |
|---|---|---|---|
| Priority: | normal | Milestone: | 6.0 |
| Component: | Users | Version: | 2.0 |
| Severity: | normal | Keywords: | has-patch has-unit-tests dev-feedback |
| Cc: | Focuses: | administration |
Description
Just like the user_nicename checking
Consider the test below
public function test_wp_insert_user_should_reject_user_url_over_100_characters() {
$user_url = str_repeat( 'a', 101 );
$u = wp_insert_user(
array(
'user_login' => 'test',
'user_email' => 'test@example.com',
'user_pass' => 'password',
'user_url' => $user_url,
)
);
$this->assertWPError( $u );
}
This also apply to the function wp_update_user
Attachments (3)
Change History (13)
#2
@
5 years ago
- Component Build/Test Tools → Administration
- Focuses administration added
- Version → 2.0
#3
@
5 years ago
- Keywords has-patch has-unit-tests dev-feedback added; needs-patch removed
The patch checks for the user url length and returns a WP_Error just like at user's nicename.
Test from @tszming added accordingly.
#4
@
5 years ago
- Component Administration → Users
- Milestone Awaiting Review → 6.0
Thanks for the patch!
Please adjust the spacing so the equal signs line up and there are no extra spaces/tabs.
public function test_wp_insert_user_should_reject_user_url_over_100_characters() {
$user_url = str_repeat( 'a', 101 );
$u = wp_insert_user(
array(
'user_login' => 'test',
'user_email' => 'test@example.com',
'user_pass' => 'password',
'user_url' => $user_url,
)
);
#6
follow-up:
↓ 8
@
5 years ago
Thanks for the patch and the unit test!
This looks good, I only have a few minor notes:
- The
if ( mb_strlen( $raw_user_url ) > 100 ) { ... }condition itself does not need a DocBlock, as it's not a function nor a hook. See the documentation standards for more details on what entities need a DocBlock. - I think the check should run after the
pre_user_urlfilter, to make sure the filtered value is still no longer than 100 characters. That would be consistent with themb_strlen( $user_login ) > 60check, which runs after thepre_user_loginfilter, though not with themb_strlen( $user_nicename ) > 50check, which runs before thepre_user_nicenamefilter for some reason. Let's address the latter in a new ticket. Some history: [34218]. - The unit test should also verify that the error code is
user_url_too_long.
I can make these adjustments on commit.
#8
in reply to: ↑ 6
@
5 years ago
Replying to SergeyBiryukov:
I think the check should run after the
pre_user_urlfilter, to make sure the filtered value is still no longer than 100 characters. That would be consistent with themb_strlen( $user_login ) > 60check, which runs after thepre_user_loginfilter, though not with themb_strlen( $user_nicename ) > 50check, which runs before thepre_user_nicenamefilter for some reason. Let's address the latter in a new ticket.
Follow-up: #54987.
#9
@
5 years ago
I did not test the code, but just for sanity, if we now insert a few mb* chars (strlen( $user_url ) > 100 === true), this "empty registration email"-issue will no longer happen? If it does, shouldn't we use strlen() instead of mb_strlen()?
echo mb_strlen( str_repeat( chr(240) . chr(159) . chr(144) . chr(152), 100 ) ); // 100 echo strlen( str_repeat( chr(240) . chr(159) . chr(144) . chr(152), 100 ) ); // 400
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
I tried to create a user with an user url with more than 100 characters. The user will not be created but an empty registration mail was sent to the given mail address and a "New User created" message is shown in admin area.