simplify regular expressions

deepsource-autofix-76c6eb20
Dan Gowans 2023-01-24 10:39:16 -05:00
parent 6077199543
commit fff93f392a
2 changed files with 9 additions and 10 deletions

View File

@ -43,6 +43,8 @@ const safeRedirects = new Set([
'/workorders/outlook', '/workorders/outlook',
'/reports' '/reports'
]); ]);
const recordUrl = /^(\/(maps|lots|lotoccupancies|workorders)\/)\d+(\/edit)?$/;
const printUrl = /^\/print\/(pdf|screen)\/[\d/=?A-Za-z-]+$/;
export function getSafeRedirectURL(possibleRedirectURL = '') { export function getSafeRedirectURL(possibleRedirectURL = '') {
const urlPrefix = configFunctions.getProperty('reverseProxy.urlPrefix'); const urlPrefix = configFunctions.getProperty('reverseProxy.urlPrefix');
if (typeof possibleRedirectURL === 'string') { if (typeof possibleRedirectURL === 'string') {
@ -51,11 +53,8 @@ export function getSafeRedirectURL(possibleRedirectURL = '') {
: possibleRedirectURL; : possibleRedirectURL;
const urlToCheckLowerCase = urlToCheck.toLowerCase(); const urlToCheckLowerCase = urlToCheck.toLowerCase();
if (safeRedirects.has(urlToCheckLowerCase) || if (safeRedirects.has(urlToCheckLowerCase) ||
/^(\/maps\/)\d+(\/edit)?$/.test(urlToCheckLowerCase) || recordUrl.test(urlToCheckLowerCase) ||
/^(\/lots\/)\d+(\/edit)?$/.test(urlToCheckLowerCase) || printUrl.test(urlToCheck)) {
/^(\/lotoccupancies\/)\d+(\/edit)?$/.test(urlToCheckLowerCase) ||
/^(\/workorders\/)\d+(\/edit)?$/.test(urlToCheckLowerCase) ||
/^\/print\/(pdf|screen)\/[\d/=?A-Za-z-]+$/.test(urlToCheck)) {
return urlPrefix + urlToCheck; return urlPrefix + urlToCheck;
} }
} }

View File

@ -59,6 +59,9 @@ const safeRedirects = new Set([
'/reports' '/reports'
]) ])
const recordUrl = /^(\/(maps|lots|lotoccupancies|workorders)\/)\d+(\/edit)?$/
const printUrl = /^\/print\/(pdf|screen)\/[\d/=?A-Za-z-]+$/
export function getSafeRedirectURL(possibleRedirectURL = ''): string { export function getSafeRedirectURL(possibleRedirectURL = ''): string {
const urlPrefix = configFunctions.getProperty('reverseProxy.urlPrefix') const urlPrefix = configFunctions.getProperty('reverseProxy.urlPrefix')
@ -71,11 +74,8 @@ export function getSafeRedirectURL(possibleRedirectURL = ''): string {
if ( if (
safeRedirects.has(urlToCheckLowerCase) || safeRedirects.has(urlToCheckLowerCase) ||
/^(\/maps\/)\d+(\/edit)?$/.test(urlToCheckLowerCase) || recordUrl.test(urlToCheckLowerCase) ||
/^(\/lots\/)\d+(\/edit)?$/.test(urlToCheckLowerCase) || printUrl.test(urlToCheck)
/^(\/lotoccupancies\/)\d+(\/edit)?$/.test(urlToCheckLowerCase) ||
/^(\/workorders\/)\d+(\/edit)?$/.test(urlToCheckLowerCase) ||
/^\/print\/(pdf|screen)\/[\d/=?A-Za-z-]+$/.test(urlToCheck)
) { ) {
return urlPrefix + urlToCheck return urlPrefix + urlToCheck
} }