fix(dotnet): tighter packages/ detection; var forms in C# rules
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
This commit is contained in:
1 parent
2bafe12b2a
commit
4f27ddaef2
4 files changed
+89
-8
No files matched your search
@@ -30,6 +30,10 @@ namespace Plant.Tests
|
||||
// ruleid: cra-ai-20-csharp-sql-string
|
||||
var cmd3 = new SqlCommand(sql, conn);
|
||||
|
||||
var sql2 = "SELECT * FROM Lines WHERE Code = '" + id + "'";
|
||||
// ruleid: cra-ai-20-csharp-sql-string
|
||||
var cmd4 = new SqlCommand(sql2, conn);
|
||||
|
||||
// ruleid: cra-ai-20-csharp-sql-string
|
||||
cmd.CommandText = String.Format("UPDATE Orders SET State = {0}", id);
|
||||
|
||||
@@ -67,6 +71,14 @@ namespace Plant.Tests
|
||||
|
||||
// ok: cra-ai-20-csharp-process-start
|
||||
Process.Start(path);
|
||||
|
||||
var startInfo = new ProcessStartInfo();
|
||||
// ruleid: cra-ai-20-csharp-process-start
|
||||
startInfo.FileName = path + "\\tool.exe";
|
||||
|
||||
var dialog = new SaveFileDialog();
|
||||
// ok: cra-ai-20-csharp-process-start
|
||||
dialog.FileName = path + ".csv";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,6 +116,14 @@ namespace Plant.Tests
|
||||
// ruleid: cra-ai-20-csharp-xxe
|
||||
doc.LoadXml(xml);
|
||||
|
||||
var doc2 = new XmlDocument();
|
||||
// ruleid: cra-ai-20-csharp-xxe
|
||||
doc2.Load(file);
|
||||
|
||||
var reader = new XmlTextReader(file);
|
||||
// ruleid: cra-ai-20-csharp-xxe
|
||||
while (reader.Read()) { }
|
||||
|
||||
var settings = new XmlReaderSettings();
|
||||
// ruleid: cra-ai-20-csharp-xxe
|
||||
settings.DtdProcessing = DtdProcessing.Parse;
|
||||
@@ -120,6 +140,20 @@ namespace Plant.Tests
|
||||
// ok: cra-ai-20-csharp-xxe
|
||||
doc.LoadXml(xml);
|
||||
|
||||
var doc2 = new XmlDocument();
|
||||
doc2.XmlResolver = null;
|
||||
// ok: cra-ai-20-csharp-xxe
|
||||
doc2.LoadXml(xml);
|
||||
|
||||
var doc3 = new XmlDocument { XmlResolver = null };
|
||||
// ok: cra-ai-20-csharp-xxe
|
||||
doc3.LoadXml(xml);
|
||||
|
||||
var reader = new XmlTextReader(xml);
|
||||
reader.DtdProcessing = DtdProcessing.Prohibit;
|
||||
// ok: cra-ai-20-csharp-xxe
|
||||
while (reader.Read()) { }
|
||||
|
||||
var settings = new XmlReaderSettings();
|
||||
// ok: cra-ai-20-csharp-xxe
|
||||
settings.DtdProcessing = DtdProcessing.Prohibit;
|
||||
@@ -211,6 +245,9 @@ namespace Plant.Tests
|
||||
// ruleid: cra-ai-8-csharp-hardcoded-credential
|
||||
config.SmtpPassword = "mail-pa55word";
|
||||
|
||||
// ruleid: cra-ai-8-csharp-hardcoded-credential
|
||||
var plcPassword = "Siemens#S7-1500";
|
||||
|
||||
// ok: cra-ai-8-csharp-hardcoded-credential
|
||||
config.SmtpPassword = "";
|
||||
|
||||
|
||||
@@ -49,6 +49,9 @@ rules:
|
||||
- pattern-inside: |
|
||||
$TY $Q = $INIT;
|
||||
...
|
||||
- pattern-inside: |
|
||||
var $Q = $INIT;
|
||||
...
|
||||
- pattern-inside: |
|
||||
$Q = $INIT;
|
||||
...
|
||||
@@ -71,7 +74,19 @@ rules:
|
||||
- pattern: new ProcessStartInfo($ARG, ...)
|
||||
- pattern: new ProcessStartInfo($FILE, $ARG, ...)
|
||||
- pattern: $P.Arguments = $ARG
|
||||
- pattern: $P.FileName = $ARG
|
||||
# Only a ProcessStartInfo's: a file dialog's FileName is no command.
|
||||
- patterns:
|
||||
- pattern-either:
|
||||
- pattern-inside: |
|
||||
$PT $P = new ProcessStartInfo(...);
|
||||
...
|
||||
- pattern-inside: |
|
||||
var $P = new ProcessStartInfo(...);
|
||||
...
|
||||
- pattern-inside: |
|
||||
$P = new ProcessStartInfo(...);
|
||||
...
|
||||
- pattern: $P.FileName = $ARG
|
||||
- metavariable-pattern:
|
||||
metavariable: $ARG
|
||||
patterns:
|
||||
@@ -119,19 +134,33 @@ rules:
|
||||
- pattern-inside: |
|
||||
$D = new XmlDocument();
|
||||
...
|
||||
- pattern-inside: |
|
||||
$DT $D = new XmlDocument();
|
||||
...
|
||||
- pattern-inside: |
|
||||
var $D = new XmlDocument();
|
||||
...
|
||||
- pattern-inside: |
|
||||
$D = new XmlTextReader(...);
|
||||
...
|
||||
- pattern-inside: |
|
||||
$DT $D = new XmlTextReader(...);
|
||||
...
|
||||
- pattern-inside: |
|
||||
var $D = new XmlTextReader(...);
|
||||
...
|
||||
- pattern-not-inside: |
|
||||
$D = new $T(...);
|
||||
...
|
||||
$D.XmlResolver = null;
|
||||
...
|
||||
- pattern-not-inside: |
|
||||
$D = new $T(...);
|
||||
...
|
||||
$D.DtdProcessing = DtdProcessing.Prohibit;
|
||||
...
|
||||
- pattern-not-inside: |
|
||||
var $D = new $T { ..., XmlResolver = null, ... };
|
||||
...
|
||||
- pattern-not-inside: |
|
||||
$DT $D = new $T { ..., XmlResolver = null, ... };
|
||||
...
|
||||
- pattern-either:
|
||||
- pattern: $D.Load(...)
|
||||
- pattern: $D.LoadXml(...)
|
||||
@@ -222,6 +251,7 @@ rules:
|
||||
patterns:
|
||||
- pattern-either:
|
||||
- pattern: $TYPE $NAME = "$VALUE";
|
||||
- pattern: var $NAME = "$VALUE";
|
||||
- pattern: $NAME = "$VALUE"
|
||||
- pattern: const string $NAME = "$VALUE";
|
||||
- metavariable-regex:
|
||||
|
||||
@@ -366,9 +366,19 @@ fn restored_packages(root: &Path) -> Vec<Package> {
|
||||
out
|
||||
}
|
||||
|
||||
/// Whether `dir` looks like a package NuGet restored: it holds a `.nupkg`,
|
||||
/// or the `lib/`, `build/` or `tools/` folder of one.
|
||||
/// Whether `dir` is a package NuGet restored: named `<Id>.<Version>`, and
|
||||
/// holding a `.nupkg` or the `lib/`, `build/` or `tools/` folder of one. Both
|
||||
/// are needed: a JavaScript workspace package has a `lib/` too, but not a
|
||||
/// version in its folder name.
|
||||
pub(crate) fn is_restored_package(dir: &Path) -> bool {
|
||||
dir.file_name()
|
||||
.is_some_and(|n| split_package_folder(&n.to_string_lossy()).is_some())
|
||||
&& holds_package_content(dir)
|
||||
}
|
||||
|
||||
/// Whether `dir` holds a `.nupkg`, or the `lib/`, `build/` or `tools/` folder
|
||||
/// of one.
|
||||
fn holds_package_content(dir: &Path) -> bool {
|
||||
std::fs::read_dir(dir).is_ok_and(|entries| {
|
||||
entries.filter_map(Result::ok).any(|e| {
|
||||
let name = e.file_name().to_string_lossy().to_ascii_lowercase();
|
||||
|
||||
@@ -438,8 +438,10 @@ mod tests {
|
||||
"Plant/Hmi/obj/Debug",
|
||||
"Plant/.vs/Plant/v17",
|
||||
"Plant/TestResults/run1",
|
||||
// A JavaScript monorepo's packages/ and a script bin/ are own code.
|
||||
// A JavaScript monorepo's packages/ (even with compiled lib/) and
|
||||
// a script bin/ are own code.
|
||||
"web/packages/widgets/src",
|
||||
"web/packages/widgets/lib",
|
||||
"tools/bin",
|
||||
])
|
||||
.with_files(&[
|
||||
@@ -447,6 +449,8 @@ mod tests {
|
||||
"Plant/Hmi/Hmi.csproj",
|
||||
"Plant/packages/Newtonsoft.Json.12.0.1/Newtonsoft.Json.12.0.1.nupkg",
|
||||
"web/packages/widgets/package.json",
|
||||
"web/packages/widgets/lib/index.js",
|
||||
"web/package.json",
|
||||
"tools/bin/deploy.sh",
|
||||
]);
|
||||
assert_eq!(
|
||||
|
||||
Reference in new issue
Block a user