mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 03:21:12 +07:00
[javadoc] SnippetMarkup: report if regexp is too complex
GitOrigin-RevId: a131553de703e6f129e6228599a85f7fe852516d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a99a0a890e
commit
32339d4c71
@@ -3,6 +3,7 @@ package com.intellij.codeInsight.javadoc;
|
||||
|
||||
import com.intellij.ide.nls.NlsMessages;
|
||||
import com.intellij.java.JavaBundle;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.util.NlsContexts;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
@@ -722,7 +723,12 @@ public class SnippetMarkup {
|
||||
String replacement = replace.replacement();
|
||||
if (selector instanceof Regex regex) {
|
||||
try {
|
||||
content = regex.pattern().matcher(content).replaceAll(replacement);
|
||||
content = regex.pattern().matcher(StringUtil.newBombedCharSequence(content, 1000)).replaceAll(replacement);
|
||||
}
|
||||
catch (StackOverflowError | ProcessCanceledException e) {
|
||||
ErrorMarkup replacementError = new ErrorMarkup(
|
||||
replace.range(), JavaBundle.message("javadoc.snippet.error.regex.too.complex", "replace", regex.pattern().pattern()));
|
||||
visitor.visitError(replacementError);
|
||||
}
|
||||
catch (IllegalArgumentException | IndexOutOfBoundsException e) {
|
||||
ErrorMarkup replacementError = new ErrorMarkup(
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@@ -368,7 +369,14 @@ public class SnippetMarkupTest {
|
||||
r2 continues yyy
|
||||
""");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void visitorRegexpTooComplex() {
|
||||
String str = "a".repeat(100000);
|
||||
testVisitor("// @replace regex=\"(a*)*b\" replacement='z':\n" + str, null, true,
|
||||
"Error: @replace: too complex regular expression '(a*)*b'\n" + str);
|
||||
}
|
||||
|
||||
private static void testParsing(@NotNull String input, @NotNull String expected) {
|
||||
assertEquals(expected, SnippetMarkup.parse(input).toString());
|
||||
}
|
||||
@@ -376,7 +384,7 @@ public class SnippetMarkupTest {
|
||||
private static void testVisitor(@NotNull String input, @Nullable String region, boolean processReplacements, @NotNull String expected) {
|
||||
var visitor = new SnippetMarkup.SnippetVisitor() {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
|
||||
|
||||
@Override
|
||||
public void visitPlainText(@NotNull PlainText plainText,
|
||||
@NotNull List<@NotNull LocationMarkupNode> activeNodes) {
|
||||
|
||||
@@ -1829,5 +1829,6 @@ javadoc.snippet.error.missing.required.attribute=@{0}: missing ''{1}'' attribute
|
||||
javadoc.snippet.error.both.substring.and.regex=@{0}: either regex or substring should be specified but not both
|
||||
javadoc.snippet.error.malformed.regular.expression=@{0}: malformed regular expression: {1}
|
||||
javadoc.snippet.error.malformed.replacement=@{0}: malformed regular expression replacement ''{1}'': {2}
|
||||
javadoc.snippet.error.regex.too.complex=@{0}: too complex regular expression ''{1}''
|
||||
intention.family.name.synchronize.inline.snippet=Synchronize inline snippet
|
||||
inspection.message.external.snippet.differs.from.inline.snippet=External snippet differs from inline snippet
|
||||
|
||||
Reference in New Issue
Block a user