(rawUrl: string)
| 99 | } |
| 100 | |
| 101 | export function splitUrlAndQuery(rawUrl: string): { |
| 102 | url: string |
| 103 | query: HttpQueryEntry[] |
| 104 | } { |
| 105 | const hashIndex = rawUrl.indexOf('#') |
| 106 | const withoutFragment |
| 107 | = hashIndex === -1 ? rawUrl : rawUrl.slice(0, hashIndex) |
| 108 | const queryIndex = withoutFragment.indexOf('?') |
| 109 | |
| 110 | if (queryIndex === -1) { |
| 111 | return { query: [], url: withoutFragment } |
| 112 | } |
| 113 | |
| 114 | const url = withoutFragment.slice(0, queryIndex) |
| 115 | const rawQuery = withoutFragment.slice(queryIndex + 1) |
| 116 | const query = rawQuery |
| 117 | .split('&') |
| 118 | .filter(Boolean) |
| 119 | .map((entry) => { |
| 120 | const separatorIndex = entry.indexOf('=') |
| 121 | const key |
| 122 | = separatorIndex === -1 ? entry : entry.slice(0, separatorIndex) |
| 123 | const value |
| 124 | = separatorIndex === -1 ? '' : entry.slice(separatorIndex + 1) |
| 125 | |
| 126 | return { |
| 127 | key: decodeQueryPart(key), |
| 128 | value: decodeQueryPart(value), |
| 129 | } |
| 130 | }) |
| 131 | |
| 132 | return { query, url } |
| 133 | } |
| 134 | |
| 135 | export function normalizeEntries<T extends HttpHeaderEntry | HttpQueryEntry>( |
| 136 | entries: T[], |
no test coverage detected