MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / patchTextValidUTF8

Function patchTextValidUTF8

internal/diff/diff.go:74–90  ·  view source on GitHub ↗

patchTextValidUTF8 reports whether every text line of a patch decodes to valid UTF-8. A line is escaped, so "%FF" is the byte 0xFF once parsed; this decodes each line the way PatchFromText does, whose result is unexported.

(patchText string)

Source from the content-addressed store, hash-verified

72// valid UTF-8. A line is escaped, so "%FF" is the byte 0xFF once parsed; this
73// decodes each line the way PatchFromText does, whose result is unexported.
74func patchTextValidUTF8(patchText string) bool {
75 for _, line := range strings.Split(patchText, "\n") {
76 if line == "" {
77 continue
78 }
79 switch line[0] {
80 case ' ', '-', '+':
81 // PatchFromText ignores the error too: a malformed line decodes
82 // to "", which is valid.
83 text, _ := url.QueryUnescape(strings.ReplaceAll(line[1:], "+", "%2b"))
84 if !utf8.ValidString(text) {
85 return false
86 }
87 }
88 }
89 return true
90}
91
92// patchApply is go-diff's PatchApply with its panic returned as an error.
93func patchApply(patches []difflib.Patch, base string) (result string, applied []bool, err error) {

Callers 2

ApplyPatchFunction · 0.85

Calls

no outgoing calls

Tested by 1