Refactor code

Improvement-#9241
Ashvini Wegodapola 9 months ago
parent 695624c455
commit 45db043902

@ -544,9 +544,9 @@ public class ApplicationManagementUtil {
* @return Sanitized and shortened file name
*/
public static String sanitizeName(String originalName, String type) {
String sanitizedName = originalName.replaceAll("[^a-zA-Z0-9.\\s-]", "");
if (type.equals(Constants.ApplicationProperties.NAME) && sanitizedName.length() > 350) {
sanitizedName = sanitizedName.substring(0, 350);
String sanitizedName = originalName.replaceAll(Constants.APP_NAME_REGEX, "");
if (Constants.ApplicationProperties.NAME.equals(type) && sanitizedName.length() > Constants.MAX_APP_NAME_CHARACTERS) {
sanitizedName = sanitizedName.substring(0, Constants.MAX_APP_NAME_CHARACTERS);
return sanitizedName;
} else if (Constants.ICON_NAME.equals(type) || Constants.SCREENSHOT_NAME.equals(type)) {
// Shortening icon/screenshot names
@ -556,7 +556,8 @@ public class ApplicationManagementUtil {
fileExtension = originalName.substring(dotIndex);
}
return type + fileExtension;
} else
} else {
return sanitizedName;
}
}
}

@ -214,4 +214,10 @@ public class Constants {
public static final String ASSOCIATION_DEVICE = "ASSOCIATION_DEVICE";
public static final String ASSOCIATION_USER = "ASSOCIATION_USER";
}
/**
* App name sanitization related constants
*/
public static final int MAX_APP_NAME_CHARACTERS = 350;
public static final String APP_NAME_REGEX = "[^a-zA-Z0-9.\\s-]";
}

Loading…
Cancel
Save