validateTextContent returns an error if content is not valid UTF-8 or contains a null byte.
(content []byte)
| 80 | |
| 81 | // validateTextContent returns an error if content is not valid UTF-8 or contains a null byte. |
| 82 | func (p *FetchPlugin) validateTextContent(content []byte) error { |
| 83 | debugf("Fetch: validating content length=%d bytes", len(content)) |
| 84 | |
| 85 | if !utf8.Valid(content) { |
| 86 | return errors.New(i18n.T("fetch_content_not_utf8")) |
| 87 | } |
| 88 | |
| 89 | if bytes.Contains(content, []byte{0}) { |
| 90 | return errors.New(i18n.T("fetch_content_null_bytes")) |
| 91 | } |
| 92 | |
| 93 | debugf("Fetch: content validation successful") |
| 94 | return nil |
| 95 | } |
| 96 | |
| 97 | // fetch downloads urlStr and applies the size, content-type, and UTF-8 checks. |
| 98 | func (p *FetchPlugin) fetch(urlStr string) (string, error) { |