Skip to content

Commit

Permalink
Merge pull request #253 from yeodonghan/filename-bug-fix
Browse files Browse the repository at this point in the history
Filename bug fix
  • Loading branch information
EugeneTeu authored Nov 5, 2019
2 parents 6a90b48 + bf3d5ad commit 946fdf1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main/java/seedu/address/logic/commands/ExportCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import seedu.address.commons.util.FileUtil;
import seedu.address.logic.CommandHistory;
import seedu.address.logic.UndoRedoStack;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.UserPrefs;

Expand All @@ -41,7 +42,8 @@ public ExportCommand(String fileName) {
}

@Override
public CommandResult execute(Model model, CommandHistory commandHistory, UndoRedoStack undoRedoStack) {
public CommandResult execute(Model model, CommandHistory commandHistory, UndoRedoStack undoRedoStack) throws
CommandException {
requireNonNull(model);
UserPrefs userPrefs = new UserPrefs();
customerFile = userPrefs.getCustomerBookFilePath();
Expand All @@ -51,6 +53,12 @@ public CommandResult execute(Model model, CommandHistory commandHistory, UndoRed
String pathName = "data/" + fileName + ".csv";

try {
if (!fileName.matches("[a-zA-Z0-9]+")) {
throw new CommandException("File name can only be Alphanumeric.");
}
if (fileName.length() >= 225) {
throw new CommandException("File name is too long.");
}
String dataCsv = this.getCsvString();
FileUtil.writeToFile(Paths.get(pathName), dataCsv);

Expand Down

0 comments on commit 946fdf1

Please sign in to comment.