[jira] [Created] (LANG-811) StringUtils.stripStart strips out too many characters

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Created] (LANG-811) StringUtils.stripStart strips out too many characters

David Mollitor (Jira)
Chris Kelly created LANG-811:
--------------------------------

             Summary: StringUtils.stripStart strips out too many characters
                 Key: LANG-811
                 URL: https://issues.apache.org/jira/browse/LANG-811
             Project: Commons Lang
          Issue Type: Bug
          Components: lang.*
    Affects Versions: 3.1, 3.0, 2.6, 2.5
         Environment: N/A
            Reporter: Chris Kelly


I have a String "Tag-TransactionId" for which I want to remove the leading "Tag-" leaving only "TransactionId". I thought I could use StringUtils.stripStart for this but when I do I get the string "ransactionId" instead.

Below is a short method indicating the issue.



 public static void main(String[] args) {
       
        String key = "Tag-TransactionId";

        String keyWithoutTag = StringUtils.stripStart(key, "Tag-");
       
        String expected = "TransactionId";

        System.out.println("Expected: " + expected + " but got: " + keyWithoutTag);
       
    }


I have tried repeating test on commons-lang from 2.5 upwards to the latest release all with the same behaviour. It looks like if the string to be removed has characters similar to the remaining string, the stripStart methods works incorrectly. It seems to be a case problem as well. If I use "Tag-transactionId" with stripStart it successfully returns "transactionId"

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Resolved] (LANG-811) StringUtils.stripStart strips out too many characters

David Mollitor (Jira)

     [ https://issues.apache.org/jira/browse/LANG-811?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sebb resolved LANG-811.
-----------------------

    Resolution: Invalid

From the Javadoc for stripStart():

Strips any of a *set* of characters from the start of a String.

It treats the "Tag-" as the set of characters 'T' 'a' 'g' '-' and removes any it finds from the start of the the string. 'T' appears twice, so is removed both times.
               

> StringUtils.stripStart strips out too many characters
> ------------------------------------------------------
>
>                 Key: LANG-811
>                 URL: https://issues.apache.org/jira/browse/LANG-811
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.*
>    Affects Versions: 2.5, 2.6, 3.0, 3.1
>         Environment: N/A
>            Reporter: Chris Kelly
>              Labels: api-change
>
> I have a String "Tag-TransactionId" for which I want to remove the leading "Tag-" leaving only "TransactionId". I thought I could use StringUtils.stripStart for this but when I do I get the string "ransactionId" instead.
> Below is a short method indicating the issue.
>  public static void main(String[] args) {
>        
>         String key = "Tag-TransactionId";
>         String keyWithoutTag = StringUtils.stripStart(key, "Tag-");
>        
>         String expected = "TransactionId";
>         System.out.println("Expected: " + expected + " but got: " + keyWithoutTag);
>        
>     }
> I have tried repeating test on commons-lang from 2.5 upwards to the latest release all with the same behaviour. It looks like if the string to be removed has characters similar to the remaining string, the stripStart methods works incorrectly. It seems to be a case problem as well. If I use "Tag-transactionId" with stripStart it successfully returns "transactionId"

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (LANG-811) StringUtils.stripStart strips out too many characters

David Mollitor (Jira)
In reply to this post by David Mollitor (Jira)

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

Matt Benson commented on LANG-811:
----------------------------------

To be helpful:  I think the functionality you're looking for is expressed by {{StringUtils#removeStart()}} :)
               

> StringUtils.stripStart strips out too many characters
> ------------------------------------------------------
>
>                 Key: LANG-811
>                 URL: https://issues.apache.org/jira/browse/LANG-811
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.*
>    Affects Versions: 2.5, 2.6, 3.0, 3.1
>         Environment: N/A
>            Reporter: Chris Kelly
>              Labels: api-change
>
> I have a String "Tag-TransactionId" for which I want to remove the leading "Tag-" leaving only "TransactionId". I thought I could use StringUtils.stripStart for this but when I do I get the string "ransactionId" instead.
> Below is a short method indicating the issue.
>  public static void main(String[] args) {
>        
>         String key = "Tag-TransactionId";
>         String keyWithoutTag = StringUtils.stripStart(key, "Tag-");
>        
>         String expected = "TransactionId";
>         System.out.println("Expected: " + expected + " but got: " + keyWithoutTag);
>        
>     }
> I have tried repeating test on commons-lang from 2.5 upwards to the latest release all with the same behaviour. It looks like if the string to be removed has characters similar to the remaining string, the stripStart methods works incorrectly. It seems to be a case problem as well. If I use "Tag-transactionId" with stripStart it successfully returns "transactionId"

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira