Skip to content

Commit c889856

Browse files
committed
Added a validator to Document.title to prevent control chars in the title (complementing a recent cleanup of more than 120 instances of document titles containing vertical tabs)
- Legacy-Id: 12893
1 parent 858d855 commit c889856

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

ietf/doc/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
DocRelationshipName, DocReminderTypeName, BallotPositionName, ReviewRequestStateName )
1919
from ietf.person.models import Email, Person
2020
from ietf.utils.admin import admin_link
21-
21+
from ietf.utils.validators import validate_no_control_chars
2222

2323
class StateType(models.Model):
2424
slug = models.CharField(primary_key=True, max_length=30) # draft, draft-iesg, charter, ...
@@ -65,7 +65,7 @@ class DocumentInfo(models.Model):
6565
time = models.DateTimeField(default=datetime.datetime.now) # should probably have auto_now=True
6666

6767
type = models.ForeignKey(DocTypeName, blank=True, null=True) # Draft, Agenda, Minutes, Charter, Discuss, Guideline, Email, Review, Issue, Wiki, External ...
68-
title = models.CharField(max_length=255)
68+
title = models.CharField(max_length=255, validators=[validate_no_control_chars, ])
6969

7070
states = models.ManyToManyField(State, blank=True) # plain state (Active/Expired/...), IESG state, stream state
7171
tags = models.ManyToManyField(DocTagName, blank=True) # Revised ID Needed, ExternalParty, AD Followup, ...

ietf/utils/validators.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,19 @@
55
import re
66

77
from django.core.exceptions import ValidationError
8+
from django.core.validators import RegexValidator
89
from django.utils.deconstruct import deconstructible
910

11+
# Note that this is an instantiation of the regex validator, _not_ the
12+
# regex-string validator defined right below
13+
validate_no_control_chars = RegexValidator(
14+
regex="^[^\x00-\x1f]*$",
15+
message="Please enter a string without control characters." )
16+
17+
1018
@deconstructible
1119
class RegexStringValidator(object):
20+
"Validates that a given regular expression can be compiled."
1221

1322
def __init__(self):
1423
pass
@@ -36,3 +45,4 @@ def __ne__(self, other):
3645
return not (self == other)
3746

3847
validate_regular_expression_string = RegexStringValidator()
48+

0 commit comments

Comments
 (0)