ParseRawQuery returns a slice of QueryItems extracted from the raw query string. The parsed QueryItems preserve escaping of key and values. All + escape characters are replaced with %20 for consistent escaping pattern.
(rawQuery string)
| 116 | // All + escape characters are replaced with %20 for consistent escaping |
| 117 | // pattern. |
| 118 | func ParseRawQuery(rawQuery string) (items []QueryItem) { |
| 119 | for _, item := range strings.Split(rawQuery, `&`) { |
| 120 | parts := strings.SplitN(item, `=`, 2) |
| 121 | var value string |
| 122 | if len(parts) > 1 { |
| 123 | value = parts[1] |
| 124 | } |
| 125 | items = append(items, QueryItem{ |
| 126 | // Go Query encoder escapes space as `+` whereas smithy protocol |
| 127 | // tests expect `%20`. |
| 128 | Key: strings.ReplaceAll(parts[0], `+`, `%20`), |
| 129 | Value: strings.ReplaceAll(value, `+`, `%20`), |
| 130 | }) |
| 131 | } |
| 132 | return items |
| 133 | } |
| 134 | |
| 135 | // HasQuery validates that the expected set of query items are present in |
| 136 | // the actual set. Returns an error if any of the expected set are not found in |