Skip to content

Commit

Permalink
Prevent unwanted line breaks in <pre> tags
Browse files Browse the repository at this point in the history
By default, Mantis wraps text within <pre> tags at 100 chars (see
$g_wrap_in_preformatted_text option).

If the text within the tag contains Unicode extended characters, the
regex performing the wrap does not count them properly, as pcre works on
bytes, causing line breaks to be added in the wrong place.

Adding 'u' modifier to the regex fixes the behavior, as suggested by
cproensa.

Fixes #21410
  • Loading branch information
dregad committed Aug 9, 2016
1 parent b0389ec commit ba89d0e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/string_api.php
Expand Up @@ -123,7 +123,8 @@ function string_nl2br( $p_string, $p_wrap = 100 ) {
# if other encoded characters are a problem
$t_piece = preg_replace( '/&#160;/', ' ', $t_piece );
if( ON == config_get( 'wrap_in_preformatted_text' ) ) {
$t_output .= preg_replace( '/([^\n]{' . $p_wrap . ',}?[\s]+)(?!<\/pre>)/', "$1\n", $t_piece );
# Use PCRE_UTF8 modifier to ensure a correct char count
$t_output .= preg_replace( '/([^\n]{' . $p_wrap . ',}?[\s]+)(?!<\/pre>)/u', "$1", $t_piece );
} else {
$t_output .= $t_piece;
}
Expand Down

0 comments on commit ba89d0e

Please sign in to comment.