+ client: Validate adding of absolute path to the filtering lists

This commit is contained in:
ArtemBaskal
2020-04-06 20:07:32 +03:00
parent fc03ca4bb8
commit 421ad744cb
5 changed files with 31 additions and 15 deletions

View File

@@ -1,7 +1,10 @@
import React, { Fragment } from 'react';
import { Trans } from 'react-i18next';
import PropTypes from 'prop-types';
import { R_IPV4, R_MAC, R_HOST, R_IPV6, R_CIDR, R_CIDR_IPV6, UNSAFE_PORTS, R_URL_REQUIRES_PROTOCOL } from '../helpers/constants';
import {
R_IPV4, R_MAC, R_HOST, R_IPV6, R_CIDR, R_CIDR_IPV6,
UNSAFE_PORTS, R_URL_REQUIRES_PROTOCOL, R_WIN_ABSOLUTE_PATH, R_UNIX_ABSOLUTE_PATH,
} from '../helpers/constants';
import { createOnBlurHandler } from './helpers';
export const renderField = (props, elementType) => {
@@ -289,4 +292,14 @@ export const isValidUrl = (value) => {
return undefined;
};
export const isValidAbsolutePath = value => R_WIN_ABSOLUTE_PATH.test(value)
|| R_UNIX_ABSOLUTE_PATH.test(value);
export const isValidPath = (value) => {
if (value && !isValidAbsolutePath(value) && !R_URL_REQUIRES_PROTOCOL.test(value)) {
return <Trans>form_error_url_or_path_format</Trans>;
}
return undefined;
};
export const toNumber = value => value && parseInt(value, 10);