Skip to content

Commit

Permalink
Handle reserved symbols in commands
Browse files Browse the repository at this point in the history
  • Loading branch information
danadi7 committed Sep 18, 2020
1 parent 6ada6c4 commit 7e192d5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/main/java/duke/logic/CommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public class CommandParser {
* @throws DukeException If command is not on the recognised list of commands.
*/
public static Command parse(String command) throws DukeException {
// Disallow use of escape characters and symbols used internally by Storage class
if (command.contains("|") || command.contains("\\")) {
throw new DukeException("The characters \\ and | are forbidden!");
}

String[] extractedCommand = command.split(" ", 2);
switch(extractedCommand[0]) {
case("bye"):
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/duke/ui/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public String buildTaskList(ArrayList<Task> taskList) {
* Prints error message from failing to load save file.
*/
public void showLoadingError() {
System.out.println("Unable to load or find save file. Initiating new instance.");
System.out.println("Unable to load or find save file. " +
"Save file is either not found or corrupted. " +
"Initiating new instance.");
}
}

0 comments on commit 7e192d5

Please sign in to comment.