Skip to content

Commit c027280

Browse files
committed
fix(description-sanitizer): allow BlockEditor file attachment and callout attributes on div elements (#27658)
* fix(description-sanitizer): allow BlockEditor file attachment and callout attributes on div elements * addressed gitar comments * unit test fix * removed attribute * fix java check style * nit
1 parent 03b3682 commit c027280

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

openmetadata-service/src/main/java/org/openmetadata/service/util/DescriptionSanitizer.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,30 @@ public final class DescriptionSanitizer {
9999
// Entity mention attributes on anchor tags (hashtag/mention nodes in BlockEditor)
100100
.allowAttributes("data-type", "data-label", "data-fqn", "data-entitytype")
101101
.onElements("a")
102+
// File attachment and callout node attributes (BlockEditor div-based nodes)
103+
// Note: data-temp-file is intentionally excluded — it holds transient upload state
104+
.allowAttributes(
105+
"data-type",
106+
"data-filename",
107+
"data-filesize",
108+
"data-mimetype",
109+
"data-uploading",
110+
"data-upload-progress",
111+
"data-is-image",
112+
"data-alt",
113+
"data-callouttype")
114+
.onElements("div")
115+
.allowAttributes("data-url")
116+
.matching(
117+
(elementName, attributeName, value) -> {
118+
if (value.startsWith("http://")
119+
|| value.startsWith("https://")
120+
|| value.startsWith("/")) {
121+
return value;
122+
}
123+
return null;
124+
})
125+
.onElements("div")
102126
.allowAttributes("align")
103127
.onElements("td", "th", "tr", "table")
104128
.allowAttributes("colspan", "rowspan")

openmetadata-service/src/test/java/org/openmetadata/service/util/DescriptionSanitizerTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,33 @@ void entityMentionAttributesOnAnchorArePreserved() {
230230
"<#E::tag::KnowledgeCenter.Article|[#Article](https://open-metadata.example.org/tags/KnowledgeCenter)>"));
231231
}
232232

233+
@Test
234+
void fileAttachmentDivAttributesArePreserved() {
235+
String input =
236+
"<p></p><div data-type=\"file-attachment\""
237+
+ " data-url=\"https://example.com/image.png\""
238+
+ " data-filename=\"image.png\""
239+
+ " data-mimetype=\"image\""
240+
+ " data-uploading=\"false\""
241+
+ " data-upload-progress=\"0\""
242+
+ " data-is-image=\"true\""
243+
+ " data-filesize=\"1024\""
244+
+ " data-alt=\"test image\""
245+
+ " data-callouttype=\"info\"></div><p></p>";
246+
String result = DescriptionSanitizer.sanitize(input);
247+
248+
assertTrue(result.contains("data-type=\"file-attachment\""));
249+
assertTrue(result.contains("data-url=\"https://example.com/image.png\""));
250+
assertTrue(result.contains("data-filename=\"image.png\""));
251+
assertTrue(result.contains("data-mimetype=\"image\""));
252+
assertTrue(result.contains("data-uploading=\"false\""));
253+
assertTrue(result.contains("data-upload-progress=\"0\""));
254+
assertTrue(result.contains("data-is-image=\"true\""));
255+
assertTrue(result.contains("data-filesize=\"1024\""));
256+
assertTrue(result.contains("data-alt=\"test image\""));
257+
assertTrue(result.contains("data-callouttype=\"info\""));
258+
}
259+
233260
@Test
234261
void entityMentionAttributesOnAnchorArePreservedForMention() {
235262
String input =

0 commit comments

Comments
 (0)