mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[javadoc] Exclude \n from regex replacement in snippets
GitOrigin-RevId: 2e7993426c86cfb8b312878f895107a873c77e8f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ffca32cd79
commit
380117325f
@@ -722,6 +722,11 @@ public class SnippetMarkup {
|
||||
Selector selector = replace.selector();
|
||||
String replacement = replace.replacement();
|
||||
if (selector instanceof Regex regex) {
|
||||
boolean addLineBreak = false;
|
||||
if (content.endsWith("\n")) {
|
||||
content = content.substring(0, content.length() - 1);
|
||||
addLineBreak = true;
|
||||
}
|
||||
try {
|
||||
content = regex.pattern().matcher(StringUtil.newBombedCharSequence(content, 1000)).replaceAll(replacement);
|
||||
}
|
||||
@@ -735,6 +740,9 @@ public class SnippetMarkup {
|
||||
replace.range(), JavaBundle.message("javadoc.snippet.error.malformed.replacement", "replace", replacement, e.getMessage()));
|
||||
visitor.visitError(replacementError);
|
||||
}
|
||||
if (addLineBreak) {
|
||||
content += "\n";
|
||||
}
|
||||
}
|
||||
else if (selector instanceof Substring substring) {
|
||||
content = content.replace(substring.substring(), replacement);
|
||||
|
||||
@@ -376,6 +376,15 @@ public class SnippetMarkupTest {
|
||||
testVisitor("// @replace regex=\"(a*)*b\" replacement='z':\n" + str, null, true,
|
||||
"Error: @replace: too complex regular expression '(a*)*b'\n" + str);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void visitorRegexpDotAsterisk() {
|
||||
testVisitor("""
|
||||
// @start region=main
|
||||
aaaa // @replace regex=".*" replacement="."
|
||||
// @end region=main
|
||||
""", null, true, "..\n");
|
||||
}
|
||||
|
||||
private static void testParsing(@NotNull String input, @NotNull String expected) {
|
||||
assertEquals(expected, SnippetMarkup.parse(input).toString());
|
||||
|
||||
Reference in New Issue
Block a user