{"record":{"id":"6c398def14e91207","repo":"larksuite/cli","slug":"json-pointer-q-segment-q-w","errorCode":null,"errorMessage":"json pointer %q: segment %q: %w","messagePattern":"json pointer %q: segment %q: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/binding/json_pointer.go","lineNumber":38,"sourceCode":"// SecretRef file provider uses object-only paths in practice.\nfunc ReadJSONPointer(data interface{}, pointer string) (interface{}, error) {\n\tif pointer == \"\" {\n\t\treturn data, nil\n\t}\n\n\tif !strings.HasPrefix(pointer, \"/\") {\n\t\treturn nil, fmt.Errorf(\"json pointer must start with '/' or be empty, got %q\", pointer)\n\t}\n\n\t// Split after the leading \"/\" and decode each segment.\n\tsegments := strings.Split(pointer[1:], \"/\")\n\tcurrent := data\n\n\tfor i, raw := range segments {\n\t\t// RFC 6901 unescaping: ~1 → /, ~0 → ~ (order matters).\n\t\tkey, err := decodeJSONPointerSegment(raw)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"json pointer %q: segment %q: %w\", pointer, raw, err)\n\t\t}\n\n\t\tm, ok := current.(map[string]interface{})\n\t\tif !ok {\n\t\t\ttraversed := \"/\" + strings.Join(segments[:i], \"/\")\n\t\t\treturn nil, fmt.Errorf(\"json pointer %q: value at %q is %T, not an object\",\n\t\t\t\tpointer, traversed, current)\n\t\t}\n\n\t\tval, exists := m[key]\n\t\tif !exists {\n\t\t\treturn nil, fmt.Errorf(\"json pointer %q: key %q not found\", pointer, key)\n\t\t}\n\n\t\tcurrent = val\n\t}\n\n\treturn current, nil","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/binding/json_pointer.go#L20-L56","documentation":"While walking the pointer, each segment is unescaped per RFC 6901 (~1 → '/', ~0 → '~') by decodeJSONPointerSegment. If a segment contains a malformed '~' escape, the traversal aborts and wraps that segment error with the full pointer and the offending segment.","triggerScenarios":"Pointer contains '~' not followed by 0 or 1 (or a trailing '~'), e.g. \"/data/~2/key\" or \"/data/~\".","commonSituations":"Keys that literally contain '~' were not escaped as '~0'; hand-written pointers guessing at the escape syntax; templated paths where a '~' home-dir token leaked into the pointer.","solutions":["Replace invalid escapes: use ~0 for a literal '~' and ~1 for a literal '/'","Remove stray '~' characters or escape them (~0)","Check the segment at the index reported in the error string"],"exampleFix":"// before\nReadJSONPointer(data, \"/path~2to/key\")\n// after\nReadJSONPointer(data, \"/path~0to/key\")","handlingStrategy":"validation","validationCode":"if strings.Contains(ptr, \"~\") && !regexp.MustCompile(`~[01]`).MatchString(ptr) {\n    return errors.New(\"pointer contains invalid ~ escape\")\n}","typeGuard":null,"tryCatchPattern":"val, err := binding.ReadJSONPointer(data, ptr)\nif err != nil && strings.Contains(err.Error(), \"invalid escape\") {\n    ptr = strings.ReplaceAll(ptr, \"~\", \"~0\") // re-escape and retry\n    val, err = binding.ReadJSONPointer(data, ptr)\n}","preventionTips":["Escape literal '~' as ~0 and '/' as ~1 in key names","Reject or sanitize keys containing '~' when building pointers programmatically"],"tags":["json","rfc6901","escaping"],"backgroundTag":"invalid-json-pointer","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}