#166 xoops_substr() shouldn't use mb_strimwidth

XOOPS_2.0.x
closed
Skalpa Keo
5
2012-09-25
2004-06-01
toshimitsu
No

in edituser.php
If there are 255 bytes or more , multi-byte Text of in
user_sig or bio .

When a browser is IE, it becomes impossible to display
correctly and commnt form post also becomes impossible

The part at edituser.php which the problem has
generated

edituser.php line 95
$edituser->setVar('user_sig', xoops_substr($user_sig, 0,
255));
edituser.php line 111
$edituser->setVar('user_sig', xoops_substr($user_sig, 0,
255));

Cause:
xoops_substr corresponds also to a multi-byte and is a
good idea. but.
However, the mb_strimwidth function currently used
there may not function correctly.
It is the case where the new-line escape sequence is
contained in text area.


This was discussed at the forum of jp.xoops.org.
http://jp.xoops.org/modules/newbb/viewtopic.php?
topic_id=2704&forum=12

Please use a mb_strcut function instead of a
mb_strimwidth function in xoops_substr.


include/
function xoops_substr($str, $start, $length, $trimmarker
= '...')
{
if ( !XOOPS_USE_MULTIBYTES ) {
return ( strlen($str) - $start <=
$length ) ? substr( $str, $start, $length ) : substr( $str,
$start, $length - strlen($trimmarker) ) . $trimmarker;
}
if (function_exists('mb_internal_encoding') &&
@mb_internal_encoding(_CHARSET)) {
return mb_strimwidth($str, $start,
$length, $trimmarker, _CHARSET);
}
}

--

to

--

function xoops_substr($str, $start, $length, $trimmarker
= '...')
{
if( strlen( $str ) <= $length ) return $str;
if (XOOPS_USE_MULTIBYTES == 1 && function_exists
('mb_internal_encoding') && @mb_internal_encoding
(_CHARSET)) {
return mb_strcut( $str , $start , $length - strlen(
$trimmarker ) ) . $trimmarker ;
}
return substr($str, $start, $length - strlen
($trimmarker)).$trimmarker;
}

--
If mb_strcut function is used, xoops_substr will function
correctly .

Discussion

  • toshimitsu
    toshimitsu
    2004-06-01

    Logged In: YES
    user_id=926983


    a while ago report write and it is a mistake.

    I wanted to write this part.
    The part at edituser.php which the problem has generated
    edituser.php line 95
    $edituser->setVar('user_sig', xoops_substr($user_sig, 0,
    255));
    edituser.php line 111
    $edituser->setVar('bio', xoops_substr($bio, 0, 255));

     
  • Skalpa Keo
    Skalpa Keo
    2004-06-06

    Logged In: YES
    user_id=882380

    ok. am checking this right now.

     
  • Skalpa Keo
    Skalpa Keo
    2004-06-07

    Logged In: YES
    user_id=882380

    I have just tried to correct this, but my testbox isn't
    configured for mbyte and I don't have the time to install
    this right now.
    So can you please get the corrected include/functions.php
    file from CVS or SF.net web cvs to test by yourself (you
    need @ least revision 1.65.8.2).
    Thanks a lot for your feedback.

     
  • toshimitsu
    toshimitsu
    2004-06-07

    Logged In: YES
    user_id=926983

    from CVS or SF.net
    I tried  include/functions.php revision 1.65.8.2 :
    This FIX operated completely.
    It is wonderful. Thank you skalpa.