Skip to content
This repository has been archived by the owner on Aug 10, 2023. It is now read-only.

Commit

Permalink
Escaping HTML entities (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
mageddo authored Jul 10, 2020
1 parent 098c30e commit 72dbca2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
3 changes: 3 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 3.9.1
* Escaping HTML entities

# 3.9.0
* Set page title as the bookmark name when editing

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.9.0
3.9.1
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
package com.mageddo.bookmarks.apiserver;

import java.util.List;

import com.mageddo.bookmarks.entity.SettingEntity;
import com.mageddo.bookmarks.exception.NotFoundException;
import com.mageddo.bookmarks.service.SettingsService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.micronaut.http.HttpResponse;
import io.micronaut.http.MediaType;
import io.micronaut.http.annotation.Body;
Expand All @@ -17,6 +12,13 @@
import io.micronaut.http.annotation.Patch;
import io.micronaut.http.annotation.QueryValue;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.unbescape.html.HtmlEscape;

import java.util.List;
import java.util.stream.Collectors;

import static io.micronaut.http.HttpResponse.badRequest;
import static io.micronaut.http.HttpResponse.notFound;
import static io.micronaut.http.HttpResponse.ok;
Expand Down Expand Up @@ -65,7 +67,12 @@ public HttpResponse _3(String version, @QueryValue("key") String key) {
produces = MediaType.APPLICATION_JSON)
public HttpResponse _4(String version, @Body List<SettingEntity> settings) {
try {
settingsService.patch(settings);
settingsService.patch(
settings
.stream()
.map(it -> it.setValue(HtmlEscape.escapeHtml4(it.getValue())))
.collect(Collectors.toList())
);
return ok();
} catch (NotFoundException e) {
logger.warn("status=not-found, msg={}", e.getMessage(), e);
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/thymeleaf/ThymeleafUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import com.mageddo.bookmarks.service.SiteMapService;
import com.mageddo.commons.UrlUtils;

import org.commonmark.internal.util.Html5Entities;
import org.unbescape.html.HtmlEscape;

import static com.mageddo.config.ApplicationContextUtils.context;

public final class ThymeleafUtils {
Expand All @@ -30,10 +33,10 @@ public static String analyticsId() {
}

public static String headerHtml(){
return context()
return HtmlEscape.unescapeHtml(context()
.getBean(SettingsService.class)
.findSetting(Setting.PUBLIC_PAGES_HEADER_HTML.name())
.getValue()
.getValue())
;
}
}

0 comments on commit 72dbca2

Please # to comment.