From aef778570ec96aaa51469aeee7a8b43b8bb73386 Mon Sep 17 00:00:00 2001 From: jeffcheasey88 Date: Sun, 14 Apr 2024 14:15:09 +0200 Subject: [PATCH] Add rules for " --- .../peerat/backend/routes/admins/puzzle/AddPuzzle.java | 8 +++++++- .../peerat/backend/routes/admins/puzzle/EditPuzzle.java | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/dev/peerat/backend/routes/admins/puzzle/AddPuzzle.java b/src/dev/peerat/backend/routes/admins/puzzle/AddPuzzle.java index 480b486..2450548 100644 --- a/src/dev/peerat/backend/routes/admins/puzzle/AddPuzzle.java +++ b/src/dev/peerat/backend/routes/admins/puzzle/AddPuzzle.java @@ -24,7 +24,7 @@ public class AddPuzzle implements Response{ @Route(path = "^/admin/puzzle/$", type = POST, needLogin = true) public void exec(Matcher matcher, Context context, HttpReader reader, HttpWriter writer) throws Exception{ JsonMap json = reader.readJson(); - Puzzle puzzle = new Puzzle(-1, json.get("name"), json.get("content").replace("206\\", "\n").replace("202\\", "\r"), json.get("soluce").replace("206\\", "\n").replace("202\\", "\r").getBytes(), null, json.get("scoreMax").intValue(), null, -1, null); + Puzzle puzzle = new Puzzle(-1, json.get("name"), clearText(json.get("content")), clearText(json.get("soluce")).getBytes(), null, json.get("scoreMax").intValue(), null, -1, null); if(repo.adminAddPuzzle(puzzle, json.get("chapter").intValue())){ context.response(200); }else{ @@ -32,4 +32,10 @@ public class AddPuzzle implements Response{ } } + private String clearText(String value){ + return value + .replace("206\\", "\n") + .replace("202\\", "\r") + .replace("126\\", "\""); + } } diff --git a/src/dev/peerat/backend/routes/admins/puzzle/EditPuzzle.java b/src/dev/peerat/backend/routes/admins/puzzle/EditPuzzle.java index 99e2b7a..6616bd8 100644 --- a/src/dev/peerat/backend/routes/admins/puzzle/EditPuzzle.java +++ b/src/dev/peerat/backend/routes/admins/puzzle/EditPuzzle.java @@ -24,7 +24,7 @@ public class EditPuzzle implements Response{ @Route(path = "^/admin/puzzle/(\\d+)$", type = PUT, needLogin = true) public void exec(Matcher matcher, Context context, HttpReader reader, HttpWriter writer) throws Exception{ JsonMap json = reader.readJson(); - Puzzle puzzle = new Puzzle(-1, json.get("name"), json.get("content").replace("206\\", "\n").replace("202\\", "\r"), json.get("soluce").replace("206\\", "\n").replace("202\\", "\r").getBytes(), null, json.get("scoreMax").intValue(), null, -1, null); + Puzzle puzzle = new Puzzle(-1, json.get("name"), clearText(json.get("content")), clearText(json.get("soluce")).getBytes(), null, json.get("scoreMax").intValue(), null, -1, null); if(repo.adminUpdatePuzzle(Integer.parseInt(matcher.group(1)), puzzle, json.get("chapter").intValue())){ context.response(200); }else{ @@ -32,4 +32,10 @@ public class EditPuzzle implements Response{ } } + private String clearText(String value){ + return value + .replace("206\\", "\n") + .replace("202\\", "\r") + .replace("126\\", "\""); + } }