mirror of
https://github.com/writefreely/writefreely
synced 2024-11-10 11:24:13 +00:00
Validate and trim spaces on WM pointer
Ref T773
This commit is contained in:
parent
ec7b299fd3
commit
13a3a68d54
1 changed files with 18 additions and 4 deletions
14
database.go
14
database.go
|
@ -907,12 +907,26 @@ func (db *datastore) UpdateCollection(c *SubmittedCollection, alias string) erro
|
|||
|
||||
// Update Monetization value
|
||||
if c.Monetization != nil {
|
||||
skipUpdate := false
|
||||
if *c.Monetization != "" {
|
||||
// Strip away any excess spaces
|
||||
trimmed := strings.TrimSpace(*c.Monetization)
|
||||
// Only update value when it starts with "$", per spec: https://paymentpointers.org
|
||||
if strings.HasPrefix(trimmed, "$") {
|
||||
c.Monetization = &trimmed
|
||||
} else {
|
||||
// Value appears invalid, so don't update
|
||||
skipUpdate = true
|
||||
}
|
||||
}
|
||||
if !skipUpdate {
|
||||
_, err = db.Exec("INSERT INTO collectionattributes (collection_id, attribute, value) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE value = ?", collID, "monetization_pointer", *c.Monetization, *c.Monetization)
|
||||
if err != nil {
|
||||
log.Error("Unable to insert monetization_pointer value: %v", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update rest of the collection data
|
||||
res, err = db.Exec("UPDATE collections SET "+q.Updates+" WHERE "+q.Conditions, q.Params...)
|
||||
|
|
Loading…
Reference in a new issue