Prevent duplicate groups in reference format fields (#4291)

This commit is contained in:
Oliver 2023-02-02 11:32:47 +11:00 committed by GitHub
parent 4f029d4d81
commit df4209801a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -16,11 +16,21 @@ def parse_format_string(fmt_string: str) -> dict:
info = {}
seen_groups = set()
for group in groups:
# Skip any group which does not have a named value
if not group[1]:
continue
name = group[1]
# Check for duplicate named groups
if name in seen_groups:
raise ValueError(f"Duplicate group '{name}'")
else:
seen_groups.add(name)
info[group[1]] = {
'format': group[1],
'prefix': group[0],

View File

@ -233,9 +233,9 @@ class ReferenceIndexingMixin(models.Model):
try:
info = InvenTree.format.parse_format_string(pattern)
except Exception:
except Exception as exc:
raise ValidationError({
"value": _("Improperly formatted pattern"),
"value": _("Improperly formatted pattern") + ": " + str(exc)
})
# Check that only 'allowed' keys are provided