260803_03_ENH: 템플릿 저장 시 QR코드의 src에 http, https없으면 붙이게 수정

This commit is contained in:
2026-08-03 15:32:43 +09:00
parent 6ad56cd4c8
commit ec243e93c4

View File

@@ -9,6 +9,7 @@ import java.nio.charset.StandardCharsets;
import java.util.regex.Pattern;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.safety.Safelist;
public final class TemplateContentSanitizer {
@@ -73,7 +74,7 @@ public final class TemplateContentSanitizer {
return null;
}
html = normalizeEscapedQrcodeTags(html);
html = normalizeQrcodeSrc(normalizeEscapedQrcodeTags(html));
Safelist safelist = Safelist.relaxed()
.addTags("mark")
@@ -99,6 +100,27 @@ public final class TemplateContentSanitizer {
return ESCAPED_QRCODE_CLOSE_TAG_PATTERN.matcher(normalized).replaceAll("");
}
private static String normalizeQrcodeSrc(String html) {
Document doc = Jsoup.parseBodyFragment(html);
doc.outputSettings(new Document.OutputSettings().prettyPrint(false));
for (Element qrcode : doc.select("qrcode[src]")) {
String src = qrcode.attr("src").trim();
if (src.isEmpty() || startsWithHttpScheme(src)) {
continue;
}
qrcode.attr("src", src.startsWith("//") ? "https:" + src : "https://" + src);
}
return doc.body().html();
}
private static boolean startsWithHttpScheme(String value) {
return value.regionMatches(true, 0, "http://", 0, "http://".length())
|| value.regionMatches(true, 0, "https://", 0, "https://".length());
}
/**
* SMS/LMS body: HTML -> 평문(개행 보존)
*/