Skip to content

Commit

Permalink
Pull request: 3684 validate client id in the mobileconfig form
Browse files Browse the repository at this point in the history
Closes AdguardTeam#3684

Squashed commit of the following:

commit 78e9862
Author: Ildar Kamalov <ik@adguard.com>
Date:   Fri Oct 15 14:39:36 2021 +0300

    fix build

commit 3ed4ee6
Author: Ildar Kamalov <ik@adguard.com>
Date:   Fri Oct 15 13:39:12 2021 +0300

    client: validate client id in the mobileconfig form
  • Loading branch information
IldarKamalov committed Oct 15, 2021
1 parent 2796e65 commit 3fa38fb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions client/src/components/ui/Guide/MobileConfigForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
toNumber,
} from '../../../helpers/form';
import {
validateClientId,
validateConfigClientId,
validateServerName,
validatePort,
validateIsSafePort,
Expand Down Expand Up @@ -132,7 +132,7 @@ const MobileConfigForm = ({ invalid }) => {
component={renderInputField}
className="form-control"
placeholder={i18next.t('client_id_placeholder')}
validate={validateClientId}
validate={validateConfigClientId}
/>
</div>
<div className="form__group form__group--settings">
Expand Down
2 changes: 1 addition & 1 deletion client/src/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const R_UNIX_ABSOLUTE_PATH = /^(\/[^/\x00]+)+$/;
// eslint-disable-next-line no-control-regex
export const R_WIN_ABSOLUTE_PATH = /^([a-zA-Z]:)?(\\|\/)(?:[^\\/:*?"<>|\x00]+\\)*[^\\/:*?"<>|\x00]*$/;

export const R_CLIENT_ID = /^[a-z0-9-]{1,64}$/;
export const R_CLIENT_ID = /^[a-z0-9-]{1,63}$/;

export const HTML_PAGES = {
INSTALL: '/install.html',
Expand Down
15 changes: 15 additions & 0 deletions client/src/helpers/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ export const validateClientId = (value) => {
return undefined;
};

/**
* @param value {string}
* @returns {undefined|string}
*/
export const validateConfigClientId = (value) => {
if (!value) {
return undefined;
}
const formattedValue = value.trim();
if (formattedValue && !R_CLIENT_ID.test(formattedValue)) {
return 'form_error_client_id_format';
}
return undefined;
};

/**
* @param value {string}
* @returns {undefined|string}
Expand Down

0 comments on commit 3fa38fb

Please sign in to comment.