Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions third_party/docfx-doclet-143274/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<apache.commons-lang.version>3.12.0</apache.commons-lang.version>
<apache.commons-collections.version>4.4</apache.commons-collections.version>
<apache.commons-io.version>2.11.0</apache.commons-io.version>
<apache.commons-text.version>1.10.0</apache.commons-text.version>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This version is safe. But commons text is often marked as CVEs.

https://security.netapp.com/advisory/ntap-20221020-0004/

<remark.version>1.1.0</remark.version>
</properties>

Expand Down Expand Up @@ -111,6 +112,11 @@
<artifactId>commons-io</artifactId>
<version>${apache.commons-io.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>${apache.commons-text.version}</version>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
import com.sun.source.doctree.LinkTree;
import com.sun.source.doctree.LiteralTree;
import com.sun.source.doctree.SeeTree;
import java.util.concurrent.ConcurrentHashMap;
import jdk.javadoc.doclet.DocletEnvironment;
import org.apache.commons.lang3.RegExUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringEscapeUtils;

import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -242,7 +241,7 @@ String replaceLinksAndCodes(List<? extends DocTree> items) {
case LITERAL:
return expandLiteralBody((LiteralTree) bodyItem);
default:
return String.valueOf(bodyItem);
return String.valueOf(StringEscapeUtils.unescapeJava(bodyItem.toString()));
}
}
).collect(Collectors.joining()));
Expand All @@ -261,11 +260,11 @@ String buildXrefTag(LinkTree linkTree) {
}

String buildCodeTag(LiteralTree literalTree) {
return String.format("<code>%s</code>", literalTree.getBody());
return String.format("<code>%s</code>", StringEscapeUtils.unescapeJava(literalTree.getBody().toString()));
}

String expandLiteralBody(LiteralTree bodyItem) {
return String.valueOf(bodyItem.getBody());
return String.valueOf(StringEscapeUtils.unescapeJava(bodyItem.getBody().toString()));
}

protected Optional<DocCommentTree> getDocCommentTree(T element) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void buildXrefTagWhenLabelPresents() {

@Test
public void buildCodeTag() {
String tagContent = "Some text";
String tagContent = "Some text";
when(literalTree.getBody()).thenReturn(textTree);
when(textTree.toString()).thenReturn(tagContent);

Expand All @@ -145,21 +145,22 @@ public void buildCodeTag() {

@Test
public void expandLiteralBody() {
String tagContent = "Some text";
String tagContent = "Some text ≤ \u2264";
when(literalTree.getBody()).thenReturn(textTree);
when(textTree.toString()).thenReturn(tagContent);

String result = baseLookup.expandLiteralBody(literalTree);
String expected = "Some text ≤ ≤";

assertEquals("Wrong result", result, tagContent);
assertEquals("Wrong result", result, expected);
}

@Test
public void replaceLinksAndCodes() {
when(linkTree.getReference()).thenReturn(referenceTree);
when(referenceTree.getSignature()).thenReturn("Some#signature");
when(linkTree.getLabel()).thenReturn(Collections.emptyList());
String textTreeContent = "Some text content";
String textTreeContent = "Some text content ≤ \u2264";
when(literalTree.getBody()).thenReturn(textTree);
when(textTree.toString()).thenReturn(textTreeContent);
when(linkTree.getKind()).thenReturn(Kind.LINK);
Expand All @@ -169,7 +170,7 @@ public void replaceLinksAndCodes() {
String result = baseLookup.replaceLinksAndCodes(Arrays.asList(linkTree, literalTree, textTree));

assertEquals("Wrong result", result, "<xref uid=\"Some#signature\" data-throw-if-not-resolved=\"false\">"
+ "Some#signature</xref><code>Some text content</code>" + textTreeContent);
+ "Some#signature</xref><code>Some text content ≤ ≤</code>" + textTreeContent);
}

@Test
Expand Down