| 138 | } |
| 139 | |
| 140 | func Sanitizer(fl validator.FieldLevel) (res bool) { |
| 141 | field := fl.Field() |
| 142 | switch field.Kind() { |
| 143 | case reflect.String: |
| 144 | filter := bluemonday.UGCPolicy() |
| 145 | content := strings.ReplaceAll(filter.Sanitize(field.String()), "&", "&") |
| 146 | field.SetString(content) |
| 147 | return true |
| 148 | case reflect.Chan, reflect.Map, reflect.Slice, reflect.Array: |
| 149 | return field.Len() > 0 |
| 150 | case reflect.Ptr, reflect.Interface, reflect.Func: |
| 151 | return !field.IsNil() |
| 152 | default: |
| 153 | return field.IsValid() && field.Interface() != reflect.Zero(field.Type()).Interface() |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | func createDefaultValidator(la i18n.Language) *validator.Validate { |
| 158 | validate := validator.New() |