[PATCH] models: Validate Project.linkname does not contain forward slash
Thomas Bracht Laumann Jespersen
t at laumann.xyz
Sun Sep 6 22:55:48 AEST 2020
I started by creating a project that contained a forward slash
(importing patches from https://lists.sr.ht/~sircmpwn/sr.ht-dev/) and
it fails to render the "projects" main page.
The specific error reads:
NoReverseMatch at /
Reverse for 'patch-list' with keyword arguments
'{'project_id': 'foo/bar'}' not found. 1 pattern(s) tried:
['project/(?P<project_id>[^/]+)/list/$']
which appears to explicitly disallow forward slashes.
So I think it makes sense to validate that project linkname doesn't
contain forward slahes.
Signed-off-by: Thomas Bracht Laumann Jespersen <t at laumann.xyz>
---
I hard a hard time satisfying flake8, so I ended up disabling the pre-commit
hook. I also looked over the documentation for contributors and figure that if
a release note is required, just let me know then I'll add it.
.../0044_add_project_linkname_validation.py | 19 +++++++++++++++++++
patchwork/models.py | 10 +++++++++-
2 files changed, 28 insertions(+), 1 deletion(-)
create mode 100644 patchwork/migrations/0044_add_project_linkname_validation.py
diff --git a/patchwork/migrations/0044_add_project_linkname_validation.py b/patchwork/migrations/0044_add_project_linkname_validation.py
new file mode 100644
index 0000000..2fff7df
--- /dev/null
+++ b/patchwork/migrations/0044_add_project_linkname_validation.py
@@ -0,0 +1,19 @@
+# Generated by Django 3.0.10 on 2020-09-06 22:47
+
+from django.db import migrations, models
+import patchwork.models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('patchwork', '0043_merge_patch_submission'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='project',
+ name='linkname',
+ field=models.CharField(max_length=255, unique=True, validators=[patchwork.models.validate_project_linkname]),
+ ),
+ ]
diff --git a/patchwork/models.py b/patchwork/models.py
index 77ab924..9027219 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -31,6 +31,13 @@ def validate_regex_compiles(regex_string):
raise ValidationError('Invalid regular expression entered!')
+def validate_project_linkname(linkname):
+ if re.fullmatch(r'[^/]+', linkname) is None:
+ raise ValidationError(
+ 'Invalid project linkname: Value cannot contain forward slash (/)'
+ )
+
+
class Person(models.Model):
# properties
@@ -56,7 +63,8 @@ class Person(models.Model):
class Project(models.Model):
# properties
- linkname = models.CharField(max_length=255, unique=True)
+ linkname = models.CharField(max_length=255, unique=True,
+ validators=[validate_project_linkname])
name = models.CharField(max_length=255, unique=True)
listid = models.CharField(max_length=255)
listemail = models.CharField(max_length=200)
--
2.26.2
More information about the Patchwork
mailing list