Uploaded image for project: 'James Server'
  1. James Server
  2. JAMES-58

SqlResources.substituteSubString(): more than one replacement of one parameter may fail

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Resolution: Fixed
    • None
    • None
    • James Core
    • None
    • Operating System: All
      Platform: All
    • 12855

    Description

      in package org.apache.james.util.SqlResources.substituteSubString() you better should
      write
      while ( index > -1 )

      { [...] index = input.indexOf(find, index + /*replace_length*/ find_length); }

      to find all occurrences of one parameter in the input
      string.

      TestCase:
      public void testSubstituteSubString() {

      String subst = null;

      subst = sr.substituteSubString("${aa} ${aa}", "${aa}", "Test" );
      assertEquals( "double
      replacement one after another", "Test Test", subst );

      subst =
      sr.substituteSubString("${aa}${aa}", "${aa}", "Test" );
      assertEquals( "double
      replacement one after another without spaces", "TestTest", subst );

      subst =
      sr.substituteSubString("Ein ${k} ${k}", "${k}", "langerTest" );
      assertEquals( "double
      replacement where NEW is longer than OLD", "Ein langerTest langerTest", subst );

      subst =
      sr.substituteSubString("Ein ${keyword} ${keyword}", "${keyword}", "T" );

      assertEquals( "double replacement where NEW is shorter than OLD", "Ein T T", subst );

      subst
      = sr.substituteSubString("Ein ${keyword} ${keyword}", "${keyword}", "Testwort12" );

      assertEquals( "double replacement where NEW is as long as OLD", "Ein Testwort12 Testwort12",
      subst );
      }

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            kai.heinecke@hamburg.de Kai Heinecke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment