* Strip domain from redirectUrl if it matches the current storeUrl, if not, leave it. * * @param {string} redirectUrl * @param {{ normalStoreUrl, storeUrl}} config * @returns {string}
(redirectUrl, config)
| 18 | * @returns {string} |
| 19 | */ |
| 20 | function normalizeRedirectUrl(redirectUrl, config) { |
| 21 | if (!redirectUrl || !redirectUrl.startsWith('http')) { |
| 22 | return redirectUrl; // already stripped, skip |
| 23 | } |
| 24 | const storeHost = new URL(config.normalStoreUrl).host; |
| 25 | const secureStoreHost = new URL(config.storeUrl).host; |
| 26 | const redirectUrlObj = new URL(redirectUrl); |
| 27 | if (redirectUrlObj.host === storeHost || redirectUrlObj.host === secureStoreHost) { |
| 28 | // Need to strip |
| 29 | return redirectUrlObj.pathname + redirectUrlObj.search + redirectUrlObj.hash; |
| 30 | } |
| 31 | return redirectUrl; // Different host, shouldn't strip |
| 32 | } |
| 33 | /** |
| 34 | * Convert a number to uuid |
| 35 | * |
no outgoing calls
no test coverage detected