From 58c74b208c4cfe97b7c103910926ef9350449047 Mon Sep 17 00:00:00 2001 From: Arthur Date: Fri, 12 May 2023 09:27:59 -0700 Subject: [PATCH] 12468 use inverse match --- .../extras/migrations/0066_customfield_name_validation.py | 3 ++- netbox/extras/models/customfields.py | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/netbox/extras/migrations/0066_customfield_name_validation.py b/netbox/extras/migrations/0066_customfield_name_validation.py index c61fcf983..fe187d525 100644 --- a/netbox/extras/migrations/0066_customfield_name_validation.py +++ b/netbox/extras/migrations/0066_customfield_name_validation.py @@ -24,8 +24,9 @@ class Migration(migrations.Migration): ), django.core.validators.RegexValidator( flags=re.RegexFlag['IGNORECASE'], + inverse_match=True, message='No double-underscores are allowed.', - regex='^(?!.*__.*)', + regex=r'__', ), ], ), diff --git a/netbox/extras/models/customfields.py b/netbox/extras/models/customfields.py index c951a5675..8fd07ec33 100644 --- a/netbox/extras/models/customfields.py +++ b/netbox/extras/models/customfields.py @@ -75,6 +75,7 @@ class CustomField(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel): null=True, help_text=_('The type of NetBox object this field maps to (for object fields)') ) + # regex=r'^(?!.*__.*)', ^((?!__).)*$ name = models.CharField( max_length=50, unique=True, @@ -86,9 +87,10 @@ class CustomField(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel): flags=re.IGNORECASE ), RegexValidator( - regex=r'^(?!.*__.*)', + regex=r'__', message="No double-underscores are allowed.", - flags=re.IGNORECASE + flags=re.IGNORECASE, + inverse_match=True ), ) )