Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/14/2013 03:43:43 PM (6 years ago)
Author:
boonebgorges
Message:

Remove BuddyPress's restriction spaces in user_login

BuddyPress has historically enforced a no-spaces rule on user_login during
user registration. Originally this was rooted in WPMU's own peculiar character
restrictions, and when the MU requirement was dropped, the same restrictions
were carried over to WordPress Single.

However, these restrictions have caused various problems. BP enforced the "no
spaces" rule during registration by simply swapping out spaces with hyphens and
not telling users. This caused immense confusion. Moreover, the restriction
caused problems when bypassing BP's native user registration, as when
integrating with an external authentication service; these external usernames
*can* sometimes have spaces, and certain areas of BuddyPress were not equipped
to deal with them.

This changeset removes the no-spaces restriction from BuddyPress, and hands
off user_login validation to WordPress Multisite when possible (meaning that on
MS, spaces will still not be allowed during native registration). It also
makes the necessary adjustments throughout BuddyPress to ensure that spaces
in user_login will not break related functionality. On a normal setup, BP (and
WP) only use user_login for authentication, but several changes were necessary
to account for "username compatibility mode", where the user_login is displayed
publicly:

  • Refactor the way that activity @-mentions work in username compatibility mode. We now have functions for converting user IDs to "mentionname" (and vice versa) which will produce @-mention-safe versions of user_nicename or user_login, as appropriate.
  • Use proper URL encoding when building and parsing URLs that contain usernames when compatibility mode is enabled.
  • Fix private messaging autocomplete to work with spaces.

See #4622

Fixes #5185

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/testcases/activity/functions.php

    r7469 r7570  
    101101        $this->assertEquals( $meta_value, bp_activity_get_meta( $a, 'linebreak_test' ) );
    102102    }
     103
     104    /**
     105     * @group bp_activity_get_user_mentionname
     106     */
     107    public function test_bp_activity_get_user_mentionname_compatibilitymode_off() {
     108        add_filter( 'bp_is_username_compatibility_mode', '__return_false' );
     109
     110        $u = $this->create_user( array(
     111            'user_login' => 'foo bar baz',
     112            'user_nicename' => 'foo-bar-baz',
     113        ) );
     114
     115        $this->assertEquals( 'foo-bar-baz', bp_activity_get_user_mentionname( $u ) );
     116
     117        remove_filter( 'bp_is_username_compatibility_mode', '__return_false' );
     118    }
     119
     120    /**
     121     * @group bp_activity_get_user_mentionname
     122     */
     123    public function test_bp_activity_get_user_mentionname_compatibilitymode_on() {
     124        add_filter( 'bp_is_username_compatibility_mode', '__return_true' );
     125
     126        $u1 = $this->create_user( array(
     127            'user_login' => 'foo bar baz',
     128            'user_nicename' => 'foo-bar-baz',
     129        ) );
     130
     131        $u2 = $this->create_user( array(
     132            'user_login' => 'foo.bar.baz',
     133            'user_nicename' => 'foo-bar-baz',
     134        ) );
     135
     136        $this->assertEquals( 'foo-bar-baz', bp_activity_get_user_mentionname( $u1 ) );
     137        $this->assertEquals( 'foo.bar.baz', bp_activity_get_user_mentionname( $u2 ) );
     138
     139        remove_filter( 'bp_is_username_compatibility_mode', '__return_true' );
     140    }
     141
     142    /**
     143     * @group bp_activity_get_userid_from_mentionname
     144     */
     145    public function test_bp_activity_get_userid_from_mentionname_compatibilitymode_off() {
     146        add_filter( 'bp_is_username_compatibility_mode', '__return_false' );
     147
     148        $u = $this->create_user( array(
     149            'user_login' => 'foo bar baz',
     150            'user_nicename' => 'foo-bar-baz',
     151        ) );
     152
     153        $this->assertEquals( $u, bp_activity_get_userid_from_mentionname( 'foo-bar-baz' ) );
     154
     155        remove_filter( 'bp_is_username_compatibility_mode', '__return_false' );
     156    }
     157
     158    /**
     159     * @group bp_activity_get_userid_from_mentionname
     160     */
     161    public function test_bp_activity_get_userid_from_mentionname_compatibilitymode_on() {
     162        add_filter( 'bp_is_username_compatibility_mode', '__return_true' );
     163
     164        // all spaces are hyphens
     165        $u1 = $this->create_user( array(
     166            'user_login' => 'foo bar baz',
     167            'user_nicename' => 'foobarbaz',
     168        ) );
     169
     170        // no spaces are hyphens
     171        $u2 = $this->create_user( array(
     172            'user_login' => 'foo-bar-baz-1',
     173            'user_nicename' => 'foobarbaz-1',
     174        ) );
     175
     176        // some spaces are hyphens
     177        $u3 = $this->create_user( array(
     178            'user_login' => 'foo bar-baz 2',
     179            'user_nicename' => 'foobarbaz-2',
     180        ) );
     181
     182        $u4 = $this->create_user( array(
     183            'user_login' => 'foo.bar.baz',
     184            'user_nicename' => 'foo-bar-baz',
     185        ) );
     186
     187        $this->assertEquals( $u1, bp_activity_get_userid_from_mentionname( 'foo-bar-baz' ) );
     188        $this->assertEquals( $u2, bp_activity_get_userid_from_mentionname( 'foo-bar-baz-1' ) );
     189        $this->assertEquals( $u3, bp_activity_get_userid_from_mentionname( 'foo-bar-baz-2' ) );
     190        $this->assertEquals( $u4, bp_activity_get_userid_from_mentionname( 'foo.bar.baz' ) );
     191
     192        remove_filter( 'bp_is_username_compatibility_mode', '__return_true' );
     193    }
     194
    103195}
Note: See TracChangeset for help on using the changeset viewer.