diff --git a/src/main/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterStringSearchInterpolator.java b/src/main/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterStringSearchInterpolator.java index 69d979d..88a1d61 100644 --- a/src/main/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterStringSearchInterpolator.java +++ b/src/main/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterStringSearchInterpolator.java @@ -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; } diff --git a/src/test/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterStringSearchInterpolatorTest.java b/src/test/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterStringSearchInterpolatorTest.java index d645785..6f49a21 100644 --- a/src/test/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterStringSearchInterpolatorTest.java +++ b/src/test/java/org/codehaus/plexus/interpolation/multi/MultiDelimiterStringSearchInterpolatorTest.java @@ -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 ); + } }