Merging from 391857 on branch. Fixes infinite recursion when expressions self-reference as part of a larger value.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@391858 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2006-04-05 23:57:52 +00:00
parent f810fd2ef2
commit 39132c3e37
2 changed files with 24 additions and 5 deletions

View File

@ -164,7 +164,7 @@ public class RegexBasedModelInterpolator
} }
// if the expression refers to itself, skip it. // if the expression refers to itself, skip it.
if ( wholeExpr.equals( value ) ) if ( String.valueOf( value ).indexOf( realExpr ) > -1 )
{ {
throw new ModelInterpolationException( wholeExpr, model.getId() + " references itself." ); throw new ModelInterpolationException( wholeExpr, model.getId() + " references itself." );
} }

View File

@ -22,7 +22,9 @@ import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.model.Organization; import org.apache.maven.model.Organization;
import org.apache.maven.model.Repository; import org.apache.maven.model.Repository;
import org.apache.maven.model.Scm;
import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
@ -43,6 +45,27 @@ public class RegexBasedModelInterpolatorTest
context = Collections.singletonMap( "basedir", "myBasedir" ); context = Collections.singletonMap( "basedir", "myBasedir" );
} }
public void testShouldThrowExceptionOnRecursiveScmConnectionReference() throws IOException
{
Model model = new Model();
Scm scm = new Scm();
scm.setConnection( "${project.scm.connection}/somepath" );
model.setScm( scm );
try
{
Model out = new RegexBasedModelInterpolator().interpolate( model, context );
fail( "The interpolator should not allow self-referencing expressions in POM." );
}
catch ( ModelInterpolationException e )
{
}
}
public void testShouldInterpolateOrganizationNameCorrectly() public void testShouldInterpolateOrganizationNameCorrectly()
throws Exception throws Exception
@ -179,8 +202,6 @@ public class RegexBasedModelInterpolatorTest
Model out = new RegexBasedModelInterpolator( envars ).interpolate( model, context ); Model out = new RegexBasedModelInterpolator( envars ).interpolate( model, context );
System.out.println( ">>> " + out.getProperties().getProperty( "outputDirectory" ) );
assertEquals( out.getProperties().getProperty( "outputDirectory" ), "${env.DOES_NOT_EXIST}" ); assertEquals( out.getProperties().getProperty( "outputDirectory" ), "${env.DOES_NOT_EXIST}" );
} }
@ -197,8 +218,6 @@ public class RegexBasedModelInterpolatorTest
Model out = new RegexBasedModelInterpolator().interpolate( model, context ); Model out = new RegexBasedModelInterpolator().interpolate( model, context );
System.out.println( ">>> " + out.getProperties().getProperty( "outputDirectory" ) );
assertEquals( out.getProperties().getProperty( "outputDirectory" ), "${DOES_NOT_EXIST}" ); assertEquals( out.getProperties().getProperty( "outputDirectory" ), "${DOES_NOT_EXIST}" );
} }
} }