(params: URLSearchParams)
| 176 | }; |
| 177 | |
| 178 | export const getRedirectNextPath = (params: URLSearchParams): string => { |
| 179 | const next = params.get('next'); |
| 180 | |
| 181 | let nextPath = '/'; |
| 182 | |
| 183 | if (next) { |
| 184 | try { |
| 185 | const nextUrl = new URL(next, 'http://localhost'); |
| 186 | // infinite redirect loop prevention |
| 187 | nextUrl.searchParams.delete('next'); |
| 188 | |
| 189 | // we ignore url origin since we don't allow cross-origin redirects |
| 190 | nextPath = getPathnameWithQuery(nextUrl.pathname, nextUrl.searchParams); |
| 191 | } catch (error) { |
| 192 | // eslint-disable-next-line no-console |
| 193 | console.error(error); |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | return checkIsExtension() ? `${webappUrl}${nextPath}` : nextPath; |
| 198 | }; |
| 199 | |
| 200 | /* A function, not a constant: `webappUrl` comes from the environment, and a |
| 201 | module-level template literal captures it before a test can set it. */ |
no test coverage detected