mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 11:50:54 +07:00
escaping # in verbose regexps is not redundant (PY-6545)
This commit is contained in:
@@ -1,17 +1,18 @@
|
||||
package com.jetbrains.python.psi.impl;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.lang.injection.InjectedLanguageManager;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.LiteralTextEscaper;
|
||||
import com.intellij.psi.PsiLanguageInjectionHost;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.psi.PsiReferenceService;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry;
|
||||
import com.intellij.psi.impl.source.tree.LeafElement;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.jetbrains.python.PyTokenTypes;
|
||||
import com.jetbrains.python.codeInsight.regexp.PythonVerboseRegexpLanguage;
|
||||
import com.jetbrains.python.lexer.PythonHighlightingLexer;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.types.PyType;
|
||||
@@ -396,9 +397,25 @@ public class PyStringLiteralExpressionImpl extends PyElementImpl implements PySt
|
||||
}
|
||||
|
||||
public boolean characterNeedsEscaping(char c) {
|
||||
if (c == '#') {
|
||||
return isVerboseInjection();
|
||||
}
|
||||
return c == ']' || c == '}' || c == '\"' || c == '\'';
|
||||
}
|
||||
|
||||
private boolean isVerboseInjection() {
|
||||
List<Pair<PsiElement,TextRange>> files = InjectedLanguageManager.getInstance(getProject()).getInjectedPsiFiles(this);
|
||||
if (files != null) {
|
||||
for (Pair<PsiElement, TextRange> file : files) {
|
||||
Language language = file.getFirst().getLanguage();
|
||||
if (language == PythonVerboseRegexpLanguage.INSTANCE) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean supportsPerl5EmbeddedComments() {
|
||||
return true;
|
||||
}
|
||||
|
||||
15
python/testData/regexp/verboseEscapedHash.py
Normal file
15
python/testData/regexp/verboseEscapedHash.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import re
|
||||
|
||||
urlparts = re.compile(
|
||||
r"""
|
||||
(?P<scheme>http|https)
|
||||
://
|
||||
(?P<netloc>(?:(?!/|\?|\#)\S)*)
|
||||
/?
|
||||
(?P<path>(?:(?!\?|\#)\S)*)
|
||||
\??
|
||||
(?P<query>(?:(?!\#)\S)*)
|
||||
\#?
|
||||
(?P<fragment>[\S]*)
|
||||
""", re.VERBOSE
|
||||
)
|
||||
@@ -55,6 +55,10 @@ public class PyRegexpTest extends PyTestCase {
|
||||
doTestHighlighting();
|
||||
}
|
||||
|
||||
public void testVerboseEscapedHash() { // PY-6545
|
||||
doTestHighlighting();
|
||||
}
|
||||
|
||||
private void doTestHighlighting() {
|
||||
myFixture.testHighlighting(true, false, true, "regexp/" + getTestName(true) + ".py");
|
||||
}
|
||||
|
||||
@@ -105,7 +105,8 @@ public class PythonAllTestsSuite {
|
||||
PyJoinLinesTest.class,
|
||||
PyStatementListTest.class,
|
||||
PyChangeSignatureTest.class,
|
||||
PyCommenterTest.class
|
||||
PyCommenterTest.class,
|
||||
PyRegexpTest.class
|
||||
};
|
||||
|
||||
public static TestSuite suite() {
|
||||
|
||||
Reference in New Issue
Block a user