Skip to content

Commit

Permalink
[Java] Escape javadoc for basic html characters. Issue #826.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjpt777 committed Dec 17, 2020
1 parent 0fbbe7a commit ccc0261
Showing 1 changed file with 79 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,11 @@ public static void generateTypeJavadoc(

sb.append('\n')
.append(indent).append("/**\n")
.append(indent).append(" * ").append(description).append('\n')
.append(indent).append(" * ");

escapeJavadoc(sb, description);

sb.append('\n')
.append(indent).append(" */\n");
}

Expand All @@ -306,7 +310,11 @@ public static void generateOptionDecodeJavadoc(
}

out.append(indent).append("/**\n")
.append(indent).append(" * ").append(description).append('\n')
.append(indent).append(" * ");

escapeJavadoc(out, description);

out.append('\n')
.append(indent).append(" *\n")
.append(indent).append(" * @return true if ").append(optionToken.name()).append(" set or false if not.\n")
.append(indent).append(" */\n");
Expand All @@ -330,9 +338,13 @@ public static void generateOptionEncodeJavadoc(
return;
}

final String name = optionToken.name();
out.append(indent).append("/**\n")
.append(indent).append(" * ").append(description).append('\n')
.append(indent).append(" * ");

escapeJavadoc(out, description);

final String name = optionToken.name();
out.append('\n')
.append(indent).append(" *\n")
.append(indent).append(" * @param value true if ").append(name).append(" is set or false if not.\n")
.append(indent).append(" */\n");
Expand All @@ -357,9 +369,17 @@ public static void generateFlyweightPropertyJavadoc(

sb.append('\n')
.append(indent).append("/**\n")
.append(indent).append(" * ").append(description).append('\n')
.append(indent).append(" * ");

escapeJavadoc(sb, description);

sb.append('\n')
.append(indent).append(" *\n")
.append(indent).append(" * @return ").append(typeName).append(" : ").append(description).append("\n")
.append(indent).append(" * @return ").append(typeName).append(" : ");

escapeJavadoc(sb, description);

sb.append("\n")
.append(indent).append(" */");
}

Expand All @@ -382,10 +402,62 @@ public static void generateGroupEncodePropertyJavadoc(

sb.append('\n')
.append(indent).append("/**\n")
.append(indent).append(" * ").append(description).append("\n")
.append(indent).append(" * ");

escapeJavadoc(sb, description);

sb.append("\n")
.append(indent).append(" *\n")
.append(indent).append(" * @param count of times the group will be encoded.\n")
.append(indent).append(" * @return ").append(typeName).append(" : encoder for the group.\n")
.append(indent).append(" */");
}

private static void escapeJavadoc(final Appendable out, final String doc) throws IOException
{
for (int i = 0, length = doc.length(); i < length; i++)
{
final char c = doc.charAt(i);
switch (c)
{
case '<':
out.append("&lt;");
break;

case '>':
out.append("&gt;");
break;

default:
out.append(c);
break;
}
}
}

private static void escapeJavadoc(final StringBuilder sb, final String doc)
{
for (int i = 0, length = doc.length(); i < length; i++)
{
final char c = doc.charAt(i);
switch (c)
{
case '<':
sb.append("&lt;");
break;

case '>':
sb.append("&gt;");
break;

case '&':
sb.append("&amp;");
break;

default:
sb.append(c);
break;
}
}
}
}

0 comments on commit ccc0261

Please sign in to comment.