From: Gianluca S. <gi...@gm...> - 2008-08-29 07:08:35
|
I notice the same kind code: $normalized_string = preg_replace('/\s+/', ' ', $original_string); used three times in this patch, maybe a candidate for a string_normalize_spaces() function? what about also adding a trim() in the mix? ---------- Forwarded message ---------- From: <thr...@us...> Date: Thu, Aug 28, 2008 at 4:03 AM Subject: [mantisbt-cvs] SF.net SVN: mantisbt:[5528] trunk/mantisbt To: man...@li... Revision: 5528 http://mantisbt.svn.sourceforge.net/mantisbt/?rev=5528&view=rev Author: thraxisp Date: 2008-08-28 02:03:19 +0000 (Thu, 28 Aug 2008) Log Message: ----------- fix for #5424: user_is_name_unique(): "Real Name" and "Real Name" (first name has one space, second name two) fix for #7880: Create new user with same name is allowed. Editting the user reports an error Modified Paths: -------------- trunk/mantisbt/account_update.php trunk/mantisbt/manage_user_create.php trunk/mantisbt/manage_user_update.php Modified: trunk/mantisbt/account_update.php =================================================================== --- trunk/mantisbt/account_update.php 2008-08-23 22:34:26 UTC (rev 5527) +++ trunk/mantisbt/account_update.php 2008-08-28 02:03:19 UTC (rev 5528) @@ -64,18 +64,13 @@ $t_email_updated = true; } - if ( $f_realname != user_get_field( $t_user_id, 'realname' ) ) { + # strip extra spaces from real name + $t_realname = d + if ( $t_realname != user_get_field( $t_user_id, 'realname' ) ) { # checks for problems with realnames $t_username = user_get_field( $t_user_id, 'username' ); - switch ( user_is_realname_unique( $t_username, $f_realname ) ) { - case 1: - break; - case 0: - default: - trigger_error( ERROR_USER_REAL_MATCH_USER, ERROR ); - break; - } - user_set_realname( $t_user_id, $f_realname ); + user_ensure_realname_unique( $t_username, $t_realname ); + user_set_realname( $t_user_id, $t_realname ); $t_realname_updated = true; } Modified: trunk/mantisbt/manage_user_create.php =================================================================== --- trunk/mantisbt/manage_user_create.php 2008-08-23 22:34:26 UTC (rev 5527) +++ trunk/mantisbt/manage_user_create.php 2008-08-28 02:03:19 UTC (rev 5528) @@ -48,8 +48,11 @@ # Check the name for validity here so we do it before promting to use a # blank password (don't want to prompt the user if the process will fail # anyway) + # strip extra space from real name + $t_realname = preg_replace('/\s+/', ' ', $f_realname); user_ensure_name_valid( $f_username ); - user_ensure_realname_valid( $f_realname ); + user_ensure_realname_valid( $t_realname ); + user_ensure_realname_unique( $f_username, $f_realname ); if ( $f_password != $f_password_verify ) { trigger_error( ERROR_USER_CREATE_PASSWORD_MISMATCH, ERROR ); @@ -75,7 +78,7 @@ form_security_validate( 'manage_user_create' ); - $t_cookie = user_create( $f_username, $f_password, $f_email, $f_access_level, $f_protected, $f_enabled, $f_realname ); + $t_cookie = user_create( $f_username, $f_password, $f_email, $f_access_level, $f_protected, $f_enabled, $t_realname ); if ( $t_cookie === false ) { $t_redirect_url = 'manage_user_page.php'; Modified: trunk/mantisbt/manage_user_update.php =================================================================== --- trunk/mantisbt/manage_user_update.php 2008-08-23 22:34:26 UTC (rev 5527) +++ trunk/mantisbt/manage_user_update.php 2008-08-28 02:03:19 UTC (rev 5528) @@ -54,6 +54,9 @@ trigger_error( ERROR_USER_NAME_NOT_UNIQUE, ERROR ); } + # strip extra space from real name + $t_realname = preg_replace('/\s+/', ' ', $f_realname); + user_ensure_name_valid( $f_username ); user_ensure_realname_valid( $f_realname ); user_ensure_realname_unique( $f_username, $f_realname ); @@ -63,7 +66,7 @@ email_ensure_not_disposable( $f_email ); $c_email = $f_email; - $c_username = $f_username; + $c_username = $t_username; $c_realname = $f_realname; $c_protected = db_prepare_bool( $f_protected ); $c_enabled = db_prepare_bool( $f_enabled ); @@ -82,7 +85,7 @@ # Project specific access rights override global levels, hence, for users who are changed # to be administrators, we have to remove project specific rights. - if ( ( $c_access_level >= ADMINISTRATOR ) && ( !user_is_administrator( $c_user_id ) ) ) { + if ( ( $c_access_level >= ADMINISTRATOR ) && ( !user_is_administrator( $c_user_id ) ) ) { user_delete_project_specific_access_levels( $c_user_id ); } -- Gianluca Sforna http://morefedora.blogspot.com http://www.linkedin.com/in/gianlucasforna |