RegExp: Escape ] correctly if it was unnecessarily escaped before (IDEA-195762)

This commit is contained in:
Bas Leijdekkers
2018-07-19 23:03:16 +02:00
parent 2b95788e95
commit 02661143f1
2 changed files with 11 additions and 1 deletions
@@ -105,7 +105,13 @@ public class SingleCharAlternationInspection extends LocalInspectionTool {
final RegExpChar ch = (RegExpChar)child;
final IElementType type = ch.getNode().getFirstChildNode().getElementType();
if (type == RegExpTT.REDUNDANT_ESCAPE) {
text.append((char)ch.getValue());
final int value = ch.getValue();
if (value == ']') {
text.append(ch.getUnescapedText());
}
else {
text.append((char)value);
}
}
else if (type == RegExpTT.ESC_CHARACTER) {
final int value = ch.getValue();
@@ -39,6 +39,10 @@ public class SingleCharAlternationInspectionTest extends RegExpInspectionTestCas
"([.\\[\\](){}^?*|+\\-$])ab", "Replace with '[.\\[\\](){}^?*|+\\-$]'");
}
public void testRedundantEscapeReplacement() {
quickfixTest("(<warning descr=\"Single character alternation in RegExp\">\\[<caret>|\\]</warning>)", "([\\[\\]])", "Replace with '[\\[\\]]");
}
@NotNull
@Override
protected LocalInspectionTool getInspection() {