Skip to content

Fix #3 : Filtering fails when target contains multiple escapes #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 );
}
}