Skip to content

Commit

Permalink
Batch of fixes (cvat-ai#1667)
Browse files Browse the repository at this point in the history
* Fixed validation pattern, register form refactoring

* Fixed snapToGrid for resize cvat-ai#1590

* Changed name validation pattern cvat-ai#1599

* Updated version

* Updated changelog
  • Loading branch information
bsekachev authored and Fernando Martínez González committed Aug 3, 2020
1 parent 5115e8c commit a6ea36d
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 22 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed dataset filter item representation for imageless dataset items (https://github.com/opencv/cvat/pull/1593)
- Fixed interpreter crash when trying to import `tensorflow` with no AVX instructions available (https://github.com/opencv/cvat/pull/1567)
- Kibana wrong working time calculation with new annotation UI use (<https://github.com/opencv/cvat/pull/1654>)
- Wrong rexex for account name validation (<https://github.com/opencv/cvat/pull/1667>)
- Wrong description on register view for the username field (<https://github.com/opencv/cvat/pull/1667>)
- Wrong resolution for resizing a shape (<https://github.com/opencv/cvat/pull/1667>)

### Security
- SQL injection in Django `CVE-2020-9402` (https://github.com/opencv/cvat/pull/1657)
Expand Down
4 changes: 3 additions & 1 deletion cvat-canvas/src/typescript/canvasView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1403,7 +1403,9 @@ export class CanvasViewImpl implements CanvasView, Listener {

let shapeSizeElement: ShapeSizeElement | null = null;
let resized = false;
(shape as any).resize().on('resizestart', (): void => {
(shape as any).resize({
snapToGrid: 0.1,
}).on('resizestart', (): void => {
this.mode = Mode.RESIZE;
if (state.shapeType === 'rectangle') {
shapeSizeElement = displayShapeSize(this.adoptedContent, this.adoptedText);
Expand Down
2 changes: 1 addition & 1 deletion cvat-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cvat-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cvat-ui",
"version": "1.2.1",
"version": "1.2.2",
"description": "CVAT single-page application",
"main": "src/index.tsx",
"scripts": {
Expand Down
41 changes: 24 additions & 17 deletions cvat-ui/src/components/register-page/register-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Checkbox from 'antd/lib/checkbox';

import patterns from 'utils/validation-patterns';

import { UserAgreement } from 'reducers/interfaces'
import { UserAgreement } from 'reducers/interfaces';
import { Row, Col } from 'antd/lib/grid';

export interface UserConfirmation {
Expand All @@ -31,7 +31,7 @@ export interface RegisterData {

type RegisterFormProps = {
fetching: boolean;
userAgreements: UserAgreement[],
userAgreements: UserAgreement[];
onSubmit(registerData: RegisterData): void;
} & FormComponentProps;

Expand Down Expand Up @@ -83,7 +83,7 @@ class RegisterFormComponent extends React.PureComponent<RegisterFormProps> {

private validateAgrement = (agreement: any, value: any, callback: any): void => {
const { userAgreements } = this.props;
let isValid: boolean = true;
let isValid = true;
for (const userAgreement of userAgreements) {
if (agreement.field === userAgreement.name
&& userAgreement.required && !value) {
Expand All @@ -107,18 +107,20 @@ class RegisterFormComponent extends React.PureComponent<RegisterFormProps> {

form.validateFields((error, values): void => {
if (!error) {
values.confirmations = []
const validatedFields = {
...values,
confirmations: [],
};

for (const userAgreement of userAgreements) {

values.confirmations.push({
validatedFields.confirmations.push({
name: userAgreement.name,
value: values[userAgreement.name]
value: validatedFields[userAgreement.name],
});
delete values[userAgreement.name];
delete validatedFields[userAgreement.name];
}

onSubmit(values);
onSubmit(validatedFields);
}
});
};
Expand Down Expand Up @@ -255,8 +257,7 @@ class RegisterFormComponent extends React.PureComponent<RegisterFormProps> {

private renderUserAgreements(): JSX.Element[] {
const { form, userAgreements } = this.props;
const getUserAgreementsElements = () =>
{
const getUserAgreementsElements = (): JSX.Element[] => {
const agreementsList: JSX.Element[] = [];
for (const userAgreement of userAgreements) {
agreementsList.push(
Expand All @@ -269,18 +270,24 @@ class RegisterFormComponent extends React.PureComponent<RegisterFormProps> {
message: 'You must accept to continue!',
}, {
validator: this.validateAgrement,
}]
}],
})(
<Checkbox>
I read and accept the <a rel='noopener noreferrer' target='_blank'
href={ userAgreement.url }>{ userAgreement.displayText }</a>
</Checkbox>
I read and accept the
<a
rel='noopener noreferrer'
target='_blank'
href={userAgreement.url}
>
{userAgreement.displayText}
</a>
</Checkbox>,
)}
</Form.Item>
</Form.Item>,
);
}
return agreementsList;
}
};

return getUserAgreementsElements();
}
Expand Down
14 changes: 12 additions & 2 deletions cvat-ui/src/utils/validation-patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,27 @@ const validationPatterns = {

validateUsernameLength: {
pattern: /(?=.{5,})/,
message: 'Username must have at least 8 characters',
message: 'Username must have at least 5 characters',
},

validateUsernameCharacters: {
pattern: /^[a-zA-Z0-9_-]{5,}$/,
message: 'Only characters (a-z), (A-Z), (0-9), -, _ are available',
},

/*
\p{Pd} - dash connectors
\p{Pc} - connector punctuations
\p{Cf} - invisible formatting indicator
\p{L} - any alphabetic character
Useful links:
https://stackoverflow.com/questions/4323386/multi-language-input-validation-with-utf-8-encoding
https://stackoverflow.com/questions/280712/javascript-unicode-regexes
https://stackoverflow.com/questions/6377407/how-to-validate-both-chinese-unicode-and-english-name
*/
validateName: {
// eslint-disable-next-line
pattern: /^[a-zA-Z]{2,}(([',. -][a-zA-Z ])?[a-zA-Z]*)*$/,
pattern: /^(\p{L}|\p{Pd}|\p{Cf}|\p{Pc}|['\s]){2,}$/gu,
message: 'Invalid name',
},

Expand Down

0 comments on commit a6ea36d

Please sign in to comment.