mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-01-24 22:32:42 +02:00
added custom insertion id regex check
This commit is contained in:
parent
ff935a39a1
commit
147344546b
@ -74,6 +74,7 @@ func (form *AdminUpsert) Validate() error {
|
||||
validation.When(
|
||||
form.admin.IsNew(),
|
||||
validation.Length(models.DefaultIdLength, models.DefaultIdLength),
|
||||
validation.Match(idRegex),
|
||||
).Else(validation.In(form.admin.Id)),
|
||||
),
|
||||
validation.Field(
|
||||
|
@ -412,7 +412,13 @@ func TestAdminUpsertWithCustomId(t *testing.T) {
|
||||
true,
|
||||
},
|
||||
{
|
||||
"id = 15 chars",
|
||||
"id = 15 chars (invalid chars)",
|
||||
`{"id":"a@3456789012345"}`,
|
||||
&models.Admin{},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"id = 15 chars (valid chars)",
|
||||
`{"id":"a23456789012345"}`,
|
||||
&models.Admin{},
|
||||
false,
|
||||
|
@ -2,6 +2,11 @@
|
||||
// validation and applying changes to existing DB models through the app Dao.
|
||||
package forms
|
||||
|
||||
import "regexp"
|
||||
|
||||
// base ID value regex pattern
|
||||
var idRegex = regexp.MustCompile(`^[^\@\#\$\&\|\.\,\'\"\\\/\s]+$`)
|
||||
|
||||
// InterceptorNextFunc is a interceptor handler function.
|
||||
// Usually used in combination with InterceptorFunc.
|
||||
type InterceptorNextFunc = func() error
|
||||
|
@ -97,6 +97,7 @@ func (form *CollectionUpsert) Validate() error {
|
||||
validation.When(
|
||||
form.collection.IsNew(),
|
||||
validation.Length(models.DefaultIdLength, models.DefaultIdLength),
|
||||
validation.Match(idRegex),
|
||||
).Else(validation.In(form.collection.Id)),
|
||||
),
|
||||
validation.Field(
|
||||
|
@ -590,7 +590,13 @@ func TestCollectionUpsertWithCustomId(t *testing.T) {
|
||||
true,
|
||||
},
|
||||
{
|
||||
"id = 15 chars",
|
||||
"id = 15 chars (invalid chars)",
|
||||
`{"id":"a@3456789012345"}`,
|
||||
newCollection(),
|
||||
true,
|
||||
},
|
||||
{
|
||||
"id = 15 chars (valid chars)",
|
||||
`{"id":"a23456789012345"}`,
|
||||
newCollection(),
|
||||
false,
|
||||
|
@ -276,6 +276,7 @@ func (form *RecordUpsert) Validate() error {
|
||||
validation.When(
|
||||
form.record.IsNew(),
|
||||
validation.Length(models.DefaultIdLength, models.DefaultIdLength),
|
||||
validation.Match(idRegex),
|
||||
).Else(validation.In(form.record.Id)),
|
||||
),
|
||||
)
|
||||
|
@ -653,7 +653,13 @@ func TestRecordUpsertWithCustomId(t *testing.T) {
|
||||
true,
|
||||
},
|
||||
{
|
||||
"id = 15 chars",
|
||||
"id = 15 chars (invalid chars)",
|
||||
map[string]string{"id": "a@3456789012345"},
|
||||
models.NewRecord(collection),
|
||||
true,
|
||||
},
|
||||
{
|
||||
"id = 15 chars (valid chars)",
|
||||
map[string]string{"id": "a23456789012345"},
|
||||
models.NewRecord(collection),
|
||||
false,
|
||||
|
@ -76,6 +76,7 @@ func (form *UserUpsert) Validate() error {
|
||||
validation.When(
|
||||
form.user.IsNew(),
|
||||
validation.Length(models.DefaultIdLength, models.DefaultIdLength),
|
||||
validation.Match(idRegex),
|
||||
).Else(validation.In(form.user.Id)),
|
||||
),
|
||||
validation.Field(
|
||||
|
@ -369,7 +369,13 @@ func TestUserUpsertWithCustomId(t *testing.T) {
|
||||
true,
|
||||
},
|
||||
{
|
||||
"id = 15 chars",
|
||||
"id = 15 chars (invalid chars)",
|
||||
`{"id":"a@3456789012345"}`,
|
||||
&models.User{},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"id = 15 chars (valid chars)",
|
||||
`{"id":"a23456789012345"}`,
|
||||
&models.User{},
|
||||
false,
|
||||
|
Loading…
x
Reference in New Issue
Block a user