1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Fixed XenForo_Helper_String::wholeWordTrim can go slightly over

Discussion in 'Resolved Bug Reports' started by Jim Boy, Nov 23, 2014.

  1. Jim Boy

    Jim Boy Well-Known Member

    Not sure if this should be classed as a bug or an improvement, but the XenForo_Helper_String::wholeWordTrim doesn't take into account the bit at the end when the length is longer than the nominated value:

    For example if I have the following text:

    "a b c d e" which is 9 characters long and I was to apply a wholeWordTrim of 8 characters, the result would be "a b c d..." assuming I accept the defaults, which is 10 characters long. Ideally I should be getting "a b c..." which is 8 characters long. I could allow for those elipses and apply a limit of 5 characters so that it would return "a b c d...", but then I would be unnecessarily trimming the text if my original string request was 7 or 8 characters long. This has been an issue for me in addon development where strict string limits are being applied such as in thread title or twitter submissions.

    Ideally the function should measure the length of the string submitted and the appended bit. then apply the following rules

    if string length is <= length limit, return the string
    else trim to (length limit - length of appendage), add appendage and return.
    Xon likes this.
  2. Mike

    Mike XenForo Developer Staff Member

    This should be fixed for the next release for all cases (including when there's an offset).
    Jim Boy likes this.

Share This Page