From 71b1f13a799c66303e2a7e8426036f7748a643a6 Mon Sep 17 00:00:00 2001
From: Russ Housley <housley@vigilsec.com>
Date: Sun, 20 Mar 2022 07:59:29 -0400
Subject: [PATCH] fix: improfe draft name syntax checks (#3703)

* fix: Include blocked charters in AD dashboard that are ub external review

* fix: Improve draft name syntax checks. Fixes #3677
---
 ietf/doc/views_search.py |  4 ++++
 ietf/submit/forms.py     | 10 +++-------
 ietf/submit/utils.py     |  6 ++++++
 3 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/ietf/doc/views_search.py b/ietf/doc/views_search.py
index 9524fd43e..4685af62d 100644
--- a/ietf/doc/views_search.py
+++ b/ietf/doc/views_search.py
@@ -447,6 +447,10 @@ def docs_for_ad(request, name):
         if blocked_docs:
             blocked_docs.sort(key=lambda d: min(p.time for p in d.blocking_positions if p.balloter==ad), reverse=True)
 
+        for d in blocked_docs:
+           if d.get_base_name() == 'charter-ietf-shmoo-01-04.txt':
+              print('Is in list')
+
     return render(request, 'doc/drafts_for_ad.html', {
         'form':form, 'docs':results, 'meta':meta, 'ad_name': ad.plain_name(), 'blocked_docs': blocked_docs
     })
diff --git a/ietf/submit/forms.py b/ietf/submit/forms.py
index a96f07644..1daf341f8 100644
--- a/ietf/submit/forms.py
+++ b/ietf/submit/forms.py
@@ -567,19 +567,15 @@ class PreapprovalForm(forms.Form):
 
     def clean_name(self):
         n = self.cleaned_data['name'].strip().lower()
-
-        if not n.startswith("draft-"):
-            raise forms.ValidationError("Name doesn't start with \"draft-\".")
-        if len(n.split(".")) > 1 and len(n.split(".")[-1]) == 3:
-            raise forms.ValidationError("Name appears to end with a file extension .%s - do not include an extension." % n.split(".")[-1])
+        error_msg = validate_submission_name(n)
+        if error_msg:
+            raise forms.ValidationError(error_msg)
 
         components = n.split("-")
         if components[-1] == "00":
             raise forms.ValidationError("Name appears to end with a revision number -00 - do not include the revision.")
         if len(components) < 4:
             raise forms.ValidationError("Name has less than four dash-delimited components - can't form a valid group draft name.")
-        if not components[-1]:
-            raise forms.ValidationError("Name ends with a dash.")
         acronym = components[2]
         if acronym not in [ g.acronym for g in self.groups ]:
             raise forms.ValidationError("Group acronym not recognized as one you can approve drafts for.")
diff --git a/ietf/submit/utils.py b/ietf/submit/utils.py
index f3f21e4fd..74874348e 100644
--- a/ietf/submit/utils.py
+++ b/ietf/submit/utils.py
@@ -127,6 +127,12 @@ def validate_submission_name(name):
             return msg
     return None
 
+    components = name.split('-')
+    if '' in components:
+        return "Name contains adjacent dashes or the name ends with a dash."
+    if len(components) < 3:
+        return "Name has less than three dash-delimited components in the name."
+
 def validate_submission_rev(name, rev):
     if not rev:
         return 'Revision not found'