From b5f88d017762716748eb74465008bc0995649467 Mon Sep 17 00:00:00 2001 From: Alex Maldonado Date: Sun, 18 Oct 2026 18:22:26 -0400 Subject: [PATCH] Match data identities and dataset IDs whole The patterns were anchored with ^ and $ and matched with match(); in Python $ also accepts a line break at the end, so 'ds-x' followed by a newline passed layer.data.dataset where an ECMAScript regex would refuse it. Use fullmatch() on unanchored patterns. No vector changes. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01B8cL4zN4XpaQF5cBtASzfq --- src/paperspec/data.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/paperspec/data.py b/src/paperspec/data.py index 0cf3928..8343999 100644 --- a/src/paperspec/data.py +++ b/src/paperspec/data.py @@ -31,11 +31,12 @@ DATA_TYPES = { """The kinds of data a body can name, with what each covers.""" ROLES = ("reports", "uses") SUBJECT_KINDS = { - "structure": re.compile(r"^([A-Z]{14}-[A-Z]{10}-[A-Z]|(smiles|smarts):[0-9a-f]{12})$"), - "sequence": re.compile(r"^(protein|dna|rna):[0-9a-f]{16}$"), + "structure": re.compile(r"([A-Z]{14}-[A-Z]{10}-[A-Z]|(smiles|smarts):[0-9a-f]{12})"), + "sequence": re.compile(r"(protein|dna|rna):[0-9a-f]{16}"), } -"""The form of a subject's identity for each kind, the forms of a `structure` and a `sequence` body's identity.""" -DATASET_ID = re.compile(r"^ds-[a-z0-9][a-z0-9._-]*$") +"""The form of a subject's identity for each kind, the forms of a `structure` and a `sequence` body's identity. Matched +whole: `$` would also accept a line break at the end.""" +DATASET_ID = re.compile(r"ds-[a-z0-9][a-z0-9._-]*") def problems(annotation, dataset=None): @@ -69,13 +70,13 @@ def problems(annotation, dataset=None): form = SUBJECT_KINDS.get(kind) if form is None: add("layer.data.subject", "subject %d is of a kind that is not %s" % (k, " or ".join(SUBJECT_KINDS))) - elif not form.match(ident): + elif not form.fullmatch(ident): add("layer.data.subject", "subject %d: %s is not the form of a %s identity" % (k, ident, kind)) if (kind, ident) in seen: add("layer.data.subject", "subject %d repeats the %s %s" % (k, kind, ident)) seen.add((kind, ident)) ds = body.get("dataset") - if ds is not None and not DATASET_ID.match(ds): + if ds is not None and not DATASET_ID.fullmatch(ds): add("layer.data.dataset", "%s is not the ID of a dataset" % ds) if dataset is not None and ds is not None: if dataset.get("id") != ds: