Skip to content

Commit fda9e90

Browse files
committed
Fix codehaus-plexus#3 : Filtering fails when target contains multiple escapes
1 parent 8ccb8a9 commit fda9e90

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/main/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterStringSearchInterpolator.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,17 @@ private String interpolate( String input, RecursionInterceptor recursionIntercep
201201

202202
if ( startIdx >= 0 && escapeString != null && escapeString.length() > 0 )
203203
{
204-
int startEscapeIdx = startIdx == 0 ? 0 : startIdx - escapeString.length();
204+
int startEscapeIdx = ( startIdx == 0 ) ? 0 : startIdx - escapeString.length();
205205
if ( startEscapeIdx >= 0 )
206206
{
207207
String escape = input.substring( startEscapeIdx, startIdx );
208208
if ( escape != null && escapeString.equals( escape ) )
209209
{
210210
result.append( wholeExpr );
211+
if ( startEscapeIdx > 0 )
212+
{
213+
--startEscapeIdx;
214+
}
211215
result.replace( startEscapeIdx, startEscapeIdx + escapeString.length(), "" );
212216
continue;
213217
}

src/test/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterStringSearchInterpolatorTest.java

+18
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,22 @@ public void testInterpolationWithMultipleEscapes()
8585
assertEquals( "#${first} and ${last}", result );
8686
}
8787

88+
public void testInterpolationWithMultipleEscapes2()
89+
throws InterpolationException
90+
{
91+
Map ctx = new HashMap();
92+
ctx.put( "name", "User" );
93+
ctx.put( "otherName", "#${first} and ##${last}" );
94+
95+
String input = "${otherName}";
96+
97+
ValueSource vs = new MapBasedValueSource( ctx );
98+
MultiDelimiterStringSearchInterpolator interpolator =
99+
new MultiDelimiterStringSearchInterpolator().withValueSource( vs );
100+
interpolator.setEscapeString( "#" );
101+
102+
String result = interpolator.interpolate( input );
103+
104+
assertEquals( "${first} and #${last}", result );
105+
}
88106
}

0 commit comments

Comments
 (0)