Skip to content

Commit

Permalink
refactor(post) : 게시글 저장 공백/줄바꿈 유지
Browse files Browse the repository at this point in the history
  • Loading branch information
Sosohy committed Jun 12, 2024
1 parent 58f218f commit 7aa2989
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,26 @@ public CmdPostAndTagsDTO registPost(CmdPostAndTagsDTO post) throws NotLoginExcep

public static String sanitizeHTML(String html) {

// 공백, 줄바꿈 대체
String spacePlaceholder = "___SPACE___";
String newlinePlaceholder = "___NEWLINE___";
String htmlWithPlaceholders = html
.replaceAll(" ", spacePlaceholder)
.replaceAll("\n", newlinePlaceholder)
.replaceAll("\r\n", newlinePlaceholder);

Whitelist whitelist = Whitelist.relaxed();
// 허용되지 않을 태그와 속성 추가
whitelist.removeTags("script", "style", "head", "header", "foot", "footer");
whitelist.removeAttributes( "style","onclick");
whitelist.removeAttributes("style", "onclick");

String cleanedHtmlWithPlaceholders = Jsoup.clean(htmlWithPlaceholders, whitelist);

String cleanedHtml = cleanedHtmlWithPlaceholders
.replaceAll(spacePlaceholder, " ")
.replaceAll(newlinePlaceholder, "\n");

String cleanedHTML = Jsoup.clean(html, whitelist);
return cleanedHTML;
return cleanedHtml;
}

public List<CmdTag> registTag(List<CmdTagDTO> tags, int postId) {
Expand Down

0 comments on commit 7aa2989

Please sign in to comment.