Skip to content

Commit

Permalink
Truncate values before writing to database history table
Browse files Browse the repository at this point in the history
TEXTAREA custom fields can contain more than 255 characters.
Changing such fields fails, as the new value can't be stored
in history table.

This change fixes the issue by truncating the string.
See #24056 for other options to fix it.

Fixes #24056
  • Loading branch information
atrol committed Mar 7, 2018
1 parent 4ca27bb commit 339cf88
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions core/constant_inc.php
Expand Up @@ -604,6 +604,7 @@
define( 'DB_FIELD_SIZE_REALNAME', 255 );
define( 'DB_FIELD_SIZE_PASSWORD', 64 );
define( 'DB_FIELD_SIZE_API_TOKEN_NAME', 128 );
define( 'DB_FIELD_SIZE_HISTORY_VALUE', 255 );

# Maximum size for the user's password when storing it as a hash
define( 'PASSWORD_MAX_SIZE_BEFORE_HASH', 1024 );
Expand Down
8 changes: 7 additions & 1 deletion core/history_api.php
Expand Up @@ -82,7 +82,11 @@ function history_log_event_direct( $p_bug_id, $p_field_name, $p_old_value, $p_ne

$c_field_name = $p_field_name;
$c_old_value = ( is_null( $p_old_value ) ? '' : (string)$p_old_value );
$c_new_value = ( is_null( $p_new_value ) ? '' : (string)$p_new_value );
if( is_null( $p_new_value ) ) {
$c_new_value = '';
} else {
$c_new_value = mb_strimwidth( $p_new_value, 0, DB_FIELD_SIZE_HISTORY_VALUE, '...' );
}

db_param_push();
$t_query = 'INSERT INTO {bug_history}
Expand Down Expand Up @@ -123,6 +127,8 @@ function history_log_event_special( $p_bug_id, $p_type, $p_old_value = '', $p_ne
}
if( is_null( $p_new_value ) ) {
$p_new_value = '';
} else {
$p_new_value = mb_strimwidth( $p_new_value, 0, DB_FIELD_SIZE_HISTORY_VALUE, '...' );
}

db_param_push();
Expand Down

0 comments on commit 339cf88

Please sign in to comment.