regex: \# is not a redundant escape in comment mode (IDEA-221089)

GitOrigin-RevId: ff2e9337cdf051134b088a7f32a732b5c27798fa
This commit is contained in:
Bas Leijdekkers
2020-02-29 19:40:47 +01:00
committed by intellij-monorepo-bot
parent c495851647
commit d6d3d67404
4 changed files with 293 additions and 271 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -381,6 +381,7 @@ BACK_REFERENCES_GROUP = [1-9][0-9]{0,2}
}
{ESCAPE} [A-Za-z] { return StringEscapesTokenTypes.INVALID_CHARACTER_ESCAPE_TOKEN; }
{ESCAPE} "#" { return commentMode ? RegExpTT.ESC_CHARACTER : RegExpTT.REDUNDANT_ESCAPE; }
{ESCAPE} {ANY} { return RegExpTT.REDUNDANT_ESCAPE; }
{ESCAPE} { return StringEscapesTokenTypes.INVALID_CHARACTER_ESCAPE_TOKEN; }

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.intellij.lang.regexp;
import com.intellij.lexer.Lexer;
@@ -733,6 +733,15 @@ public class RegExpLexerTest extends LexerTestCase {
"ESC_CHARACTER ('\\^')", lexer);
}
public void testPoundSign() {
final RegExpLexer lexer = new RegExpLexer(EnumSet.noneOf(RegExpCapability.class));
doTest("\\#(?x)\\#", "REDUNDANT_ESCAPE ('\\#')\n" +
"SET_OPTIONS ('(?')\n" +
"OPTIONS_ON ('x')\n" +
"GROUP_END (')')\n" +
"ESC_CHARACTER ('\\#')", lexer);
}
@Override
protected Lexer createLexer() {
return null;

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.intellij.lang.regexp.inspection;
import com.intellij.codeInspection.LocalInspectionTool;
@@ -29,6 +29,10 @@ public class RedundantEscapeInspectionTest extends RegExpInspectionTestCase {
new RegExpFileType(EcmaScriptRegexpLanguage.INSTANCE));
}
public void testPoundSign() {
highlightTest("<warning descr=\"Redundant character escape '\\#' in RegExp\">\\#</warning>(?x)\\#");
}
@NotNull
@Override
protected LocalInspectionTool getInspection() {