(
{ returnTo, origin, pathPrefix }: Partial<RedirectParams>,
_homeLocation = HOME_LOCATION
)
| 55 | * @returns The normalized parameters. |
| 56 | */ |
| 57 | export function normalizeParams( |
| 58 | { returnTo, origin, pathPrefix }: Partial<RedirectParams>, |
| 59 | _homeLocation = HOME_LOCATION |
| 60 | ): RedirectParams { |
| 61 | // coerce to strings, just in case something weird and nefarious is happening |
| 62 | // TODO: validate, don't coerce |
| 63 | returnTo = '' + returnTo; |
| 64 | origin = '' + origin; |
| 65 | pathPrefix = '' + pathPrefix; |
| 66 | // TODO(Post-MVP): consider adding HOME_LOCATION in allowedOrigins to allow |
| 67 | // redirection to work in development. |
| 68 | // we add the '/' to prevent returns to |
| 69 | // www.freecodecamp.org.somewhere.else.com |
| 70 | if ( |
| 71 | !returnTo || |
| 72 | !allowedOrigins.some(allowed => returnTo?.startsWith(allowed + '/')) |
| 73 | ) { |
| 74 | returnTo = `${_homeLocation}/learn`; |
| 75 | origin = _homeLocation; |
| 76 | pathPrefix = ''; |
| 77 | } |
| 78 | if (!origin || !allowedOrigins.includes(origin)) { |
| 79 | returnTo = `${_homeLocation}/learn`; |
| 80 | origin = _homeLocation; |
| 81 | pathPrefix = ''; |
| 82 | } |
| 83 | pathPrefix = availableLangs.client.includes(pathPrefix) ? pathPrefix : ''; |
| 84 | return { returnTo, origin, pathPrefix }; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Get the prefixed landing path. |
no outgoing calls
no test coverage detected