Skip to content

Commit ca014e0

Browse files
committed
Refactor JLPopupBuilder to enhance content sanitization and improve text handling
Signed-off-by: makbn <[email protected]>
1 parent 67df807 commit ca014e0

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

jlmap-api/src/main/java/io/github/makbn/jlmap/model/builder/JLPopupBuilder.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,22 @@ public String buildJsElement() {
5757
getElementVarName(),
5858
renderOptions(),
5959
lat, lng,
60-
sanitizeContent(),
60+
sanitizeContent(true),
6161
getElementVarName(),
6262
renderCallbacks());
6363
}
6464

65-
private @NotNull String sanitizeContent() {
66-
return content != null ? "\"" + content.replace("\"", "\\\"") + "\"" : "\"\"";
65+
private @NotNull String sanitizeContent(boolean wrap) {
66+
var sanitized = content != null ? content.replace("\"", "\\\"")
67+
.replaceAll("<script[^>]*?>.*?</script>", "") : "";
68+
return wrap ? "\"" + sanitized + "\"" : sanitized;
6769
}
6870

6971
@Override
7072
public JLPopup buildJLObject() {
7173
return JLPopup.builder()
7274
.id(uuid)
73-
.text(sanitizeContent())
75+
.text(sanitizeContent(false))
7476
.latLng(JLLatLng.builder()
7577
.lat(lat)
7678
.lng(lng)

0 commit comments

Comments
 (0)