Merge pull request #2138 from Alfresco/MNT-23476_UNZIP_FILENAME_ACCENT

MNT-23476 Unable to unzip files in Share if it contains a document with a filename containing an accent
This commit is contained in:
Piyush Joshi
2023-08-22 13:36:09 +05:30
committed by GitHub

View File

@@ -44,7 +44,6 @@ import java.util.zip.ZipException;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ApplicationModel;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ActionServiceImpl;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.importer.ACPImportPackageHandler;
@@ -66,8 +65,7 @@ import org.alfresco.util.TempFileProvider;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.apache.commons.compress.utils.InputStreamStatistics;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.lang3.StringUtils;
/**
* Importer action executor
@@ -76,7 +74,6 @@ import org.apache.commons.logging.LogFactory;
*/
public class ImporterActionExecuter extends ActionExecuterAbstractBase
{
private static Log logger = LogFactory.getLog(ImporterActionExecuter.class);
public static final String NAME = "import";
public static final String PARAM_ENCODING = "encoding";
public static final String PARAM_DESTINATION_FOLDER = "destination";
@@ -246,22 +243,18 @@ public class ImporterActionExecuter extends ActionExecuterAbstractBase
// http://bugs.sun.com/bugdatabase/view_bug.do;:WuuT?bug_id=4820807
// We also try to use the extra encoding information if present
String encoding = (String) ruleAction.getParameterValue(PARAM_ENCODING);
logger.info("Encoding before: "+encoding);
if (encoding == null)
{
logger.info("Encoding is null ");
encoding = "Cp437";
encoding = "UTF-8";
}
else
{
if (encoding.equalsIgnoreCase("default"))
{
logger.info("Encoding is default ");
encoding = "Cp437";
encoding = null;
}
}
logger.info("Encoding after: "+encoding);
zipFile = new ZipFile(tempFile, encoding, true);
zipFile = new ZipFile(tempFile, encoding, false);
// build a temp dir name based on the ID of the noderef we are importing
// also use the long life temp folder as large ZIP files can take a while
File alfTempDir = TempFileProvider.getLongLifeTempDir("import");
@@ -414,7 +407,7 @@ public class ImporterActionExecuter extends ActionExecuterAbstractBase
ZipArchiveEntry entry = e.nextElement();
if (!entry.isDirectory())
{
fileName = entry.getName();
fileName = StringUtils.stripAccents(entry.getName()).replaceAll("\\?","_");
fileName = fileName.replace('/', File.separatorChar);
if (fileName.startsWith("/") || fileName.indexOf(":" + File.separator) == 1 || fileName.contains(".." + File.separator))