fix(csaf): read a Siemens fix only from 'Update to V<version>'

Sampled across the feed: a vendor fix can name hardware (LOGO! V9 BM) or a
version with letters (V3.X.18); neither is a firmware to update to.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9
This commit is contained in:
Sharang ParnerkarandClaude Opus 5.5 committed 2026-11-28 14:57:05 +01:00
1 parent 5d4d6198df
commit 87a0f5b5c6
1 file changed
+41 -12
+41 -12
View File
@@ -222,19 +222,48 @@ impl Advisory {
}
}
/// The first version a text names after a `V` (`Update to V3.1.5 or later
/// version` names `3.1.5`), if any.
/// The firmware a vendor fix's text updates to, when it says so the way
/// Siemens does: `Update to V3.1.5 or later version` is `3.1.5`. Anything
/// else gives none: a version with letters (`V3.X.18`), or a text about
/// something other than an update (`A hardware upgrade to LOGO! V9 BM`).
fn version_in_text(text: &str) -> Option<String> {
text.match_indices(['V', 'v']).find_map(|(at, _)| {
let version: String = text[at + 1..]
.chars()
.take_while(|c| c.is_ascii_digit() || *c == '.')
.collect();
let version = version.trim_end_matches('.');
version
.starts_with(|c: char| c.is_ascii_digit())
.then(|| version.to_string())
})
let rest = text.trim_start().strip_prefix("Update to V")?;
let end = rest
.find(|c: char| !(c.is_ascii_digit() || c == '.'))
.unwrap_or(rest.len());
let (version, after) = rest.split_at(end);
let version = version.trim_end_matches('.');
let ends_cleanly = after.is_empty() || after.starts_with([' ', ',', '.', ';']);
(version.starts_with(|c: char| c.is_ascii_digit()) && ends_cleanly).then(|| version.to_string())
}
#[cfg(test)]
mod tests {
use super::version_in_text;
#[test]
fn only_an_update_to_a_numeric_version_names_a_fix() {
let read = |t: &str| version_in_text(t);
assert_eq!(
read("Update to V3.1.5 or later version").as_deref(),
Some("3.1.5")
);
assert_eq!(read("Update to V9 or later version").as_deref(), Some("9"));
assert_eq!(
read("Update to V4.2.1 or later version, migrate project").as_deref(),
Some("4.2.1")
);
assert_eq!(read("Update to V2.9.8.").as_deref(), Some("2.9.8"));
assert_eq!(read("Update to V3.X.18 or later version"), None);
assert_eq!(
read("Note: A hardware upgrade to LOGO! V9 BM or later is also required"),
None
);
assert_eq!(
read("To obtain SIMATIC S7-410 V10.1 contact your local support."),
None
);
}
}
/// The text at `key` of `value`, trimmed, if not empty.