ValidationUtils { public static boolean expressionIsValidSQl( String filter ) { if ( filter == null ) { return true; } if ( TextUtils.containsAnyIgnoreCase( filter, ILLEGAL_SQL_KEYWORDS ) ) { return false; } for ( int i = 0; i < filter.length(); i++ ) { char ch = filter.charAt( i ); if ( !(Character.isWhitespace( ch ) || Character.isLetterOrDigit( ch ) || SQL_VALID_CHARS.contains( ch )) ) { return false; } } return true; }  static boolean expressionIsValidSQl( String filter ); static boolean emailIsValid( String email ); static boolean dateIsValid( String date, Locale locale ); static boolean dateIsValid( String date ); static boolean timeIsValid( String time ); static boolean urlIsValid( String url ); static boolean uuidIsValid( String uuid ); static boolean usernameIsValid( String username ); static boolean passwordIsValid( String password ); static boolean coordinateIsValid( String coordinate ); static boolean bboxIsValid( String bbox ); static String getLongitude( String coordinate ); static String getLatitude( String coordinate ); static Point2D getCoordinatePoint2D( String coordinate ); static String getCoordinate( String longitude, String latitude ); static String dataValueIsValid( String value, DataElement dataElement ); static String dataValueIsValid( String value, ValueType valueType ); static boolean dataValueIsZeroAndInsignificant( String value, DataElement dataElement ); static String commentIsValid( String comment ); static String storedByIsValid( String storedBy ); static boolean isValidHexColor( String value ); static Object getSubstitutionValue( ValueType valueType ); static String normalizeBoolean( String bool, ValueType valueType ); static boolean validateRenderingType( Class<?> clazz, ValueType valueType, boolean optionSet, ValueTypeRenderingType type ); static boolean validateWhatsapp( String whatsapp ); static boolean validateInternationalPhoneNumber( String phoneNumber ); static final ImmutableSet<String> ILLEGAL_SQL_KEYWORDS; }
@Test public void testExpressionIsValidSQl() { assertFalse( expressionIsValidSQl( "10 == 10; delete from table" ) ); assertFalse( expressionIsValidSQl( "select from table" ) ); assertTrue( expressionIsValidSQl( "\"abcdef12345\" < 30" ) ); assertTrue( expressionIsValidSQl( "\"abcdef12345\" >= \"bcdefg23456\"" ) ); assertTrue( expressionIsValidSQl( "\"DO0v7fkhUNd\" > -30000 and \"DO0v7fkhUNd\" < 30000" ) ); assertTrue( expressionIsValidSQl( "\"oZg33kd9taw\" == 'Female'" ) ); assertTrue( expressionIsValidSQl( "\"oZg33kd9taw\" == 'Female' and \"qrur9Dvnyt5\" <= 5" ) ); }