You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2021/04/24 12:17:26 UTC
[maven-javadoc-plugin] branch master updated: [MJAVADOC-662]
Generated javadoc for static final fields should be HTML escaped
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new e7a3fe0 [MJAVADOC-662] Generated javadoc for static final fields should be HTML escaped
e7a3fe0 is described below
commit e7a3fe0ed8d7be61de9cc458751b5a24f640fba8
Author: XenoAmess <xe...@gmail.com>
AuthorDate: Sat Apr 24 14:17:05 2021 +0200
[MJAVADOC-662] Generated javadoc for static final fields should be HTML escaped
Signed-off-by: rfscholte <rf...@apache.org>
---
pom.xml | 5 +++++
.../maven/plugins/javadoc/AbstractFixJavadocMojo.java | 10 ++++++----
.../expected/src/main/java/fix/test/ClassWithJavadoc.java | 15 +++++++++++++++
.../src/main/java/fix/test/ClassWithNoJavadoc.java | 9 +++++++++
.../fix-test/src/main/java/fix/test/ClassWithJavadoc.java | 15 +++++++++++++++
.../src/main/java/fix/test/ClassWithNoJavadoc.java | 6 ++++++
6 files changed, 56 insertions(+), 4 deletions(-)
diff --git a/pom.xml b/pom.xml
index 2d7edee..ca3c59f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -256,6 +256,11 @@ under the License.
<version>3.8.1</version>
</dependency>
<dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-text</artifactId>
+ <version>1.3</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
diff --git a/src/main/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojo.java b/src/main/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojo.java
index 1d98ada..fac56cc 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojo.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojo.java
@@ -39,6 +39,7 @@ import com.thoughtworks.qdox.parser.ParseException;
import com.thoughtworks.qdox.type.TypeResolver;
import org.apache.commons.lang3.ClassUtils;
+import org.apache.commons.text.StringEscapeUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -1381,7 +1382,7 @@ public abstract class AbstractFixJavadocMojo
Character.TYPE.toString() ) )
{
sb.append( "=" );
- sb.append( field.getInitializationExpression().trim() );
+ sb.append( StringEscapeUtils.escapeHtml4( field.getInitializationExpression().trim() ) );
}
if ( qualifiedName.equals( String.class.getName() ) )
@@ -1408,15 +1409,16 @@ public abstract class AbstractFixJavadocMojo
}
sb.append( "=\"" );
+ String escapedValue = StringEscapeUtils.escapeHtml4( value.toString() );
// reduce the size
// CHECKSTYLE_OFF: MagicNumber
- if ( value.length() < 40 )
+ if ( escapedValue.length() < 40 )
{
- sb.append( value.toString() ).append( "\"" );
+ sb.append( escapedValue ).append( "\"" );
}
else
{
- sb.append( value.toString(), 0, 39 ).append( "\"{trunked}" );
+ sb.append( escapedValue, 0, 39 ).append( "\"{trunked}" );
}
// CHECKSTYLE_ON: MagicNumber
}
diff --git a/src/test/resources/unit/fix-test/expected/src/main/java/fix/test/ClassWithJavadoc.java b/src/test/resources/unit/fix-test/expected/src/main/java/fix/test/ClassWithJavadoc.java
index 174992f..c5a6ba3 100644
--- a/src/test/resources/unit/fix-test/expected/src/main/java/fix/test/ClassWithJavadoc.java
+++ b/src/test/resources/unit/fix-test/expected/src/main/java/fix/test/ClassWithJavadoc.java
@@ -451,6 +451,21 @@ public class ClassWithJavadoc
{
throw new Exception();
}
+
+ /**
+ * to test if it will handle static final int field with left shift operators correctly.
+ */
+ public static final int TEST_STATIC_FINAL_FIELD_0 = 1 << 2;
+
+ /**
+ * to test if it will handle static final int field with right shift operators correctly.
+ */
+ public static final int TEST_STATIC_FINAL_FIELD_1 = 2 >> 1;
+
+ /**
+ * to test if it will handle static final String field with left shift operator and right shift operator correctly.
+ */
+ public static final String TEST_STATIC_FINAL_FIELD_2 = "<>?";
}
/**
diff --git a/src/test/resources/unit/fix-test/expected/src/main/java/fix/test/ClassWithNoJavadoc.java b/src/test/resources/unit/fix-test/expected/src/main/java/fix/test/ClassWithNoJavadoc.java
index e2ff6a9..44d869e 100644
--- a/src/test/resources/unit/fix-test/expected/src/main/java/fix/test/ClassWithNoJavadoc.java
+++ b/src/test/resources/unit/fix-test/expected/src/main/java/fix/test/ClassWithNoJavadoc.java
@@ -267,6 +267,15 @@ public class ClassWithNoJavadoc
{
throw new Exception();
}
+
+ /** Constant <code>TEST_STATIC_FINAL_FIELD_0=1 << 2</code> */
+ public static final int TEST_STATIC_FINAL_FIELD_0 = 1 << 2;
+
+ /** Constant <code>TEST_STATIC_FINAL_FIELD_1=2 >> 1</code> */
+ public static final int TEST_STATIC_FINAL_FIELD_1 = 2 >> 1;
+
+ /** Constant <code>TEST_STATIC_FINAL_FIELD_2="<>?"</code> */
+ public static final String TEST_STATIC_FINAL_FIELD_2 = "<>?";
}
@SuppressWarnings("SameReturnValue")
diff --git a/src/test/resources/unit/fix-test/src/main/java/fix/test/ClassWithJavadoc.java b/src/test/resources/unit/fix-test/src/main/java/fix/test/ClassWithJavadoc.java
index f5c2f96..e82ecaa 100644
--- a/src/test/resources/unit/fix-test/src/main/java/fix/test/ClassWithJavadoc.java
+++ b/src/test/resources/unit/fix-test/src/main/java/fix/test/ClassWithJavadoc.java
@@ -414,6 +414,21 @@ public class ClassWithJavadoc
{
throw new Exception();
}
+
+ /**
+ * to test if it will handle static final int field with left shift operators correctly.
+ */
+ public static final int TEST_STATIC_FINAL_FIELD_0 = 1 << 2;
+
+ /**
+ * to test if it will handle static final int field with right shift operators correctly.
+ */
+ public static final int TEST_STATIC_FINAL_FIELD_1 = 2 >> 1;
+
+ /**
+ * to test if it will handle static final String field with left shift operator and right shift operator correctly.
+ */
+ public static final String TEST_STATIC_FINAL_FIELD_2 = "<>?";
}
/**
diff --git a/src/test/resources/unit/fix-test/src/main/java/fix/test/ClassWithNoJavadoc.java b/src/test/resources/unit/fix-test/src/main/java/fix/test/ClassWithNoJavadoc.java
index fa4421c..5fddac7 100644
--- a/src/test/resources/unit/fix-test/src/main/java/fix/test/ClassWithNoJavadoc.java
+++ b/src/test/resources/unit/fix-test/src/main/java/fix/test/ClassWithNoJavadoc.java
@@ -170,6 +170,12 @@ public class ClassWithNoJavadoc
{
throw new Exception();
}
+
+ public static final int TEST_STATIC_FINAL_FIELD_0 = 1 << 2;
+
+ public static final int TEST_STATIC_FINAL_FIELD_1 = 2 >> 1;
+
+ public static final String TEST_STATIC_FINAL_FIELD_2 = "<>?";
}
@SuppressWarnings("SameReturnValue")