mirror of
https://git.sr.ht/~sircmpwn/hub.sr.ht
synced 2024-10-06 08:24:53 +02:00
projects.create_POST: validate name matches regex
This commit is contained in:
parent
102fca490c
commit
f29b90b8fa
1 changed files with 3 additions and 1 deletions
|
@ -1,3 +1,4 @@
|
|||
import re
|
||||
from flask import Blueprint, render_template, request, redirect, url_for
|
||||
from hubsrht.decorators import adminrequired
|
||||
from hubsrht.projects import ProjectAccess, get_project
|
||||
|
@ -77,7 +78,8 @@ def create_POST():
|
|||
visibility = valid.require("visibility", cls=Visibility)
|
||||
valid.expect(not name or len(name) < 128,
|
||||
"Name must be fewer than 128 characters", field="name")
|
||||
# TODO: Test that name passes some validity regex
|
||||
valid.expect(not name or re.match(r'^[A-Za-z._-][A-Za-z0-9._-]*$', name),
|
||||
"Name must match [A-Za-z._-][A-Za-z0-9._-]*", field="name")
|
||||
valid.expect(not name or Project.query
|
||||
.filter(Project.name == name)
|
||||
.filter(Project.owner_id == current_user.id).count() == 0,
|
||||
|
|
Loading…
Reference in a new issue