Skip to content

Commit e170d31

Browse files
committed
Merge remote-tracking branch 'origin/main' into footnotes-extension
2 parents ee7b710 + 591b452 commit e170d31

11 files changed

Lines changed: 322 additions & 10 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
wrapperVersion=3.3.2
18+
distributionType=only-script
19+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Coordinates for core library (see all on [Maven Central]):
3636
<dependency>
3737
<groupId>org.commonmark</groupId>
3838
<artifactId>commonmark</artifactId>
39-
<version>0.21.0</version>
39+
<version>0.22.0</version>
4040
</dependency>
4141
```
4242

@@ -265,7 +265,7 @@ First, add an additional dependency (see [Maven Central] for others):
265265
<dependency>
266266
<groupId>org.commonmark</groupId>
267267
<artifactId>commonmark-ext-gfm-tables</artifactId>
268-
<version>0.21.0</version>
268+
<version>0.22.0</version>
269269
</dependency>
270270
```
271271

commonmark/src/main/java/org/commonmark/node/FencedCodeBlock.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void setFenceIndent(int fenceIndent) {
6767
}
6868

6969
/**
70-
* @see <a href="http://spec.commonmark.org/0.18/#info-string">CommonMark spec</a>
70+
* @see <a href="http://spec.commonmark.org/0.31.2/#info-string">CommonMark spec</a>
7171
*/
7272
public String getInfo() {
7373
return info;

commonmark/src/main/java/org/commonmark/node/HtmlBlock.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* HTML block
55
*
6-
* @see <a href="http://spec.commonmark.org/0.18/#html-blocks">CommonMark Spec</a>
6+
* @see <a href="http://spec.commonmark.org/0.31.2/#html-blocks">CommonMark Spec</a>
77
*/
88
public class HtmlBlock extends Block {
99

commonmark/src/main/java/org/commonmark/node/HtmlInline.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* Inline HTML element.
55
*
6-
* @see <a href="http://spec.commonmark.org/0.24/#raw-html">CommonMark Spec</a>
6+
* @see <a href="http://spec.commonmark.org/0.31.2/#raw-html">CommonMark Spec</a>
77
*/
88
public class HtmlInline extends Node {
99

commonmark/src/main/java/org/commonmark/node/Link.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Note that the text in the link can contain inline formatting, so it could also contain an {@link Image} or
1919
* {@link Emphasis}, etc.
2020
*
21-
* @see <a href="http://spec.commonmark.org/0.26/#links">CommonMark Spec for links</a>
21+
* @see <a href="http://spec.commonmark.org/0.31.2/#links">CommonMark Spec for links</a>
2222
*/
2323
public class Link extends Node {
2424

commonmark/src/main/java/org/commonmark/node/LinkReferenceDefinition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* They can be referenced anywhere else in the document to produce a link using <code>[foo]</code>. The definitions
1010
* themselves are usually not rendered in the final output.
1111
*
12-
* @see <a href="https://spec.commonmark.org/0.29/#link-reference-definition">Link reference definitions</a>
12+
* @see <a href="https://spec.commonmark.org/0.31.2/#link-reference-definition">Link reference definitions</a>
1313
*/
1414
public class LinkReferenceDefinition extends Block {
1515

commonmark/src/main/java/org/commonmark/node/ListBlock.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public abstract class ListBlock extends Block {
66

77
/**
88
* @return whether this list is tight or loose
9-
* @see <a href="https://spec.commonmark.org/0.28/#tight">CommonMark Spec for tight lists</a>
9+
* @see <a href="https://spec.commonmark.org/0.31.2/#tight">CommonMark Spec for tight lists</a>
1010
*/
1111
public boolean isTight() {
1212
return tight;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
/**
66
*
7-
* Allows http, https and mailto protocols for url.
7+
* Allows http, https, mailto, and data protocols for url.
88
* Also allows protocol relative urls, and relative urls.
99
* Implementation based on https://github.com/OWASP/java-html-sanitizer/blob/f07e44b034a45d94d6fd010279073c38b6933072/src/main/java/org/owasp/html/FilterUrlByProtocolAttributePolicy.java
1010
*/
1111
public class DefaultUrlSanitizer implements UrlSanitizer {
1212
private Set<String> protocols;
1313

1414
public DefaultUrlSanitizer() {
15-
this(List.of("http", "https", "mailto"));
15+
this(List.of("http", "https", "mailto", "data"));
1616
}
1717

1818
public DefaultUrlSanitizer(Collection<String> protocols) {

commonmark/src/test/java/org/commonmark/test/HtmlRendererTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,47 @@ public void sanitizedUrlsShouldSetRelNoFollow() {
9393
assertEquals("<p><a rel=\"nofollow\" href=\"https://google.com\"></a></p>\n", sanitizeUrlsRenderer().render(paragraph));
9494
}
9595

96+
@Test
97+
public void sanitizedUrlsShouldAllowSafeProtocols() {
98+
Paragraph paragraph = new Paragraph();
99+
Link link = new Link();
100+
link.setDestination("http://google.com");
101+
paragraph.appendChild(link);
102+
assertEquals("<p><a rel=\"nofollow\" href=\"http://google.com\"></a></p>\n", sanitizeUrlsRenderer().render(paragraph));
103+
104+
paragraph = new Paragraph();
105+
link = new Link();
106+
link.setDestination("https://google.com");
107+
paragraph.appendChild(link);
108+
assertEquals("<p><a rel=\"nofollow\" href=\"https://google.com\"></a></p>\n", sanitizeUrlsRenderer().render(paragraph));
109+
110+
paragraph = new Paragraph();
111+
link = new Link();
112+
link.setDestination("mailto:foo@bar.example.com");
113+
paragraph.appendChild(link);
114+
assertEquals("<p><a rel=\"nofollow\" href=\"mailto:foo@bar.example.com\"></a></p>\n", sanitizeUrlsRenderer().render(paragraph));
115+
116+
String image = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAFiUAABYlAUlSJPAAAAAQSURBVBhXY/iPBVBf8P9/AG8TY51nJdgkAAAAAElFTkSuQmCC";
117+
paragraph = new Paragraph();
118+
link = new Link();
119+
link.setDestination(image);
120+
paragraph.appendChild(link);
121+
assertEquals("<p><a rel=\"nofollow\" href=\"" + image + "\"></a></p>\n", sanitizeUrlsRenderer().render(paragraph));
122+
}
123+
96124
@Test
97125
public void sanitizedUrlsShouldFilterDangerousProtocols() {
98126
Paragraph paragraph = new Paragraph();
99127
Link link = new Link();
100128
link.setDestination("javascript:alert(5);");
101129
paragraph.appendChild(link);
102130
assertEquals("<p><a rel=\"nofollow\" href=\"\"></a></p>\n", sanitizeUrlsRenderer().render(paragraph));
131+
132+
paragraph = new Paragraph();
133+
link = new Link();
134+
link.setDestination("ftp://google.com");
135+
paragraph.appendChild(link);
136+
assertEquals("<p><a rel=\"nofollow\" href=\"\"></a></p>\n", sanitizeUrlsRenderer().render(paragraph));
103137
}
104138

105139
@Test

0 commit comments

Comments
 (0)