Skip to content

Find the holes before someone else does. A fast, 100% Rust vulnerability scanner: XSS, SQL injection, leaked secrets, dependency CVEs and AI agent setups.

fix(report): use singular for one file or one package in the summary line (#177)

Minga17a20b9c111
diff --git a/CHANGELOG.md b/CHANGELOG.md
index dbfa333..890dc9d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,8 @@
## Unreleased
+- Report: the summary line says `Scanned 1 file` and `1 package checked against OSV.dev` for a
+ count of one; other counts stay plural.
- Code: the JavaScript and Python patterns in `code.sql-injection` now also match escaped
newlines, tabs and carriage returns (`\n`, `\t`, `\r`) inside quoted query strings
(`db.query("SELECT id\nFROM users WHERE id = " + id)`,
diff --git a/src/report.rs b/src/report.rs
index eb7f8a9..d1585d2 100644
--- a/src/report.rs
+++ b/src/report.rs
@@ -83,8 +83,13 @@ pub fn terminal(report: &Report, style: &Style) -> String {
let deps = match &report.dependency_check {
DependencyCheck::Skipped => "skipped (offline)".to_string(),
DependencyCheck::Done => format!(
- "{} packages checked against OSV.dev",
- report.packages_checked
+ "{} package{} checked against OSV.dev",
+ report.packages_checked,
+ if report.packages_checked == 1 {
+ ""
+ } else {
+ "s"
+ }
),
DependencyCheck::Failed(e) => format!("failed: {e}"),
};
@@ -94,8 +99,9 @@ pub fn terminal(report: &Report, style: &Style) -> String {
style.paint(
"2",
&format!(
- "Scanned {} files in {:.2} s. Dependencies: {deps}.",
+ "Scanned {} file{} in {:.2} s. Dependencies: {deps}.",
thousands(report.files_scanned),
+ if report.files_scanned == 1 { "" } else { "s" },
report.elapsed_ms as f64 / 1000.0
)
)
@@ -128,3 +134,35 @@ fn thousands(n: usize) -> String {
}
out
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn summary(files: usize, packages: usize) -> String {
+ let report = Report {
+ files_scanned: files,
+ packages_checked: packages,
+ dependency_check: DependencyCheck::Done,
+ ..Default::default()
+ };
+ terminal(&report, &Style { color: false })
+ }
+
+ #[test]
+ fn summary_line_uses_singular_for_one() {
+ let out = summary(1, 1);
+ assert!(out.contains("Scanned 1 file in "), "{out}");
+ assert!(out.contains("1 package checked against OSV.dev"), "{out}");
+ }
+
+ #[test]
+ fn summary_line_keeps_plural_and_thousands_separator() {
+ let out = summary(1195, 2);
+ assert!(out.contains("Scanned 1,195 files in "), "{out}");
+ assert!(out.contains("2 packages checked against OSV.dev"), "{out}");
+ let out = summary(0, 0);
+ assert!(out.contains("Scanned 0 files in "), "{out}");
+ assert!(out.contains("0 packages checked against OSV.dev"), "{out}");
+ }
+}