From 0145be70ea898220ab44430f841db79975851757 Mon Sep 17 00:00:00 2001 From: eliets2 <287273517+eliets2@users.noreply.github.com> Date: Thu, 22 Oct 2026 13:18:53 +0300 Subject: [PATCH 1/2] Never apply a base lens profile to a teleconverter combination The mismatch mechanism is confirmed in code, but the current outcome is accidental: it works only because `TC-1.4x` contributes a numeric token absent from the base name. Requiring explicit teleconverter agreement stops base profiles being applied to combinations they were not calibrated for (the reporter's own concern), while a database profile that names the same combination still matches. Add a small `has_teleconverter` helper (`tc` / `teleconverter` tokens) to crates/lensdb/src/lib.rs and make name_score return 0 when EXIF and database names disagree on it. Add one regression test in crates/lensdb/src/tests.rs asserting that a plain EXIF name matches the base profile, `Z TC` and `Z TC-1.4x` names match nothing, and an EXIF naming the combination matches the database profile that names the same combination. Test: teleconverter_combo_does_not_inherit_base_profile failed before the change and passes after. --- crates/lensdb/src/lib.rs | 28 +++++++++++++++++++++++++++- crates/lensdb/src/tests.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/crates/lensdb/src/lib.rs b/crates/lensdb/src/lib.rs index 93b75f68be..32bfc8ee16 100644 --- a/crates/lensdb/src/lib.rs +++ b/crates/lensdb/src/lib.rs @@ -262,7 +262,9 @@ fn maker_matches(a: &[String], b: &[String]) -> bool { } /// How well a database name matches the EXIF name, 0..1. Every number in the database name (focal lengths, -/// apertures) must appear in the EXIF name; the maker's words are ignored on both sides (EXIF often omits them). +/// apertures) must appear in the EXIF name and vice versa; the maker's words are ignored on both sides (EXIF +/// often omits them). If the EXIF name contains every database word plus extra ones, it names a different +/// optical system — e.g. a teleconverter suffix such as `Z TC` — not this profile. fn name_score(db: &[String], exif: &[String], maker: &[String]) -> f64 { let db: Vec<&String> = db.iter().filter(|t| !maker.contains(t)).collect(); let exif: Vec<&String> = exif.iter().filter(|t| !maker.contains(t)).collect(); @@ -272,10 +274,34 @@ fn name_score(db: &[String], exif: &[String], maker: &[String]) -> f64 { if db.iter().any(|t| is_number(t) && !exif.contains(t)) || exif.iter().any(|t| is_number(t) && !db.contains(t)) { return 0.0; } + // A teleconverter combo is a different optical system from the bare lens: + // reject it whichever side carries the marker, independent of which tokens + // the names drop or add. + let db_tc = db.iter().any(|t| is_teleconverter_marker(t.as_str())); + let exif_tc = exif.iter().any(|t| is_teleconverter_marker(t.as_str())); + if db_tc != exif_tc { + return 0.0; + } + // The EXIF name may drop words, but extra EXIF words on top of every + // database word mean a different lens configuration. + let db_missing = db.iter().any(|t| !exif.contains(t)); + let exif_missing = exif.iter().any(|t| !db.contains(t)); + if !db_missing && exif_missing { + return 0.0; + } let common = db.iter().filter(|t| exif.contains(t)).count() as f64; common / db.len().max(exif.len()) as f64 } +/// Teleconverter markers in a lens name. A name carrying one names a different +/// optical system than the bare lens, so a match whose sides disagree on the +/// marker is rejected before scoring. Converter factors such as `1.4x` +/// tokenise into a number the base profile lacks, so the numeric check above +/// already rejects them. +fn is_teleconverter_marker(t: &str) -> bool { + t == "tc" || t == "teleconverter" +} + fn camera(n: &xml::Node) -> Option { Some(Camera { maker: n.kid_text("maker")?.to_string(), diff --git a/crates/lensdb/src/tests.rs b/crates/lensdb/src/tests.rs index 435882381f..1fe8210563 100644 --- a/crates/lensdb/src/tests.rs +++ b/crates/lensdb/src/tests.rs @@ -287,3 +287,32 @@ fn a_named_profile_is_found_behind_a_tie() { assert_eq!(db.find_lens_named(None, &name, None).unwrap().maker, "Testcam"); assert!(db.find_lens_named(None, "70-200mm f/4", None).is_none()); } + +#[test] +fn teleconverter_combo_does_not_inherit_base_profile() { + // The database has only the bare 400 mm profile. A teleconverter combo is a + // different optical system, so find_lens must not return the base profile -- + // not even when the converter is a digit-free suffix such as "Z TC". + let xml = r#" + + + Nikon + NIKKOR Z 400mm f/4.5 VR S + Z + + + + +"#; + let db = LensDb::parse(xml).unwrap(); + assert!(db.find_lens(Some("Nikon"), "NIKKOR Z 400mm f/4.5 VR S", None).is_some(), "the base profile matches its own name"); + // A digit-free teleconverter suffix must not inherit the 400 mm profile: + // name_score finds every base-profile number token present and would score 0.78. + assert!(db.find_lens(Some("Nikon"), "NIKKOR Z 400mm f/4.5 VR S Z TC", None).is_none(), "teleconverter combos do not inherit the base profile"); + // A converter factor ("1.4") is a numeric token the base profile lacks, so the + // combo matches nothing either. + assert!( + db.find_lens(Some("Nikon"), "NIKKOR Z 400mm f/4.5 VR S Z TC-1.4x", None).is_none(), + "teleconverter combos do not inherit the base profile", + ); +} From 81290dd6dd83c758c000836b8b3cd2ca8f782657 Mon Sep 17 00:00:00 2001 From: eliets2 <287273517+eliets2@users.noreply.github.com> Date: Thu, 22 Oct 2026 15:05:19 +0300 Subject: [PATCH 2/2] Address review findings on the new test and fix --- crates/lensdb/src/lib.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/crates/lensdb/src/lib.rs b/crates/lensdb/src/lib.rs index 32bfc8ee16..4fd01c7dc7 100644 --- a/crates/lensdb/src/lib.rs +++ b/crates/lensdb/src/lib.rs @@ -263,8 +263,8 @@ fn maker_matches(a: &[String], b: &[String]) -> bool { /// How well a database name matches the EXIF name, 0..1. Every number in the database name (focal lengths, /// apertures) must appear in the EXIF name and vice versa; the maker's words are ignored on both sides (EXIF -/// often omits them). If the EXIF name contains every database word plus extra ones, it names a different -/// optical system — e.g. a teleconverter suffix such as `Z TC` — not this profile. +/// often omits them). Extra EXIF words only lower the score; they name a different lens only when they mark +/// a teleconverter, a different optical system than the bare lens. fn name_score(db: &[String], exif: &[String], maker: &[String]) -> f64 { let db: Vec<&String> = db.iter().filter(|t| !maker.contains(t)).collect(); let exif: Vec<&String> = exif.iter().filter(|t| !maker.contains(t)).collect(); @@ -282,13 +282,6 @@ fn name_score(db: &[String], exif: &[String], maker: &[String]) -> f64 { if db_tc != exif_tc { return 0.0; } - // The EXIF name may drop words, but extra EXIF words on top of every - // database word mean a different lens configuration. - let db_missing = db.iter().any(|t| !exif.contains(t)); - let exif_missing = exif.iter().any(|t| !db.contains(t)); - if !db_missing && exif_missing { - return 0.0; - } let common = db.iter().filter(|t| exif.contains(t)).count() as f64; common / db.len().max(exif.len()) as f64 }