:
サニタイズされた HTML でのサインインを許可するにはどうすればよいですか? Javaメールを生成する際にHTMLコードをサニタイズするために使用しています。このコードには、 のようなインライン イメージ コンテンツ ID があり<img src=\"cid:image\" height=\"70\" width=\"70\" />
ます。サニタイズすると、src
属性はサニタイズされた html に含まれません。
PolicyFactory IMAGES = new HtmlPolicyBuilder().allowUrlProtocols("http", "https")
.allowElements("img")
.allowAttributes("src").matching(Pattern.compile("^cid[:][\\w]+$"))
.onElements("img")
.allowAttributes("border", "height", "width").onElements("img")
.toFactory();
String html = "<img src=\"cid:image\" height=\"70\" width=\"70\" />";
final String sanitized = IMAGES.sanitize(html);
System.out.println(sanitized);
上記のコードの出力は次のとおりです。
<img height="70" width="70" />