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

Nipuni Kavindya 2 weeks ago
parent d91a1dd05d
commit b3ba0f49f8

@ -483,8 +483,6 @@ public class APIUtil {
return application; return application;
} }
private static final String FILE_NAME_PARAM = "?fileName=";
public static ApplicationRelease releaseDtoToRelease(ApplicationReleaseDTO applicationReleaseDTO) public static ApplicationRelease releaseDtoToRelease(ApplicationReleaseDTO applicationReleaseDTO)
throws ApplicationManagementException { throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
@ -507,28 +505,28 @@ public class APIUtil {
applicationRelease.setSupportedOsVersions(applicationReleaseDTO.getSupportedOsVersions()); applicationRelease.setSupportedOsVersions(applicationReleaseDTO.getSupportedOsVersions());
applicationRelease.setRating(applicationReleaseDTO.getRating()); applicationRelease.setRating(applicationReleaseDTO.getRating());
applicationRelease.setIconPath( applicationRelease.setIconPath(
basePath + Constants.ICON_ARTIFACT + FILE_NAME_PARAM + basePath + Constants.ICON_ARTIFACT + Constants.FILE_NAME_PARAM +
URLEncoder.encode(applicationReleaseDTO.getIconName(), StandardCharsets.UTF_8)); URLEncoder.encode(applicationReleaseDTO.getIconName(), StandardCharsets.UTF_8));
if (!StringUtils.isEmpty(applicationReleaseDTO.getBannerName())) { if (!StringUtils.isEmpty(applicationReleaseDTO.getBannerName())) {
applicationRelease.setBannerPath( applicationRelease.setBannerPath(
basePath + Constants.BANNER_ARTIFACT + FILE_NAME_PARAM + basePath + Constants.BANNER_ARTIFACT + Constants.FILE_NAME_PARAM +
URLEncoder.encode(applicationReleaseDTO.getBannerName(), StandardCharsets.UTF_8)); URLEncoder.encode(applicationReleaseDTO.getBannerName(), StandardCharsets.UTF_8));
} }
applicationRelease.setInstallerPath( applicationRelease.setInstallerPath(
constructInstallerPath(applicationReleaseDTO.getInstallerName(), applicationReleaseDTO.getAppHashValue())); constructInstallerPath(applicationReleaseDTO.getInstallerName(), applicationReleaseDTO.getAppHashValue()));
if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName1())) { if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName1())) {
screenshotPaths.add( screenshotPaths.add(
basePath + Constants.SCREENSHOT_ARTIFACT + 1 + FILE_NAME_PARAM + basePath + Constants.SCREENSHOT_ARTIFACT + 1 + Constants.FILE_NAME_PARAM +
URLEncoder.encode(applicationReleaseDTO.getScreenshotName1(), StandardCharsets.UTF_8)); URLEncoder.encode(applicationReleaseDTO.getScreenshotName1(), StandardCharsets.UTF_8));
} }
if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName2())) { if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName2())) {
screenshotPaths.add( screenshotPaths.add(
basePath + Constants.SCREENSHOT_ARTIFACT + 2 + FILE_NAME_PARAM + basePath + Constants.SCREENSHOT_ARTIFACT + 2 + Constants.FILE_NAME_PARAM +
URLEncoder.encode(applicationReleaseDTO.getScreenshotName2(), StandardCharsets.UTF_8)); URLEncoder.encode(applicationReleaseDTO.getScreenshotName2(), StandardCharsets.UTF_8));
} }
if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName3())) { if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName3())) {
screenshotPaths.add( screenshotPaths.add(
basePath + Constants.SCREENSHOT_ARTIFACT + 3 + FILE_NAME_PARAM + basePath + Constants.SCREENSHOT_ARTIFACT + 3 + Constants.FILE_NAME_PARAM +
URLEncoder.encode(applicationReleaseDTO.getScreenshotName3(), StandardCharsets.UTF_8)); URLEncoder.encode(applicationReleaseDTO.getScreenshotName3(), StandardCharsets.UTF_8));
} }
applicationRelease.setScreenshots(screenshotPaths); applicationRelease.setScreenshots(screenshotPaths);
@ -549,7 +547,7 @@ public class APIUtil {
appHash + Constants.FORWARD_SLASH; appHash + Constants.FORWARD_SLASH;
return urlValidator.isValid(installerName) return urlValidator.isValid(installerName)
? installerName ? installerName
: basePath + Constants.APP_ARTIFACT + FILE_NAME_PARAM + : basePath + Constants.APP_ARTIFACT + Constants.FILE_NAME_PARAM +
URLEncoder.encode(installerName, StandardCharsets.UTF_8); URLEncoder.encode(installerName, StandardCharsets.UTF_8);
} }

@ -140,6 +140,11 @@ public class Constants {
public static final String DB_TYPE_POSTGRESQL = "PostgreSQL"; public static final String DB_TYPE_POSTGRESQL = "PostgreSQL";
} }
/**
* Query parameter for specifying the filename in the App artifact URL.
*/
public static final String FILE_NAME_PARAM = "?fileName=";
/** /**
* Directory name of the icon artifact that are saved in the file system. * Directory name of the icon artifact that are saved in the file system.
*/ */

Loading…
Cancel
Save