Skip to content

Commit 249e751

Browse files
committed
Prepare for 0.14.0 release
1 parent a65c781 commit 249e751

4 files changed

Lines changed: 22 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
66
This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html),
77
with the exception that 0.x versions can break between minor versions.
88

9+
## [0.14.0] - 2020-01-22
10+
### Added
11+
- Add `sanitizeUrls` to `HtmlRenderer.Builder` to enable sanitizing URLs
12+
of `<a>` and `<img>` tags. Sanitizing logic can be customized via
13+
`urlSanitizer`. Thanks @VandorpeDavid
14+
915
## [0.13.1] - 2019-11-25
1016
### Fixed
1117
- Fix potential `StackOverflowError` for regular expressions used in the
@@ -263,6 +269,7 @@ Initial release of commonmark-java, a port of commonmark.js with extensions
263269
for autolinking URLs, GitHub flavored strikethrough and tables.
264270

265271

272+
[0.14.0]: https://github.com/atlassian/commonmark-java/compare/commonmark-parent-0.13.1...commonmark-parent-0.14.0
266273
[0.13.1]: https://github.com/atlassian/commonmark-java/compare/commonmark-parent-0.13.0...commonmark-parent-0.13.1
267274
[0.13.0]: https://github.com/atlassian/commonmark-java/compare/commonmark-parent-0.12.1...commonmark-parent-0.13.0
268275
[0.12.1]: https://github.com/atlassian/commonmark-java/compare/commonmark-parent-0.11.0...commonmark-parent-0.12.1

commonmark/src/main/java/org/commonmark/renderer/html/HtmlNodeRendererContext.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.commonmark.renderer.html;
22

3-
import org.commonmark.node.Link;
43
import org.commonmark.node.Image;
4+
import org.commonmark.node.Link;
55
import org.commonmark.node.Node;
66

77
import java.util.Map;
@@ -48,14 +48,14 @@ public interface HtmlNodeRendererContext {
4848
boolean shouldEscapeHtml();
4949

5050
/**
51-
*
5251
* @return true if the {@link UrlSanitizer} should be used.
52+
* @since 0.14.0
5353
*/
5454
boolean shouldSanitizeUrls();
5555

5656
/**
57-
*
58-
* @return Sanitizer to use for securing {@link Link} href and {@link Image} src if sanitizeUrls is true.
57+
* @return Sanitizer to use for securing {@link Link} href and {@link Image} src if {@link #shouldSanitizeUrls()} is true.
58+
* @since 0.14.0
5959
*/
6060
UrlSanitizer urlSanitizer();
6161
}

commonmark/src/main/java/org/commonmark/renderer/html/HtmlRenderer.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
import org.commonmark.Extension;
44
import org.commonmark.internal.renderer.NodeRendererMap;
55
import org.commonmark.internal.util.Escaping;
6-
import org.commonmark.node.HtmlBlock;
7-
import org.commonmark.node.HtmlInline;
8-
import org.commonmark.node.Link;
9-
import org.commonmark.node.Image;
10-
import org.commonmark.node.Node;
6+
import org.commonmark.node.*;
117
import org.commonmark.renderer.NodeRenderer;
128
import org.commonmark.renderer.Renderer;
139

@@ -134,22 +130,22 @@ public Builder escapeHtml(boolean escapeHtml) {
134130

135131
/**
136132
* Whether {@link Image} src and {@link Link} href should be sanitized, defaults to {@code false}.
137-
* <p>
138133
*
139134
* @param sanitizeUrls true for sanitization, false for preserving raw attribute
140135
* @return {@code this}
136+
* @since 0.14.0
141137
*/
142138
public Builder sanitizeUrls(boolean sanitizeUrls) {
143139
this.sanitizeUrls = sanitizeUrls;
144140
return this;
145141
}
146142

147143
/**
148-
* {@link UrlSanitizer} used to filter URL's if sanitizeUrls is true.
149-
* <p>
144+
* {@link UrlSanitizer} used to filter URL's if {@link #sanitizeUrls} is true.
150145
*
151146
* @param urlSanitizer Filterer used to filter {@link Image} src and {@link Link}.
152147
* @return {@code this}
148+
* @since 0.14.0
153149
*/
154150
public Builder urlSanitizer(UrlSanitizer urlSanitizer) {
155151
this.urlSanitizer = urlSanitizer;

commonmark/src/main/java/org/commonmark/renderer/html/UrlSanitizer.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,25 @@
66
/**
77
* Sanitizes urls for img and a elements by whitelisting protocols.
88
* This is intended to prevent XSS payloads like [Click this totally safe url](javascript:document.xss=true;)
9-
*
9+
* <p>
1010
* Implementation based on https://github.com/OWASP/java-html-sanitizer/blob/f07e44b034a45d94d6fd010279073c38b6933072/src/main/java/org/owasp/html/FilterUrlByProtocolAttributePolicy.java
11+
*
12+
* @since 0.14.0
1113
*/
1214
public interface UrlSanitizer {
1315
/**
1416
* Sanitize a url for use in the href attribute of a {@link Link}.
17+
*
1518
* @param url Link to sanitize
1619
* @return Sanitized link
1720
*/
18-
public String sanitizeLinkUrl(String url);
21+
String sanitizeLinkUrl(String url);
1922

2023
/**
2124
* Sanitize a url for use in the src attribute of a {@link Image}.
25+
*
2226
* @param url Link to sanitize
2327
* @return Sanitized link {@link Image}
2428
*/
25-
public String sanitizeImageUrl(String url);
29+
String sanitizeImageUrl(String url);
2630
}

0 commit comments

Comments
 (0)