Skip to content

Commit

Permalink
тип обычная уязвимость + обработка Новый(Тип) + выключил правило
Browse files Browse the repository at this point in the history
  • Loading branch information
artbear committed Jul 20, 2023
1 parent c95c010 commit b77d947
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,21 @@
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticSeverity;
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticTag;
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticType;
import com.github._1c_syntax.bsl.languageserver.utils.bsl.Constructors;
import com.github._1c_syntax.bsl.parser.BSLParser;
import com.github._1c_syntax.utils.CaseInsensitivePattern;
import org.antlr.v4.runtime.tree.ParseTree;

import java.util.regex.Pattern;

@DiagnosticMetadata(
type = DiagnosticType.CODE_SMELL,
type = DiagnosticType.VULNERABILITY,
severity = DiagnosticSeverity.MINOR,
minutesToFix = 1,
tags = {
DiagnosticTag.SUSPICIOUS
}
},
activatedByDefault = false
)

public class InternetAccessDiagnostic extends AbstractVisitorDiagnostic {
Expand All @@ -48,13 +50,12 @@ public class InternetAccessDiagnostic extends AbstractVisitorDiagnostic {

@Override
public ParseTree visitNewExpression(BSLParser.NewExpressionContext ctx) {
var typeNameContext = ctx.typeName();
if (typeNameContext != null) {
var matcherTypeName = PATTERN_NEW_EXPRESSION.matcher(typeNameContext.getText());
Constructors.typeName(ctx).ifPresent((String typeName) -> {
var matcherTypeName = PATTERN_NEW_EXPRESSION.matcher(typeName);
if (matcherTypeName.matches()) {
diagnosticStorage.addDiagnostic(ctx);
}
}
});
return super.visitNewExpression(ctx);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ void test() {
.hasRange(25, 21, 51)
.hasRange(29, 14, 43)
.hasRange(35, 14, 32)
.hasRange(38, 10, 21)
.hasSize(17);
.hasRange(39, 14, 35)
.hasRange(42, 10, 21)
.hasSize(18);
}
}
4 changes: 4 additions & 0 deletions src/test/resources/diagnostics/InternetAccessDiagnostic.bsl
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@
Профиль = Новый InternetMail; // ошибка
КонецФункции

Функция InternetMail_НовыйТип()
Профиль = Новый("InternetMail"); // ошибка
КонецФункции

Профиль = Новый Почта; // ошибка

0 comments on commit b77d947

Please sign in to comment.