|
7 | 7 | "fmt"
|
8 | 8 | "strings"
|
9 | 9 |
|
10 |
| - "go4.org/bytereplacer" |
11 |
| - |
12 | 10 | "github.com/operator-framework/operator-registry/alpha/property"
|
13 | 11 | )
|
14 | 12 |
|
@@ -100,25 +98,27 @@ func (m Meta) MarshalJSON() ([]byte, error) {
|
100 | 98 | }
|
101 | 99 |
|
102 | 100 | func (m *Meta) UnmarshalJSON(blob []byte) error {
|
103 |
| - blob = bytereplacer.New(`\u003c`, "<", `\u003e`, ">", `\u0026`, "&").Replace(blob) |
104 |
| - |
105 |
| - type tmp struct { |
106 |
| - Schema string `json:"schema"` |
107 |
| - Package string `json:"package,omitempty"` |
108 |
| - Name string `json:"name,omitempty"` |
109 |
| - Properties []property.Property `json:"properties,omitempty"` |
| 101 | + blobMap := map[string]interface{}{} |
| 102 | + if err := json.Unmarshal(blob, &blobMap); err != nil { |
| 103 | + return err |
| 104 | + } |
| 105 | + for key, ptr := range map[string]*string{"schema": &m.Schema, "package": &m.Package, "name": &m.Name} { |
| 106 | + if _, ok := blobMap[key]; !ok { |
| 107 | + continue |
| 108 | + } |
| 109 | + v, ok := blobMap[key].(string) |
| 110 | + if !ok { |
| 111 | + return fmt.Errorf("expected value for key %q to be a string, got %t: %v", key, blobMap[key], blobMap[key]) |
| 112 | + } |
| 113 | + *ptr = v |
110 | 114 | }
|
111 |
| - var t tmp |
112 |
| - if err := json.Unmarshal(blob, &t); err != nil { |
113 |
| - // TODO: return an error that includes the the full JSON message, |
114 |
| - // the offset of the error, and the error message. Let callers |
115 |
| - // decide how to format it. |
116 |
| - return errors.New(resolveUnmarshalErr(blob, err)) |
| 115 | + buf := bytes.Buffer{} |
| 116 | + enc := json.NewEncoder(&buf) |
| 117 | + enc.SetEscapeHTML(false) |
| 118 | + if err := enc.Encode(blobMap); err != nil { |
| 119 | + return err |
117 | 120 | }
|
118 |
| - m.Schema = t.Schema |
119 |
| - m.Package = t.Package |
120 |
| - m.Name = t.Name |
121 |
| - m.Blob = blob |
| 121 | + m.Blob = buf.Bytes() |
122 | 122 | return nil
|
123 | 123 | }
|
124 | 124 |
|
|
0 commit comments