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

Function isJSONEncodedFieldKey

internal/server/middleware_request_text.go:790–806  ·  view source on GitHub ↗

isJSONEncodedFieldKey matches a wire key the way the DECODER that consumes it does: case-insensitively. encoding/json matches an incoming key to a struct field by an exact match first and a CASE-INSENSITIVE one otherwise, so `{"Fields":...}` and `{"FIELDS":...}` both land in ItemCreate.Fields. A ca

(k string)

Source from the content-addressed store, hash-verified

788// rather than a bare map index: the map is the vocabulary, the MATCHING RULE
789// belongs to the consumer.
790func isJSONEncodedFieldKey(k string) bool {
791 if jsonEncodedFieldKeys[k] {
792 return true
793 }
794 // EqualFold, not ToLower. encoding/json matches with Unicode SIMPLE
795 // FOLDING, which is wider than lower-casing: U+017F LATIN SMALL LETTER
796 // LONG S folds to 's', so "ſchema" reaches the `schema` field while
797 // strings.ToLower("ſchema") is still "ſchema" and missed the allowlist.
798 // Fixing the ASCII half and leaving the Unicode half
799 // would have been this bug's own pattern one more time.
800 for canonical := range jsonEncodedFieldKeys {
801 if strings.EqualFold(k, canonical) {
802 return true
803 }
804 }
805 return false
806}
807
808// nestedDocumentDecodesNUL walks a JSON document carried as a string — an
809// item's `fields` blob, a collection's `schema` — for a string containing a

Callers 3

repairDecodedNULsFunction · 0.85
encodedFieldKeyFunction · 0.85
mapModelDecodesNULFunction · 0.85

Calls

no outgoing calls

Tested by 1

mapModelDecodesNULFunction · 0.68