Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERAttachment name with currency error #941

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,14 @@ protected static String _parsePathTemplate(ERAttachment attachment, String templ
hashPathBuffer.append(filenameHash.charAt(1));
hashPathBuffer.append('/');
hashPathBuffer.append(filenameHash.charAt(2));
//hashPathBuffer.append('/');
//hashPathBuffer.append(filenameHash.substring(3));
// hashPathBuffer.append('/');
// hashPathBuffer.append(filenameHash.substring(3));
parsedPath = parsedPath.replaceAll(ERAttachmentProcessor.HASH_VARIABLE, hashPathBuffer.toString());

parsedPath = parsedPath.replaceAll(ERAttachmentProcessor.UUID_VARIABLE, UUID.randomUUID().toString());

parsedPath = parsedPath.replaceAll(ERAttachmentProcessor.FILE_NAME_VARIABLE, recommendedFileName);
parsedPath = parsedPath.replaceAll(ERAttachmentProcessor.FILE_NAME_VARIABLE, escapeCurrencyOf(recommendedFileName));

parsedPath = parsedPath.replaceAll(ERAttachmentProcessor.PK_VARIABLE, attachment.primaryKeyInTransaction());
return parsedPath;
}
Expand Down Expand Up @@ -462,4 +463,8 @@ public String getRecommendedFileName() {
return _recommendedFileName;
}
}

static String escapeCurrencyOf(String text) {
return text.replaceAll("\\$", "\\\\\\$");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package er.attachment.processors;

import static java.util.regex.Pattern.quote;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -88,11 +90,12 @@ else if (!webPath.startsWith("/")) {
File actualFilesystemPath = ERXFileUtilities.reserveUniqueFile(desiredFilesystemPath, overwrite);

ERXFileUtilities.copyFileToFile(uploadedFile, actualFilesystemPath, pendingDelete, true);

String desiredFileName = escapeCurrencyOf(desiredFilesystemPath.getName());
String actualFileName = escapeCurrencyOf(actualFilesystemPath.getName());

String desiredFileName = desiredFilesystemPath.getName();
String actualFileName = actualFilesystemPath.getName();
// in case the name was not unique and changed, we need to update webPath ...
webPath = webPath.replaceAll("\\Q" + desiredFileName + "\\E$", actualFileName);
webPath = webPath.replaceAll(quote(desiredFileName), actualFileName);

attachment.setWebPath(webPath);
attachment.setFilesystemPath(actualFilesystemPath.getAbsolutePath());
Expand Down