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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B8cL4zN4XpaQF5cBtASzfq
This commit is contained in:
1 file changed
+7
-6
@@ -31,11 +31,12 @@ DATA_TYPES = {
|
|||||||
"""The kinds of data a body can name, with what each covers."""
|
"""The kinds of data a body can name, with what each covers."""
|
||||||
ROLES = ("reports", "uses")
|
ROLES = ("reports", "uses")
|
||||||
SUBJECT_KINDS = {
|
SUBJECT_KINDS = {
|
||||||
"structure": re.compile(r"^([A-Z]{14}-[A-Z]{10}-[A-Z]|(smiles|smarts):[0-9a-f]{12})$"),
|
"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}$"),
|
"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."""
|
"""The form of a subject's identity for each kind, the forms of a `structure` and a `sequence` body's identity. Matched
|
||||||
DATASET_ID = re.compile(r"^ds-[a-z0-9][a-z0-9._-]*$")
|
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):
|
def problems(annotation, dataset=None):
|
||||||
@@ -69,13 +70,13 @@ def problems(annotation, dataset=None):
|
|||||||
form = SUBJECT_KINDS.get(kind)
|
form = SUBJECT_KINDS.get(kind)
|
||||||
if form is None:
|
if form is None:
|
||||||
add("layer.data.subject", "subject %d is of a kind that is not %s" % (k, " or ".join(SUBJECT_KINDS)))
|
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))
|
add("layer.data.subject", "subject %d: %s is not the form of a %s identity" % (k, ident, kind))
|
||||||
if (kind, ident) in seen:
|
if (kind, ident) in seen:
|
||||||
add("layer.data.subject", "subject %d repeats the %s %s" % (k, kind, ident))
|
add("layer.data.subject", "subject %d repeats the %s %s" % (k, kind, ident))
|
||||||
seen.add((kind, ident))
|
seen.add((kind, ident))
|
||||||
ds = body.get("dataset")
|
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)
|
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 is not None and ds is not None:
|
||||||
if dataset.get("id") != ds:
|
if dataset.get("id") != ds:
|
||||||
|
|||||||
Reference in new issue
Block a user