Skip to content

Commit

Permalink
Merge pull request #7 from belingueres/Fix3
Browse files Browse the repository at this point in the history
Fix #3 : Filtering fails when target contains multiple escapes
  • Loading branch information
olamy authored Nov 8, 2016
2 parents de0ef57 + fda9e90 commit 8091398
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,17 @@ private String interpolate( String input, RecursionInterceptor recursionIntercep

if ( startIdx >= 0 && escapeString != null && escapeString.length() > 0 )
{
int startEscapeIdx = startIdx == 0 ? 0 : startIdx - escapeString.length();
int startEscapeIdx = ( startIdx == 0 ) ? 0 : startIdx - escapeString.length();
if ( startEscapeIdx >= 0 )
{
String escape = input.substring( startEscapeIdx, startIdx );
if ( escape != null && escapeString.equals( escape ) )
{
result.append( wholeExpr );
if ( startEscapeIdx > 0 )
{
--startEscapeIdx;
}
result.replace( startEscapeIdx, startEscapeIdx + escapeString.length(), "" );
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,22 @@ public void testInterpolationWithMultipleEscapes()
assertEquals( "#${first} and ${last}", result );
}

public void testInterpolationWithMultipleEscapes2()
throws InterpolationException
{
Map ctx = new HashMap();
ctx.put( "name", "User" );
ctx.put( "otherName", "#${first} and ##${last}" );

String input = "${otherName}";

ValueSource vs = new MapBasedValueSource( ctx );
MultiDelimiterStringSearchInterpolator interpolator =
new MultiDelimiterStringSearchInterpolator().withValueSource( vs );
interpolator.setEscapeString( "#" );

String result = interpolator.interpolate( input );

assertEquals( "${first} and #${last}", result );
}
}

0 comments on commit 8091398

Please sign in to comment.