mirror of https://github.com/apache/maven.git
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:
parent
f810fd2ef2
commit
39132c3e37
|
@ -164,7 +164,7 @@ public class RegexBasedModelInterpolator
|
|||
}
|
||||
|
||||
// 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." );
|
||||
}
|
||||
|
|
|
@ -22,7 +22,9 @@ import org.apache.maven.model.Dependency;
|
|||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Organization;
|
||||
import org.apache.maven.model.Repository;
|
||||
import org.apache.maven.model.Scm;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
@ -44,6 +46,27 @@ public class RegexBasedModelInterpolatorTest
|
|||
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()
|
||||
throws Exception
|
||||
{
|
||||
|
@ -179,8 +202,6 @@ public class RegexBasedModelInterpolatorTest
|
|||
|
||||
Model out = new RegexBasedModelInterpolator( envars ).interpolate( model, context );
|
||||
|
||||
System.out.println( ">>> " + out.getProperties().getProperty( "outputDirectory" ) );
|
||||
|
||||
assertEquals( out.getProperties().getProperty( "outputDirectory" ), "${env.DOES_NOT_EXIST}" );
|
||||
}
|
||||
|
||||
|
@ -197,8 +218,6 @@ public class RegexBasedModelInterpolatorTest
|
|||
|
||||
Model out = new RegexBasedModelInterpolator().interpolate( model, context );
|
||||
|
||||
System.out.println( ">>> " + out.getProperties().getProperty( "outputDirectory" ) );
|
||||
|
||||
assertEquals( out.getProperties().getProperty( "outputDirectory" ), "${DOES_NOT_EXIST}" );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue