Fix the validation issue when the APK file and screenshot names contain spaces

Nipuni Kavindya 1 month ago
parent a6d46429e8
commit 5110c241c7

@ -481,6 +481,12 @@ public class APIUtil {
return application;
}
private static String encodeURI(String value) {
return value.replace(" ", "%20");
}
private static final String FILE_NAME_PARAM = "?fileName=";
public static ApplicationRelease releaseDtoToRelease(ApplicationReleaseDTO applicationReleaseDTO)
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
@ -503,31 +509,29 @@ public class APIUtil {
applicationRelease.setSupportedOsVersions(applicationReleaseDTO.getSupportedOsVersions());
applicationRelease.setRating(applicationReleaseDTO.getRating());
applicationRelease.setIconPath(
basePath + Constants.ICON_ARTIFACT + Constants.FORWARD_SLASH + applicationReleaseDTO.getIconName());
basePath + Constants.ICON_ARTIFACT + FILE_NAME_PARAM +
encodeURI(applicationReleaseDTO.getIconName()));
if (!StringUtils.isEmpty(applicationReleaseDTO.getBannerName())) {
applicationRelease.setBannerPath(
basePath + Constants.BANNER_ARTIFACT + Constants.FORWARD_SLASH + applicationReleaseDTO
.getBannerName());
basePath + Constants.BANNER_ARTIFACT + FILE_NAME_PARAM +
encodeURI(applicationReleaseDTO.getBannerName()));
}
applicationRelease.setInstallerPath(constructInstallerPath(applicationReleaseDTO.getInstallerName(),
applicationReleaseDTO.getAppHashValue()));
applicationRelease.setInstallerPath(
constructInstallerPath(applicationReleaseDTO.getInstallerName(), applicationReleaseDTO.getAppHashValue()));
if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName1())) {
screenshotPaths
.add(basePath + Constants.SCREENSHOT_ARTIFACT + 1 + Constants.FORWARD_SLASH + applicationReleaseDTO
.getScreenshotName1());
screenshotPaths.add(
basePath + Constants.SCREENSHOT_ARTIFACT + 1 + FILE_NAME_PARAM +
encodeURI(applicationReleaseDTO.getScreenshotName1()));
}
if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName2())) {
screenshotPaths
.add(basePath + Constants.SCREENSHOT_ARTIFACT + 2 + Constants.FORWARD_SLASH + applicationReleaseDTO
.getScreenshotName2());
screenshotPaths.add(
basePath + Constants.SCREENSHOT_ARTIFACT + 2 + FILE_NAME_PARAM +
encodeURI(applicationReleaseDTO.getScreenshotName2()));
}
if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName3())) {
screenshotPaths
.add(basePath + Constants.SCREENSHOT_ARTIFACT + 3 + Constants.FORWARD_SLASH + applicationReleaseDTO
.getScreenshotName3());
screenshotPaths.add(
basePath + Constants.SCREENSHOT_ARTIFACT + 3 + FILE_NAME_PARAM +
encodeURI(applicationReleaseDTO.getScreenshotName3()));
}
applicationRelease.setScreenshots(screenshotPaths);
return applicationRelease;
@ -543,9 +547,11 @@ public class APIUtil {
public static String constructInstallerPath(String installerName, String appHash) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
UrlValidator urlValidator = new UrlValidator();
String basePath = getArtifactDownloadBaseURL() + tenantId + Constants.FORWARD_SLASH + appHash + Constants.FORWARD_SLASH;
return urlValidator.isValid(installerName) ? installerName
: basePath + Constants.APP_ARTIFACT + Constants.FORWARD_SLASH + installerName;
String basePath = getArtifactDownloadBaseURL() + tenantId + Constants.FORWARD_SLASH +
appHash + Constants.FORWARD_SLASH;
return urlValidator.isValid(installerName)
? installerName
: basePath + Constants.APP_ARTIFACT + FILE_NAME_PARAM + encodeURI(installerName);
}
public static String getArtifactDownloadBaseURL() throws ApplicationManagementException {

Loading…
Cancel
Save