Validate cookie policy link in banner description
Translations are no longer part of the version snapshot, so the
banner_description text must be validated at write time to ensure
the {{cookie_policy_link}} placeholder is present. Without it
the cookie policy URL silently disappears from the rendered banner.
Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -328,7 +328,12 @@ func (r *UpsertCookieBannerTranslationRequest) Validate() error {
|
||||
if json.Unmarshal(raw, &s) != nil {
|
||||
continue
|
||||
}
|
||||
v.Check(s, "translations."+key, validator.NoHTML(), validator.MaxLen(2000))
|
||||
|
||||
validators := []validator.ValidatorFunc{validator.NoHTML(), validator.MaxLen(2000)}
|
||||
if key == "banner_description" {
|
||||
validators = append(validators, validator.ContainsSubstring("{{cookie_policy_link}}"))
|
||||
}
|
||||
v.Check(s, "translations."+key, validators...)
|
||||
}
|
||||
|
||||
return v.Error()
|
||||
|
||||
Reference in New Issue
Block a user