mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-21 22:11:40 +07:00
Fixed SQL 'select/insert/...' rule injection into indented string literals (PY-11970)
This commit is contained in:
@@ -9,6 +9,6 @@
|
||||
</injection>
|
||||
<injection language="SQL" injector-id="python">
|
||||
<display-name>"SQL select/delete/insert/update/create"</display-name>
|
||||
<place><![CDATA[pyLiteralExpression().withText(string().matchesBrics(".{0,5}(((SELECT|DELETE) .*FROM)|((INSERT|REPLACE) .*INTO)|(UPDATE .* SET)|((CREATE|DROP|ALTER) +(TABLE|INDEX))) .*"))]]></place>
|
||||
<place><![CDATA[pyStringLiteralMatches("[ \\t\\r\\n]*(((SELECT|DELETE) .*FROM)|((INSERT|REPLACE) .*INTO)|(UPDATE .* SET)|((CREATE|DROP|ALTER) +(TABLE|INDEX))).*")]]></place>
|
||||
</injection>
|
||||
</component>
|
||||
|
||||
@@ -22,11 +22,14 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import com.jetbrains.python.codeInsight.controlflow.ScopeOwner;
|
||||
import com.jetbrains.python.documentation.DocStringUtil;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.resolve.PyResolveContext;
|
||||
import com.jetbrains.python.psi.types.TypeEvalContext;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
@@ -39,6 +42,23 @@ public class PythonPatterns extends PlatformPatterns {
|
||||
});
|
||||
}
|
||||
|
||||
public static PyElementPattern.Capture<PyStringLiteralExpression> pyStringLiteralMatches(final String regexp) {
|
||||
final Pattern pattern = Pattern.compile(regexp, Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
|
||||
return new PyElementPattern.Capture<PyStringLiteralExpression>(new InitialPatternCondition<PyStringLiteralExpression>(PyStringLiteralExpression.class) {
|
||||
@Override
|
||||
public boolean accepts(@Nullable Object o, ProcessingContext context) {
|
||||
if (o instanceof PyStringLiteralExpression) {
|
||||
final PyStringLiteralExpression expr = (PyStringLiteralExpression)o;
|
||||
if (!DocStringUtil.isDocStringExpression(expr)) {
|
||||
final String value = expr.getStringValue();
|
||||
return pattern.matcher(value).matches();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static PyElementPattern.Capture<PyExpression> pyArgument(final String functionName, final int index) {
|
||||
return new PyElementPattern.Capture<PyExpression>(new InitialPatternCondition<PyExpression>(PyExpression.class) {
|
||||
public boolean accepts(@Nullable final Object o, final ProcessingContext context) {
|
||||
|
||||
Reference in New Issue
Block a user