Skip to content

Commit

Permalink
Apply filename normalization with UTF8 NFC
Browse files Browse the repository at this point in the history
Filename normalization is applied for windows which use NFC
See: https://docs.oracle.com/javase/tutorial/i18n/text/normalizerapi.html
  • Loading branch information
doortts committed Feb 6, 2016
1 parent 8491a56 commit 44ab8e3
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions app/controllers/AttachmentApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
*/
package controllers;

import com.fasterxml.jackson.databind.JsonNode;
import controllers.annotation.AnonymousCheck;
import models.Attachment;
import models.User;
import models.enumeration.Operation;
import models.enumeration.ResourceType;
import org.apache.commons.lang3.StringUtils;
import com.fasterxml.jackson.databind.JsonNode;
import play.Configuration;
import play.Logger;
import play.mvc.Controller;
Expand All @@ -38,6 +38,7 @@
import java.io.File;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.text.Normalizer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -69,8 +70,13 @@ public static Result uploadFile() throws NoSuchAlgorithmException, IOException {
}

// Attach the file to the user who upload it.
//
// Filename normalization is applied for windows which use NFC
// See: https://docs.oracle.com/javase/tutorial/i18n/text/normalizerapi.html
Attachment attach = new Attachment();
boolean isCreated = attach.store(file, filePart.getFilename(), uploader.asResource());
boolean isCreated = attach.store(file,
Normalizer.normalize(filePart.getFilename(), Normalizer.Form.NFC),
uploader.asResource());

// The request has been fulfilled and resulted in a new resource being
// created. The newly created resource can be referenced by the URI(s)
Expand Down Expand Up @@ -222,6 +228,7 @@ public static Map<String, List<Map<String, String>>> getFileList(String containe
attach.asResource(), Operation.READ)) {
throw new PermissionDeniedException();
}
attach.name = Normalizer.normalize(attach.name, Normalizer.Form.NFC);
attachments.add(extractFileMetaDataFromAttachementAsMap(attach));
}
files.put("attachments", attachments);
Expand Down

0 comments on commit 44ab8e3

Please sign in to comment.