mirror of
https://github.com/apache/maven.git
synced 2025-02-20 17:05:35 +00:00
[MNG-6629] - Make ID validation faster
Use a simple list of allowed characters instead of a regex.
This commit is contained in:
parent
80c6fe3a01
commit
baed5a294f
@ -73,10 +73,6 @@ public class DefaultModelValidator
|
||||
AbstractStringBasedModelInterpolator.CHANGELIST_PROPERTY,
|
||||
AbstractStringBasedModelInterpolator.SHA1_PROPERTY );
|
||||
|
||||
private static final Pattern ID_REGEX = Pattern.compile( "[A-Za-z0-9_\\-.]+" );
|
||||
|
||||
private static final Pattern ID_WITH_WILDCARDS_REGEX = Pattern.compile( "[A-Za-z0-9_\\-.?*]+" );
|
||||
|
||||
private static final String ILLEGAL_FS_CHARS = "\\/:\"<>|?*";
|
||||
|
||||
private static final String ILLEGAL_VERSION_CHARS = ILLEGAL_FS_CHARS;
|
||||
@ -829,16 +825,35 @@ private boolean validateId( String fieldName, ModelProblemCollector problems, Se
|
||||
}
|
||||
else
|
||||
{
|
||||
boolean match = ID_REGEX.matcher( id ).matches();
|
||||
if ( !match )
|
||||
if ( !isValidId( id ) )
|
||||
{
|
||||
addViolation( problems, severity, version, fieldName, sourceHint,
|
||||
"with value '" + id + "' does not match a valid id pattern.", tracker );
|
||||
return false;
|
||||
}
|
||||
return match;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isValidId( String id )
|
||||
{
|
||||
for ( int i = 0; i < id.length(); i++ )
|
||||
{
|
||||
char c = id.charAt( i );
|
||||
if ( !isValidIdCharacter( c ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private boolean isValidIdCharacter( char c )
|
||||
{
|
||||
return c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c == '-' || c == '_' || c == '.';
|
||||
}
|
||||
|
||||
private boolean validateIdWithWildcards( String fieldName, ModelProblemCollector problems, Severity severity,
|
||||
Version version, String id, String sourceHint,
|
||||
InputLocationTracker tracker )
|
||||
@ -849,16 +864,34 @@ private boolean validateIdWithWildcards( String fieldName, ModelProblemCollector
|
||||
}
|
||||
else
|
||||
{
|
||||
boolean match = ID_WITH_WILDCARDS_REGEX.matcher( id ).matches();
|
||||
if ( !match )
|
||||
if ( !isValidIdWithWildCards( id ) )
|
||||
{
|
||||
addViolation( problems, severity, version, fieldName, sourceHint,
|
||||
"with value '" + id + "' does not match a valid id pattern.", tracker );
|
||||
return false;
|
||||
}
|
||||
return match;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isValidIdWithWildCards( String id )
|
||||
{
|
||||
for ( int i = 0; i < id.length(); i++ )
|
||||
{
|
||||
char c = id.charAt( i );
|
||||
if ( !isValidIdWithWildCardCharacter( c ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isValidIdWithWildCardCharacter( char c )
|
||||
{
|
||||
return isValidIdCharacter( c ) || c == '?' || c == '*';
|
||||
}
|
||||
|
||||
private boolean validateStringNoExpression( String fieldName, ModelProblemCollector problems, Severity severity,
|
||||
Version version, String string, InputLocationTracker tracker )
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user