private static final String REGEX_EMAIL = "[A-Za-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\\.[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\\.)+[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])??"; //$NON-NLS-1$
private static final String REGEX_URL = "\\b(https?)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]"; //$NON-NLS-1$
- private static final String REGEX_VERSION = "[0-9]{1,2}\\.[0-9]{1,2}(\\.[0-9]{1,4})?"; //$NON-NLS-1$
+ private static final String REGEX_VERSION = "[0-9]{1,3}\\.[0-9]{1,3}(\\.[0-9]{1,5})?"; //$NON-NLS-1$
private static final String REGEX_APPWIDGETID = "[0-9a-zA-Z]{10}\\.[0-9a-zA-Z]{1,52}\\.[0-9a-zA-Z]{1,}"; //$NON-NLS-1$
public static final String WIDGET_CONTENT_FILE_EXTENSIONS[] = { ".html", ".htm", ".xhtml", ".xht", ".svg" }; // http://www.w3.org/TR/widgets/#default-start-files
/**
* Checking for version.
- *
+ * The application version format has the following constraints: {xxx.yyy.zzzz} "0<={x,y}<=255, 0<=z<=65535"
* @param version
* @return {@code true} if version is valid version
*/
public static boolean checkForVersion( String version ) {
- if ( version == null || StringUtil.isEmpty( version ) || version.equals( "0.0" ) ) {
+ if ( version == null || StringUtil.isEmpty( version ) ) {
return false;
}
Pattern pattern = Pattern.compile( REGEX_VERSION );
Matcher matcher = pattern.matcher( version );
- return matcher.matches();
+ if ( matcher.matches() ) {
+ String[] versions = version.split("\\.");
+ // check version length: x.y(.z)
+ if ( versions.length < 3 ) {
+ return false;
+ }
+ // check x,y value: 0<=(x,y)<=255
+ for ( int index=0; index<2; index++ ) {
+ int xy = Integer.parseInt(versions[index]);
+ if ( xy < 0 || 255 < xy ) {
+ return false;
+ }
+ }
+ // check z value: 0<=z<=65535
+ int z = Integer.parseInt(versions[2]);
+ if ( z < 0 || 65535 < z ) {
+ return false;
+ }
+ return true;
+ } else {
+ return false;
+ }
}
/**
*/
@Test
public void test_checkForVersion() throws Exception {
- final String[] validedVersions = { "1.0.1", "1.0.111", "1.10.111", "35.35.123", "0.0.1", "0.1", "1.0", "0.0.0" };
+ final String[] validedVersions = { "0.0.0", "0.0.1", "0.1.0", "1.0.0", "1.0.1", "1.1.1", "0.0.00001", "000.000.00001", "000.001.00000", "001.000.00000", "001.001.00001", "255.0.0", "0.255.0", "0.0.65535", "255.255.65535" };
for ( String version : validedVersions ) {
assertTrue( "Failed for \"" + version + "\"", ValidationUtil.checkForVersion( version ) );
}
- final String[] invalidedVersions = { "", "111.111.111111", "1", "1.0.", "0" };
+ final String[] invalidedVersions = { "", "256.256.65536", "0", "0.0.", "1", "256.0.0", "0.256.0", "0.0.65536", "0000.000.00001", "000.0000.00001", "000.000.000001" };
for ( String version : invalidedVersions ) {
assertFalse( "Failed for \"" + version + "\"", ValidationUtil.checkForVersion( version ) );
}