You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Ramesh Dhungel (Jira)" <ji...@apache.org> on 2019/11/02 17:11:00 UTC

[jira] [Commented] (LANG-1463) StringUtils abbreviate returns String of length greater than maxWidth

    [ https://issues.apache.org/jira/browse/LANG-1463?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16965426#comment-16965426 ] 

Ramesh Dhungel commented on LANG-1463:
--------------------------------------

In StringUtils.abbreviate in line 335 you are checking if the string is empty or the abbreviation marker is empty and if one of them is true its returning the original string. This means that for the string "much too long text" it is not empty however it is returning the exact string without the abbreviation because the abbreviation is empty. You can fix this by checking if only the string is empty and returning the string then add another if statement to check if the abbreviation is empty or null if it is then you would return the string abbreviated. However this causes an issue due to incorrect test case in line 305 in StringUtilsTest. It states that the max width is 10 and passes in the string"paranaguacu" which is a 11 letter string. However the excepted string is "paranaguacu" rather than "paranaguac".

> StringUtils abbreviate returns String of length greater than maxWidth
> ---------------------------------------------------------------------
>
>                 Key: LANG-1463
>                 URL: https://issues.apache.org/jira/browse/LANG-1463
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.*
>    Affects Versions: 3.9
>            Reporter: Thomas Wessendorf
>            Priority: Minor
>
> In the JavaDoc of StringUtils.abbreviate(final String str, final String abbrevMarker, final int maxWidth) is written, that the method in no case will return a String of length greater than maxWidth. This doesn't hold, if abbrevMarker is an empty string.
> Expected behaviour:
> abbreviate("much too long text", "", 13).equals("much too long")
>  
> Actual behaviour:
> abbreviate("much too long text", "", 13).equals("much too long text")



--
This message was sent by Atlassian Jira
(v8.3.4#803005)