parseIndices filters out invalid and duplicate blob indices
(r *http.Request, max int)
| 99 | |
| 100 | // parseIndices filters out invalid and duplicate blob indices |
| 101 | func parseIndices(r *http.Request, max int) ([]uint64, *httpError) { |
| 102 | query := r.URL.Query() |
| 103 | normalizeQueryValues(query) |
| 104 | r.URL.RawQuery = query.Encode() |
| 105 | rawIndices := r.URL.Query()["indices"] |
| 106 | indices := make([]uint64, 0, max) |
| 107 | invalidIndices := make([]string, 0) |
| 108 | loop: |
| 109 | for _, raw := range rawIndices { |
| 110 | ix, err := strconv.ParseUint(raw, 10, 64) |
| 111 | if err != nil { |
| 112 | invalidIndices = append(invalidIndices, raw) |
| 113 | continue |
| 114 | } |
| 115 | if max > 0 && ix >= uint64(max) { |
| 116 | invalidIndices = append(invalidIndices, raw) |
| 117 | continue |
| 118 | } |
| 119 | for i := range indices { |
| 120 | if ix == indices[i] { |
| 121 | continue loop |
| 122 | } |
| 123 | } |
| 124 | indices = append(indices, ix) |
| 125 | } |
| 126 | |
| 127 | if len(invalidIndices) > 0 { |
| 128 | return nil, newBadRequestError(fmt.Sprintf("requested blob indices %v are invalid", invalidIndices)) |
| 129 | } |
| 130 | return indices, nil |
| 131 | } |
| 132 | |
| 133 | // normalizeQueryValues replaces comma-separated values with individual values |
| 134 | func normalizeQueryValues(queryParams url.Values) { |