Skip to content
Open
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
@@ -1,5 +1,6 @@
package com.example.catapp.controllers;

import org.apache.commons.text.StringEscapeUtils;
import com.example.catapp.models.Comment;
import com.example.catapp.repositories.CommentRepository;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -24,7 +25,7 @@ public String addCommentForm() {
@PostMapping("/addComment")
public String addComment(@RequestParam String commentText, Model model) {
Comment comment = new Comment();
comment.setText(commentText); // No sanitization
comment.setText(StringEscapeUtils.escapeHtml4(commentText)); // Sanitize input
commentRepository.save(comment);
model.addAttribute("message", "Comment added");
return "addCommentResult"; // Returns addCommentResult.html
Expand Down