fixing the incident #23862
This commit is contained in:
parent
9ca232196e
commit
a7bed05f4c
|
@ -4,12 +4,13 @@
|
|||
All notable changes to this project will be documented in this file.
|
||||
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [v6.35.2] - 2022-09-05
|
||||
## [v6.35.2] - 2022-09-14
|
||||
|
||||
#### Bug fixed
|
||||
|
||||
- [#23676] Fixed - Added extension .txt to ASC files when dowloaded
|
||||
- [#23789] Fixed - Notebook files (.ipynb) are downloaded with .txt attached.
|
||||
- [#23862] Fixed - Downloading folders containing a "." in the name, the .zip is appended to file name
|
||||
|
||||
## [v6.35.1] - 2022-06-27
|
||||
|
||||
|
|
|
@ -153,7 +153,7 @@ public class DownloadServlet extends HttpServlet{
|
|||
ByteArrayInputStream is = new ByteArrayInputStream(fileContent.getBytes());
|
||||
String contentDisposition = viewContent?"inline":"attachment";
|
||||
String urlMimeType = "text/uri-list";
|
||||
String itemName = MimeTypeUtility.getNameWithExtension(item.getName(), urlMimeType);
|
||||
String itemName = MimeTypeUtility.getNameWithExtension(item.getName(), urlMimeType, false);
|
||||
resp.setHeader("Content-Disposition", contentDisposition+"; filename=\"" + itemName + "\"" );
|
||||
resp.setContentType(urlMimeType);
|
||||
|
||||
|
@ -190,7 +190,7 @@ public class DownloadServlet extends HttpServlet{
|
|||
logger.info("Downloading the folder: "+workspaceFolder);
|
||||
String contentDisposition = viewContent?"inline":"attachment";
|
||||
String mimeType = "application/zip";
|
||||
String itemName = MimeTypeUtility.getNameWithExtension(item.getName(), mimeType);
|
||||
String itemName = MimeTypeUtility.getNameWithExtension(item.getName(), mimeType,true);
|
||||
resp.setHeader("Content-Disposition", contentDisposition+"; filename=\"" + itemName + "\"" );
|
||||
resp.setContentType(mimeType);
|
||||
|
||||
|
@ -233,7 +233,7 @@ public class DownloadServlet extends HttpServlet{
|
|||
String mimeType = pdfFile.getMimeType();
|
||||
logger.trace("EXTERNAL_FILE DOWNLOAD FOR "+pdfFile.getId());
|
||||
String contentDisposition = viewContent?"inline":"attachment";
|
||||
String itemName = MimeTypeUtility.getNameWithExtension(descr.getItemName(), mimeType);
|
||||
String itemName = MimeTypeUtility.getNameWithExtension(descr.getItemName(), mimeType,false);
|
||||
|
||||
resp.setHeader("Content-Disposition", contentDisposition+"; filename=\"" + itemName + "\"" );
|
||||
resp.setContentType(mimeType);
|
||||
|
@ -267,7 +267,7 @@ public class DownloadServlet extends HttpServlet{
|
|||
ImageFileItem imageFile = (ImageFileItem) workspaceFileItem;
|
||||
logger.info("Downloading: "+imageFile);
|
||||
String mimeType = imageFile.getMimeType();
|
||||
String itemName = MimeTypeUtility.getNameWithExtension(descr.getItemName(), mimeType);
|
||||
String itemName = MimeTypeUtility.getNameWithExtension(descr.getItemName(), mimeType,false);
|
||||
String contentDisposition = viewContent?"inline":"attachment";
|
||||
resp.setHeader("Content-Disposition", contentDisposition+"; filename=\"" + itemName + "\"" );
|
||||
resp.setContentType(mimeType);
|
||||
|
@ -298,7 +298,7 @@ public class DownloadServlet extends HttpServlet{
|
|||
URLFileItem externalUrl = (URLFileItem) workspaceFileItem;
|
||||
logger.info("Downloading: "+externalUrl);
|
||||
String urlMimeType = "text/uri-list";
|
||||
String itemName = MimeTypeUtility.getNameWithExtension(descr.getItemName(), urlMimeType);
|
||||
String itemName = MimeTypeUtility.getNameWithExtension(descr.getItemName(), urlMimeType,false);
|
||||
String contentDisposition = viewContent?"inline":"attachment";
|
||||
resp.setHeader("Content-Disposition", contentDisposition+"; filename=\"" + itemName + "\"" );
|
||||
resp.setContentType(urlMimeType);
|
||||
|
@ -347,7 +347,7 @@ public class DownloadServlet extends HttpServlet{
|
|||
|
||||
try{
|
||||
|
||||
String itemName = MimeTypeUtility.getNameWithExtension(descr.getItemName(), workspaceFileItem.getMimeType());
|
||||
String itemName = MimeTypeUtility.getNameWithExtension(descr.getItemName(), workspaceFileItem.getMimeType(),false);
|
||||
logger.info("Downloading default item: "+workspaceFileItem);
|
||||
|
||||
//String contentDisposition = viewContent?"inline":"attachment";
|
||||
|
|
|
@ -163,11 +163,12 @@ public class MimeTypeUtility {
|
|||
*
|
||||
* @param name the file name.
|
||||
* @param mimeType the mime type.
|
||||
* @param isFolder the is folder
|
||||
* @return the right name.
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public static String getNameWithExtension(String name, String mimeType) throws IOException {
|
||||
logger.debug("Deriving the file extension for file name: " + name + ", with mimeType: " + mimeType);
|
||||
public static String getNameWithExtension(String name, String mimeType, boolean isFolder) throws IOException {
|
||||
logger.debug("Deriving the file extension for file name: " + name + ", with mimeType: " + mimeType+", isFolder: "+isFolder);
|
||||
|
||||
if (mimeType == null || mimeType.isEmpty()) {
|
||||
logger.debug("Input mime type is null or empty returning passed name: " + name);
|
||||
|
@ -177,13 +178,14 @@ public class MimeTypeUtility {
|
|||
String declaredExtension = FilenameUtils.getExtension(name);
|
||||
logger.info("The name " + name + " contains the extension: " + declaredExtension);
|
||||
|
||||
if (declaredExtension != null && !declaredExtension.isEmpty()) {
|
||||
//If the filename contains the extension returning the name like it is (skipping the folder)
|
||||
if (declaredExtension != null && !declaredExtension.isEmpty() && !isFolder) {
|
||||
logger.debug(
|
||||
"The name contains a not empty extension: " + declaredExtension + ", so returning the name like it is");
|
||||
"The filename contains a not empty extension: " + declaredExtension + ", so returning the name like it is");
|
||||
return name;
|
||||
}
|
||||
|
||||
logger.debug("The name does not contains the extension, deriving it from mimeType");
|
||||
logger.debug("Either the name does not contains the extension or it is a folder, deriving extension from mimeType");
|
||||
List<String> extensions = MimeTypeUtility.getExtension(mimeType);
|
||||
logger.debug("Extension/s available for input mimetype: " + mimeType + " into map is/are: " + extensions);
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ public class MimeTypeUtilityTest {
|
|||
for (String keyFileName : fileNamesToMimeTypes.keySet()) {
|
||||
try {
|
||||
System.out.println("\nResolving file name with extension for name: "+keyFileName);
|
||||
String toFileName = MimeTypeUtility.getNameWithExtension(keyFileName, fileNamesToMimeTypes.get(keyFileName));
|
||||
String toFileName = MimeTypeUtility.getNameWithExtension(keyFileName, fileNamesToMimeTypes.get(keyFileName), false);
|
||||
System.out.println("Assigned the file name: "+toFileName);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
|
Loading…
Reference in New Issue