#44107 closed defect (bug) (fixed)
wp_insert_user should return WP_Error if user_url's length is too long
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 6.0 | Priority: | normal |
Severity: | normal | Version: | 2.0 |
Component: | Users | Keywords: | has-patch has-unit-tests dev-feedback |
Focuses: | administration | Cc: |
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
@
3 years ago
- Component changed from Build/Test Tools to Administration
- Focuses administration added
- Version set to 2.0
#3
@
3 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
@
3 years ago
- Component changed from Administration to Users
- Milestone changed from Awaiting Review to 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
@
3 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_url
filter, to make sure the filtered value is still no longer than 100 characters. That would be consistent with themb_strlen( $user_login ) > 60
check, which runs after thepre_user_login
filter, though not with themb_strlen( $user_nicename ) > 50
check, which runs before thepre_user_nicename
filter 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.
#7
@
3 years ago
- Owner set to SergeyBiryukov
- Resolution set to fixed
- Status changed from new to closed
In 52650:
#8
in reply to:
↑ 6
@
3 years ago
Replying to SergeyBiryukov:
I think the check should run after the
pre_user_url
filter, to make sure the filtered value is still no longer than 100 characters. That would be consistent with themb_strlen( $user_login ) > 60
check, which runs after thepre_user_login
filter, though not with themb_strlen( $user_nicename ) > 50
check, which runs before thepre_user_nicename
filter for some reason. Let's address the latter in a new ticket.
Follow-up: #54987.
#9
@
3 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
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.