MCPcopy Create free account
hub / github.com/danielmiessler/Fabric / validateTextContent

Method validateTextContent

internal/plugins/template/fetch.go:82–95  ·  view source on GitHub ↗

validateTextContent returns an error if content is not valid UTF-8 or contains a null byte.

(content []byte)

Source from the content-addressed store, hash-verified

80
81// validateTextContent returns an error if content is not valid UTF-8 or contains a null byte.
82func (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.
98func (p *FetchPlugin) fetch(urlStr string) (string, error) {

Callers 1

fetchMethod · 0.95

Calls 2

TFunction · 0.92
debugfFunction · 0.85

Tested by

no test coverage detected