Skip to content

Commit

Permalink
Replace utf8_substr by mb_substr
Browse files Browse the repository at this point in the history
Issue #23214
  • Loading branch information
atrol committed Mar 4, 2018
1 parent 63cac7b commit 292c704
Show file tree
Hide file tree
Showing 22 changed files with 34 additions and 48 deletions.
2 changes: 1 addition & 1 deletion bug_actiongroup_ext_page.php
Expand Up @@ -47,7 +47,7 @@
require_api( 'string_api.php' );
require_api( 'utility_api.php' );

$t_external_action = utf8_strtolower( utf8_substr( $f_action, mb_strlen( $t_external_action_prefix ) ) );
$t_external_action = utf8_strtolower( mb_substr( $f_action, mb_strlen( $t_external_action_prefix ) ) );
$t_form_fields_page = 'bug_actiongroup_' . $t_external_action . '_inc.php';
$t_form_name = 'bug_actiongroup_' . $t_external_action;

Expand Down
2 changes: 1 addition & 1 deletion bugnote_view_inc.php
Expand Up @@ -280,7 +280,7 @@
echo lang_get( 'reminder_sent_none' );
} else {
# If recipients list's last char is not a delimiter, it was truncated
$t_truncated = ( '|' != utf8_substr( $t_activity['note']->note_attr, mb_strlen( $t_activity['note']->note_attr ) - 1 ) );
$t_truncated = ( '|' != mb_substr( $t_activity['note']->note_attr, mb_strlen( $t_activity['note']->note_attr ) - 1 ) );

# Build recipients list for display
$t_to = array();
Expand Down
4 changes: 2 additions & 2 deletions core/authentication_api.php
Expand Up @@ -739,7 +739,7 @@ function auth_does_password_match( $p_user_id, $p_test_password ) {

# Check for migration to another login method and test whether the password was encrypted
# with our previously insecure implementation of the CRYPT method
if( ( $t_login_method != $t_configured_login_method ) || (( CRYPT == $t_configured_login_method ) && utf8_substr( $t_password, 0, 2 ) == utf8_substr( $p_test_password, 0, 2 ) ) ) {
if( ( $t_login_method != $t_configured_login_method ) || (( CRYPT == $t_configured_login_method ) && mb_substr( $t_password, 0, 2 ) == mb_substr( $p_test_password, 0, 2 ) ) ) {
user_set_password( $p_user_id, $p_test_password, true );
}

Expand Down Expand Up @@ -789,7 +789,7 @@ function auth_process_plain_password( $p_password, $p_salt = null, $p_method = n
}

# cut this off to DB_FIELD_SIZE_PASSWORD characters which the largest possible string in the database
return utf8_substr( $t_processed_password, 0, DB_FIELD_SIZE_PASSWORD );
return mb_substr( $t_processed_password, 0, DB_FIELD_SIZE_PASSWORD );
}

/**
Expand Down
6 changes: 3 additions & 3 deletions core/cfdefs/cfdef_standard.php
Expand Up @@ -257,7 +257,7 @@ function cfdef_prepare_string( $p_value ) {
*/
function cfdef_prepare_list_value_for_email( $p_value ) {
# strip start and end markers before converting markers to commas
return str_replace( '|', ', ', utf8_substr( str_replace( '||', '|', '|' . $p_value . '|' ), 1, -1 ) );
return str_replace( '|', ', ', mb_substr( str_replace( '||', '|', '|' . $p_value . '|' ), 1, -1 ) );
}

/**
Expand Down Expand Up @@ -307,7 +307,7 @@ function cfdef_prepare_date_default( $p_value ) {
# We are expanding {tomorrow}, {yesterday}, {+3 days}, {-7 days}, {next week}
# See strtotime() for more details about supported formats.
if( $t_value_length >= 3 && $t_value[0] == '{' && $t_value[$t_value_length - 1] == '}' ) {
$t_value = utf8_substr( $t_value, 1, $t_value_length - 2 );
$t_value = mb_substr( $t_value, 1, $t_value_length - 2 );
$t_value = @strtotime( $t_value );

# Different versions of PHP return different values in case of error.
Expand All @@ -326,7 +326,7 @@ function cfdef_prepare_date_default( $p_value ) {
*/
function cfdef_prepare_list_value( $p_value ) {
# strip start and end markers before converting markers to commas
return string_display_line( str_replace( '|', ', ', utf8_substr( str_replace( '||', '|', '|' . $p_value . '|' ), 1, -1 ) ) );
return string_display_line( str_replace( '|', ', ', mb_substr( str_replace( '||', '|', '|' . $p_value . '|' ), 1, -1 ) ) );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion core/columns_api.php
Expand Up @@ -343,7 +343,7 @@ function column_is_sortable( $p_column ) {
*/
function column_get_custom_field_name( $p_column ) {
if( strncmp( $p_column, 'custom_', 7 ) === 0 ) {
return utf8_substr( $p_column, 7 );
return mb_substr( $p_column, 7 );
}

return null;
Expand Down
2 changes: 1 addition & 1 deletion core/custom_field_api.php
Expand Up @@ -1158,7 +1158,7 @@ function custom_field_validate( $p_field_id, $p_value ) {
*/
function custom_field_prepare_possible_values( $p_possible_values ) {
if( !is_blank( $p_possible_values ) && ( $p_possible_values[0] == '=' ) ) {
return helper_call_custom_function( 'enum_' . utf8_substr( $p_possible_values, 1 ), array() );
return helper_call_custom_function( 'enum_' . mb_substr( $p_possible_values, 1 ), array() );
}

return $p_possible_values;
Expand Down
6 changes: 3 additions & 3 deletions core/database_api.php
Expand Up @@ -715,7 +715,7 @@ function db_prepare_string( $p_string ) {
return addslashes( $p_string );
case 'mysqli':
$t_escaped = $g_db->qstr( $p_string, false );
return utf8_substr( $t_escaped, 1, mb_strlen( $t_escaped ) - 2 );
return mb_substr( $t_escaped, 1, mb_strlen( $t_escaped ) - 2 );
case 'pgsql':
return pg_escape_string( $p_string );
case 'oci8':
Expand Down Expand Up @@ -1320,9 +1320,9 @@ function db_format_query_log_msg( $p_query, array $p_arr_parms ) {
# Skip this token, so replacing it with itself.
$t_replace = $t_match_param[0];
}
$p_query = utf8_substr( $p_query, 0, $t_utf8_offset )
$p_query = mb_substr( $p_query, 0, $t_utf8_offset )
. $t_replace
. utf8_substr( $p_query, $t_utf8_offset + mb_strlen( $t_match_param[0] ) );
. mb_substr( $p_query, $t_utf8_offset + mb_strlen( $t_match_param[0] ) );
$t_lastoffset = $t_match_param[1] + strlen( $t_replace ) + 1;
} else {
$t_lastoffset = $t_match_param[1] + 1;
Expand Down
4 changes: 2 additions & 2 deletions core/form_api.php
Expand Up @@ -169,7 +169,7 @@ function form_security_validate( $p_form_name ) {
}

# Get the date claimed by the token
$t_date = utf8_substr( $t_input, 0, 8 );
$t_date = mb_substr( $t_input, 0, 8 );

# Check if the token exists
if( isset( $t_tokens[$p_form_name][$t_date][$t_input] ) ) {
Expand Down Expand Up @@ -204,7 +204,7 @@ function form_security_purge( $p_form_name ) {
$t_input = gpc_get_string( $t_form_token, '' );

# Get the date claimed by the token
$t_date = utf8_substr( $t_input, 0, 8 );
$t_date = mb_substr( $t_input, 0, 8 );

# Generate a date string of three days ago
$t_purge_date = date( 'Ymd', time() - ( 3 * 24 * 60 * 60 ) );
Expand Down
2 changes: 1 addition & 1 deletion core/helper_api.php
Expand Up @@ -710,7 +710,7 @@ function shutdown_functions_register() {
function helper_filter_by_prefix( array $p_set, $p_prefix ) {
$t_matches = array();
foreach ( $p_set as $p_item ) {
if( utf8_strtolower( utf8_substr( $p_item, 0, mb_strlen( $p_prefix ) ) ) === utf8_strtolower( $p_prefix ) ) {
if( utf8_strtolower( mb_substr( $p_item, 0, mb_strlen( $p_prefix ) ) ) === utf8_strtolower( $p_prefix ) ) {
$t_matches[] = $p_item;
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/install_helper_functions_api.php
Expand Up @@ -550,7 +550,7 @@ function install_update_history_long_custom_fields() {
$t_result = db_query( $t_query );
while( $t_field = db_fetch_array( $t_result ) ) {
if( mb_strlen( $t_field['name'] ) > 32 ) {
$t_custom_fields[utf8_substr( $t_field['name'], 0, 32 )] = $t_field['name'];
$t_custom_fields[mb_substr( $t_field['name'], 0, 32 )] = $t_field['name'];
}
}
if( !isset( $t_custom_fields ) ) {
Expand Down
14 changes: 0 additions & 14 deletions core/php_api.php
Expand Up @@ -47,17 +47,3 @@ function php_mode() {

return $s_mode;
}

# If mb_* not defined, define it to map to standard methods.
if( !function_exists( 'mb_substr' ) ) {
/**
* Map mb_substr to utf8_substr if mb extension is not found
* @param string $p_text Text string.
* @param integer $p_index Start position.
* @param integer $p_size Size.
* @return string
*/
function mb_substr( $p_text, $p_index, $p_size ) {
return utf8_substr( $p_text, $p_index, $p_size );
}
}
6 changes: 3 additions & 3 deletions core/plugin_api.php
Expand Up @@ -511,7 +511,7 @@ function plugin_dependency( $p_base_name, $p_required, $p_initialized = false )
# their code, adapt it if necessary, and release a new version of the
# plugin with updated dependencies.
if( $p_base_name == 'MantisCore' && strpos( $p_required, '<' ) === false ) {
$t_version_core = utf8_substr( $t_plugin_version, 0, strpos( $t_plugin_version, '.' ) );
$t_version_core = mb_substr( $t_plugin_version, 0, strpos( $t_plugin_version, '.' ) );
$t_is_current_core_supported = false;
foreach( $t_required_array as $t_version_required ) {
$t_is_current_core_supported = $t_is_current_core_supported
Expand All @@ -530,12 +530,12 @@ function plugin_dependency( $p_base_name, $p_required, $p_initialized = false )
# check for a less-than-or-equal version requirement
$t_ltpos = strpos( $t_required, '<=' );
if( $t_ltpos !== false ) {
$t_required = trim( utf8_substr( $t_required, $t_ltpos + 2 ) );
$t_required = trim( mb_substr( $t_required, $t_ltpos + 2 ) );
$t_maximum = true;
} else {
$t_ltpos = strpos( $t_required, '<' );
if( $t_ltpos !== false ) {
$t_required = trim( utf8_substr( $t_required, $t_ltpos + 1 ) );
$t_required = trim( mb_substr( $t_required, $t_ltpos + 1 ) );
$t_maximum = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/relationship_api.php
Expand Up @@ -804,7 +804,7 @@ function relationship_get_details( $p_bug_id, BugRelationshipData $p_relationshi
if( mb_strlen( $t_bug->summary ) <= $t_summary_wrap_at ) {
$t_relationship_info_text .= string_email_links( $t_bug->summary );
} else {
$t_relationship_info_text .= utf8_substr( string_email_links( $t_bug->summary ), 0, $t_summary_wrap_at - 3 ) . '...';
$t_relationship_info_text .= mb_substr( string_email_links( $t_bug->summary ), 0, $t_summary_wrap_at - 3 ) . '...';
}
}

Expand Down
8 changes: 4 additions & 4 deletions core/string_api.php
Expand Up @@ -66,7 +66,7 @@ function string_preserve_spaces_at_bol( $p_string ) {
$t_count = 0;
$t_prefix = '';

$t_char = utf8_substr( $t_lines[$i], $t_count, 1 );
$t_char = mb_substr( $t_lines[$i], $t_count, 1 );
$t_spaces = 0;
while( ( $t_char == ' ' ) || ( $t_char == "\t" ) ) {
if( $t_char == ' ' ) {
Expand All @@ -78,14 +78,14 @@ function string_preserve_spaces_at_bol( $p_string ) {
# 1 tab = 4 spaces, can be configurable.

$t_count++;
$t_char = utf8_substr( $t_lines[$i], $t_count, 1 );
$t_char = mb_substr( $t_lines[$i], $t_count, 1 );
}

for( $j = 0;$j < $t_spaces;$j++ ) {
$t_prefix .= '&#160;';
}

$t_lines[$i] = $t_prefix . utf8_substr( $t_lines[$i], $t_count );
$t_lines[$i] = $t_prefix . mb_substr( $t_lines[$i], $t_count );
}
return implode( "\n", $t_lines );
}
Expand Down Expand Up @@ -838,7 +838,7 @@ function string_shorten( $p_string, $p_max = null ) {
$t_last_len = strlen( $t_last );

if( count( $t_bits ) == 1 ) {
$t_string .= utf8_substr( $t_last, 0, $t_max - 3 );
$t_string .= mb_substr( $t_last, 0, $t_max - 3 );
$t_string .= '...';
} else {
foreach( $t_bits as $t_bit ) {
Expand Down
2 changes: 1 addition & 1 deletion core/tag_api.php
Expand Up @@ -393,7 +393,7 @@ function tag_parse_filters( $p_string ) {
if( !is_blank( $t_name ) && tag_name_is_valid( $t_name, $t_matches, $t_prefix ) ) {
$t_tag_row = tag_get_by_name( $t_matches[1] );
if( $t_tag_row !== false ) {
$t_filter = utf8_substr( $t_name, 0, 1 );
$t_filter = mb_substr( $t_name, 0, 1 );

if( '+' == $t_filter ) {
$t_tag_row['filter'] = 1;
Expand Down
2 changes: 1 addition & 1 deletion csv_export.php
Expand Up @@ -91,7 +91,7 @@
# Fixed for a problem in Excel where it prompts error message "SYLK: File Format Is Not Valid"
# See Microsoft Knowledge Base Article - 323626
# http://support.microsoft.com/default.aspx?scid=kb;en-us;323626&Product=xlw
$t_first_three_chars = utf8_substr( $t_header, 0, 3 );
$t_first_three_chars = mb_substr( $t_header, 0, 3 );
if( strcmp( $t_first_three_chars, 'ID' . $t_sep ) == 0 ) {
$t_header = str_replace( 'ID' . $t_sep, 'Id' . $t_sep, $t_header );
}
Expand Down
2 changes: 1 addition & 1 deletion issues_rss.php
Expand Up @@ -156,7 +156,7 @@
# add missing : in the O part of the date. PHP 5 supports a 'c' format which will output the format
# exactly as we want it.
# 2002-10-02T10:00:00-0500 -> 2002-10-02T10:00:00-05:00
$t_base = utf8_substr( $t_base, 0, 22 ) . ':' . utf8_substr( $t_base, -2 );
$t_base = mb_substr( $t_base, 0, 22 ) . ':' . mb_substr( $t_base, -2 );

$t_rssfile->addSYdata( $t_period, $t_frequency, $t_base );

Expand Down
2 changes: 1 addition & 1 deletion news_rss.php
Expand Up @@ -129,7 +129,7 @@
# add missing : in the O part of the date. @todo PHP 5 supports a 'c' format which will output the format
# exactly as we want it.
# 2002-10-02T10:00:00-0500 -> 2002-10-02T10:00:00-05:00
$t_base = utf8_substr( $t_base, 0, 22 ) . ':' . utf8_substr( $t_base, -2 );
$t_base = mb_substr( $t_base, 0, 22 ) . ':' . mb_substr( $t_base, -2 );

$t_rssfile->addSYdata( $t_period, $t_frequency, $t_base );

Expand Down
2 changes: 1 addition & 1 deletion plugins/MantisGraph/pages/issues_trend_bystatus_table.php
Expand Up @@ -148,7 +148,7 @@
# @todo - these should probably be separate strings, but in the summary page context,
# the string is used as the title for all columns
$t_label_string = lang_get( 'orct' ); # use the (open/resolved/closed/total) label
$t_label_strings = explode( '/', utf8_substr( $t_label_string, 1, strlen( $t_label_string ) - 2 ) );
$t_label_strings = explode( '/', mb_substr( $t_label_string, 1, strlen( $t_label_string ) - 2 ) );

# add headers for table
$t_date_format = config_get( 'short_date_format' );
Expand Down
2 changes: 1 addition & 1 deletion print_all_bug_page_word.php
Expand Up @@ -548,7 +548,7 @@
switch ( $t_bugnote->note_type ) {
case REMINDER:
echo lang_get( 'reminder_sent_to' ) . ': ';
$t_note_attr = utf8_substr( $t_bugnote->note_attr, 1, mb_strlen( $t_bugnote->note_attr ) - 2 );
$t_note_attr = mb_substr( $t_bugnote->note_attr, 1, mb_strlen( $t_bugnote->note_attr ) - 2 );
$t_to = array();
foreach ( explode( '|', $t_note_attr ) as $t_recipient ) {
$t_to[] = prepare_user_name( $t_recipient );
Expand Down
6 changes: 3 additions & 3 deletions return_dynamic_filters.php
Expand Up @@ -90,16 +90,16 @@ function return_dynamic_filters_prepend_headers() {
}

$f_filter_target = gpc_get_string( 'filter_target' );
$filter_target = utf8_substr( $f_filter_target, 0, -7 ); # -7 for '_filter'
$filter_target = mb_substr( $f_filter_target, 0, -7 ); # -7 for '_filter'
$t_found = false;
$t_content = @call_user_func_array( 'filter_form_get_input', array( $t_filter, $filter_target, true ) );
if( false !== $t_content ) {
return_dynamic_filters_prepend_headers();
$t_found = true;
echo $t_content;
} else if( 'custom_field' == utf8_substr( $f_filter_target, 0, 12 ) ) {
} else if( 'custom_field' == mb_substr( $f_filter_target, 0, 12 ) ) {
# custom function
$t_custom_id = utf8_substr( $f_filter_target, 13, -7 );
$t_custom_id = mb_substr( $f_filter_target, 13, -7 );
$t_cfdef = @custom_field_get_definition( $t_custom_id );
# Check existence of custom field id, and if the user have access to read and filter by
if( $t_cfdef && access_has_any_project_level( $t_cfdef['access_level_r'] ) && $t_cfdef['filter_by'] ) {
Expand Down
2 changes: 1 addition & 1 deletion search.php
Expand Up @@ -135,7 +135,7 @@
$t_custom_fields = array();
foreach( $_GET as $t_var_name => $t_var_value ) {
if( strpos( $t_var_name, 'custom_field_' ) === 0 ) {
$t_custom_field_id = utf8_substr( $t_var_name, 13 );
$t_custom_field_id = mb_substr( $t_var_name, 13 );
$t_custom_fields[$t_custom_field_id] = $t_var_value;
}
}
Expand Down

0 comments on commit 292c704

Please sign in to comment.