diff --git a/src/ga4gh/vrs/extras/translator.py b/src/ga4gh/vrs/extras/translator.py index b10b62b6..2f385561 100644 --- a/src/ga4gh/vrs/extras/translator.py +++ b/src/ga4gh/vrs/extras/translator.py @@ -257,7 +257,7 @@ def _from_beacon(self, beacon_expr: str, **kwargs) -> models.Allele | None: if not isinstance(beacon_expr, str): return None - m = self.beacon_re.match(beacon_expr.replace(" ", "")) + m = self.beacon_re.fullmatch(beacon_expr.replace(" ", "")) if not m: return None @@ -321,7 +321,7 @@ def _from_gnomad(self, gnomad_expr: str, **kwargs) -> models.Allele | None: """ if not isinstance(gnomad_expr, str): return None - m = self.gnomad_re.match(gnomad_expr) + m = self.gnomad_re.fullmatch(gnomad_expr) if not m: return None @@ -395,7 +395,7 @@ def _from_spdi(self, spdi_expr: str, **kwargs) -> models.Allele | None: if not isinstance(spdi_expr, str): return None - m = self.spdi_re.match(spdi_expr) + m = self.spdi_re.fullmatch(spdi_expr) if not m: return None diff --git a/tests/extras/test_allele_translator.py b/tests/extras/test_allele_translator.py index 02f0d56c..dda62972 100644 --- a/tests/extras/test_allele_translator.py +++ b/tests/extras/test_allele_translator.py @@ -337,6 +337,22 @@ def test_from_invalid(tlr): tlr.translate_from("BRAF amplication", assembly_name="GRCh37") +@pytest.mark.parametrize( + ("expr", "fmt"), + [ + # multi-allelic gnomAD-style input must not be truncated to its first ALT + ("1-55516888-G-GA,GT", "gnomad"), + ("19-44908822-C-T;foo", "gnomad"), + ("NC_000019.10:44908821:1:T:extra", "spdi"), + ("19 : 44908822 C > T,G", "beacon"), + ], +) +def test_from_trailing_input_rejected(tlr, expr, fmt): + """Expressions with trailing content must be rejected, not partially parsed""" + with pytest.raises(ValueError, match=f"Unable to parse data as {fmt}"): + tlr.translate_from(expr, fmt=fmt) + + @pytest.mark.vcr def test_from_beacon(tlr): do_normalize = False