diff --git a/src/js/_enqueues/admin/user-profile.js b/src/js/_enqueues/admin/user-profile.js
index b73f2ab5c4..ef3e1afcc9 100644
a
|
b
|
|
215 | 215 | var pass1 = $('#pass1').val(), strength; |
216 | 216 | |
217 | 217 | $('#pass-strength-result').removeClass('short bad good strong empty'); |
218 | | if ( ! pass1 ) { |
| 218 | if ( ! pass1 || '' === pass1.trim() ) { |
219 | 219 | $( '#pass-strength-result' ).addClass( 'empty' ).html( ' ' ); |
220 | 220 | return; |
221 | 221 | } |
diff --git a/src/wp-admin/includes/user.php b/src/wp-admin/includes/user.php
index de7cb989c1..5fbfd9f9b4 100644
a
|
b
|
function edit_user( $user_id = 0 ) { |
47 | 47 | $pass1 = ''; |
48 | 48 | $pass2 = ''; |
49 | 49 | if ( isset( $_POST['pass1'] ) ) { |
50 | | $pass1 = $_POST['pass1']; |
| 50 | $pass1 = trim( $_POST['pass1'] ); |
51 | 51 | } |
52 | 52 | if ( isset( $_POST['pass2'] ) ) { |
53 | | $pass2 = $_POST['pass2']; |
| 53 | $pass2 = trim( $_POST['pass2'] ); |
54 | 54 | } |
55 | 55 | |
56 | 56 | if ( isset( $_POST['role'] ) && current_user_can( 'promote_users' ) && ( ! $user_id || current_user_can( 'promote_user', $user_id ) ) ) { |
diff --git a/tests/phpunit/tests/user.php b/tests/phpunit/tests/user.php
index b9d93325aa..8ef284c272 100644
a
|
b
|
class Tests_User extends WP_UnitTestCase { |
1451 | 1451 | * Checks that calling edit_user() with no password returns an error when adding, and doesn't when updating. |
1452 | 1452 | * |
1453 | 1453 | * @ticket 35715 |
| 1454 | * @ticket 42766 |
1454 | 1455 | */ |
1455 | 1456 | function test_edit_user_blank_pw() { |
1456 | 1457 | $_POST = array(); |
… |
… |
class Tests_User extends WP_UnitTestCase { |
1491 | 1492 | $this->assertInternalType( 'int', $user_id ); |
1492 | 1493 | $this->assertSame( 'nickname_updated', $user->nickname ); |
1493 | 1494 | |
| 1495 | // Check not to change an old password if a new password contains only spaces. Ticket #42766 |
| 1496 | $user = get_user_by( 'ID', $user_id ); |
| 1497 | $old_pass = $user->user_pass; |
| 1498 | $_POST['pass1'] = $_POST['pass2'] = ' '; |
| 1499 | |
| 1500 | $user_id = edit_user( $user_id ); |
| 1501 | $user = get_user_by( 'ID', $user_id ); |
| 1502 | |
| 1503 | $this->assertInternalType( 'int', $user_id ); |
| 1504 | $this->assertEquals( $old_pass, $user->user_pass ); |
| 1505 | |
1494 | 1506 | // Check updating user with missing second password. |
1495 | 1507 | $_POST['nickname'] = 'nickname_updated2'; |
1496 | 1508 | $_POST['pass1'] = 'blank_pass2'; |