(ref string, rootPath *url.URL, element any)
| 112 | } |
| 113 | |
| 114 | func (loader *Loader) loadSingleElementFromURI(ref string, rootPath *url.URL, element any) (*url.URL, error) { |
| 115 | // IsExternalRefsAllowed is enforced here only when no custom ReadFromURIFunc |
| 116 | // is installed; otherwise the custom func owns the access policy (see the |
| 117 | // SECURITY note on the ReadFromURIFunc field). |
| 118 | if loader.ReadFromURIFunc == nil { |
| 119 | if err := loader.allowsExternalRefs(ref); err != nil { |
| 120 | return nil, err |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | resolvedPath, err := loader.resolvePathWithRef(ref, rootPath) |
| 125 | if err != nil { |
| 126 | return nil, err |
| 127 | } |
| 128 | if frag := resolvedPath.Fragment; frag != "" { |
| 129 | return nil, fmt.Errorf("unexpected ref fragment %q", frag) |
| 130 | } |
| 131 | |
| 132 | data, err := loader.readURL(resolvedPath) |
| 133 | if err != nil { |
| 134 | return nil, err |
| 135 | } |
| 136 | if err := unmarshal(data, element, loader.IncludeOrigin, resolvedPath); err != nil { |
| 137 | return nil, err |
| 138 | } |
| 139 | |
| 140 | return resolvedPath, nil |
| 141 | } |
| 142 | |
| 143 | func (loader *Loader) readURL(location *url.URL) ([]byte, error) { |
| 144 | if f := loader.ReadFromURIFunc; f != nil { |
no test coverage detected