json: improve cutting html anchor tag from untrusted x-intellij-html-description (IDEA-283967)

GitOrigin-RevId: 74f2712cb31556ddd35781a7fe118cda1eefa9fc
This commit is contained in:
Sergey Simonchik
2023-03-02 00:54:37 +00:00
committed by intellij-monorepo-bot
parent 347e1e6c28
commit de7af54d1c
@@ -187,7 +187,7 @@ public class JsonSchemaDocumentationProvider implements DocumentationProvider {
public static String getBestDocumentation(boolean preferShort, @NotNull final JsonSchemaObject schema) {
String htmlDescription = schema.getHtmlDescription();
if (htmlDescription != null && hasNonTrustedProjects()) {
htmlDescription = htmlDescription.replaceAll("<a[^>]*>", "").replaceAll("</a>", "");
htmlDescription = cutHtmlAnchor(htmlDescription);
}
final String description = schema.getDescription();
final String title = schema.getTitle();
@@ -205,6 +205,16 @@ public class JsonSchemaDocumentationProvider implements DocumentationProvider {
return null;
}
private static @NotNull String cutHtmlAnchor(@NotNull String html) {
String current;
String next = html;
do {
current = next;
next = current.replaceAll("<\\s*a[^>]*>", "").replaceAll("<\\s*/\\s*a\\s*>", "");
} while (!next.equals(current));
return next;
}
private static boolean hasNonTrustedProjects() {
for (Project project : ProjectManager.getInstance().getOpenProjects()) {
if (!TrustedProjects.isTrusted(project)) {