Skip to content

Commit 2976eff

Browse files
committed
Fixed MultiDelimiterStringSearchInterpolator escape String code
1 parent 8ccb8a9 commit 2976eff

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,16 @@ 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+
--startEscapeIdx;
213+
}
211214
result.replace( startEscapeIdx, startEscapeIdx + escapeString.length(), "" );
212215
continue;
213216
}

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

Lines changed: 18 additions & 0 deletions
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 = new MultiDelimiterStringSearchInterpolator()
99+
.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)