FELIX-3730 validate value string length when validating string typed attribues.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1401839 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/metatype/src/main/java/org/apache/felix/metatype/AD.java b/metatype/src/main/java/org/apache/felix/metatype/AD.java
index 15b40d0..8899ccf 100644
--- a/metatype/src/main/java/org/apache/felix/metatype/AD.java
+++ b/metatype/src/main/java/org/apache/felix/metatype/AD.java
@@ -181,32 +181,81 @@
return null;
}
- Comparable value = convertToType( valueString );
- if ( value == null )
+ // min/max for strings and passwords indicates the length
+ final Comparable value;
+ if ( getType() == AttributeDefinition.STRING || getType() == AttributeDefinition.PASSWORD )
{
- if ( isRequired() )
+ if ( valueString == null )
{
- return VALIDATE_MISSING;
+ if ( isRequired() )
+ {
+ return VALIDATE_MISSING;
+ }
+
+ return ""; // accept null value
}
- return ""; // accept null value
- }
-
- Comparable other = convertToType( getMin() );
- if ( other != null )
- {
- if ( value.compareTo( other ) < 0 )
+ if ( getMin() != null )
{
- return VALIDATE_LESS_THAN_MINIMUM;
+ try
+ {
+ if ( valueString.length() < Integer.parseInt( getMin() ) )
+ {
+ return VALIDATE_LESS_THAN_MINIMUM;
+ }
+ }
+ catch ( NumberFormatException nfe )
+ {
+ // cannot check min length
+ }
}
- }
- other = convertToType( getMax() );
- if ( other != null )
- {
- if ( value.compareTo( other ) > 0 )
+ if ( getMax() != null )
{
- return VALIDATE_GREATER_THAN_MAXIMUM;
+ try
+ {
+ if ( valueString.length() > Integer.parseInt( getMax() ) )
+ {
+ return VALIDATE_GREATER_THAN_MAXIMUM;
+ }
+ }
+ catch ( NumberFormatException nfe )
+ {
+ // cannot check min length
+ }
+ }
+
+ value = valueString;
+ }
+ else
+ {
+ value = convertToType( valueString );
+ if ( value == null )
+ {
+ if ( isRequired() )
+ {
+ return VALIDATE_MISSING;
+ }
+
+ return ""; // accept null value
+ }
+
+ Comparable other = convertToType( getMin() );
+ if ( other != null )
+ {
+ if ( value.compareTo( other ) < 0 )
+ {
+ return VALIDATE_LESS_THAN_MINIMUM;
+ }
+ }
+
+ other = convertToType( getMax() );
+ if ( other != null )
+ {
+ if ( value.compareTo( other ) > 0 )
+ {
+ return VALIDATE_GREATER_THAN_MAXIMUM;
+ }
}
}
@@ -215,7 +264,7 @@
{
for ( int i = 0; i < optionValues.length; i++ )
{
- other = convertToType( optionValues[i] );
+ Comparable other = convertToType( optionValues[i] );
if ( value.compareTo( other ) == 0 )
{
// one of the option values