dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #35094
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18015: change validation for hex colors to also allow for xxx, xxxxxx instead of just #xxx, #xxxxxx
------------------------------------------------------------
revno: 18015
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-01-16 13:55:12 +0700
message:
change validation for hex colors to also allow for xxx, xxxxxx instead of just #xxx, #xxxxxx
modified:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/DefaultSchemaValidator.java
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/DefaultSchemaValidator.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/DefaultSchemaValidator.java 2015-01-15 09:50:45 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/DefaultSchemaValidator.java 2015-01-16 06:55:12 +0000
@@ -121,7 +121,7 @@
if ( PropertyType.COLOR == property.getPropertyType() && !ValidationUtils.isValidHexColor( value ) )
{
- validationViolations.add( new ValidationViolation( property.getName(), "Not a valid color (in hex format).", value ) );
+ validationViolations.add( new ValidationViolation( property.getName(), "Not a valid hex color.", value ) );
}
/* TODO add proper validation for both Points and Polygons, ValidationUtils only supports points at this time
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java 2014-12-22 09:56:13 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java 2015-01-16 06:55:12 +0000
@@ -374,7 +374,7 @@
}
/**
- * Checks to see if given parameter is a valid hex color string (#xxx and #xxxxxx).
+ * Checks to see if given parameter is a valid hex color string (#xxx and #xxxxxx, xxx, xxxxxx).
*
* @param value Value to check against
* @return true if value is a hex color string, false otherwise
@@ -386,21 +386,19 @@
return false;
}
- if ( !value.startsWith( "#" ) )
- {
- return false;
- }
-
- if ( !(value.length() == 4 || value.length() == 7) )
- {
- return false;
- }
-
- char[] chars = value.toCharArray();
-
- for ( int i = 1; i < chars.length; i++ )
- {
- if ( !Verifier.isHexDigit( chars[i] ) )
+ if ( value.startsWith( "#" ) )
+ {
+ value = value.substring( 1 );
+ }
+
+ if ( !(value.length() == 3 || value.length() == 6) )
+ {
+ return false;
+ }
+
+ for ( char aChar : value.toCharArray() )
+ {
+ if ( !Verifier.isHexDigit( aChar ) )
{
return false;
}