Skip to content

TagSpaces is an offline, open source, document manager with tagging support

fix tag name validation

Ilian Sapundshiev8dcd5c95e374
diff --git a/app/components/dialogs/CreateTagsDialog.js b/app/components/dialogs/CreateTagsDialog.js
index 38fd748ea..4f695961d 100644
--- a/app/components/dialogs/CreateTagsDialog.js
+++ b/app/components/dialogs/CreateTagsDialog.js
@@ -109,7 +109,7 @@ class CreateTagsDialog extends React.Component<Props, State> {
data-tid="addTagsInput"
fullWidth={true}
/>
- {this.state.inputError && <FormHelperText>{i18n.t('core:taggroupTitleHelper')}</FormHelperText>}
+ {this.state.inputError && <FormHelperText>{i18n.t('core:tagTitleHelper')}</FormHelperText>}
</FormControl>
</DialogContent>
diff --git a/app/components/dialogs/EditEntryTagDialog.js b/app/components/dialogs/EditEntryTagDialog.js
index 5f0b76457..4717c5237 100644
--- a/app/components/dialogs/EditEntryTagDialog.js
+++ b/app/components/dialogs/EditEntryTagDialog.js
@@ -42,7 +42,7 @@ const styles = theme => ({
type Props = {
open: boolean,
onClose: () => void,
- editTagForEntry: () => void,
+ editTagForEntry: (path: string, tag: Tag, title: string) => void,
currentEntryPath: string,
selectedTag: Tag,
open: boolean
@@ -57,13 +57,16 @@ type State = {
class EditEntryTagDialog extends React.Component<Props, State> {
state = {
disableConfirmButton: true,
- errorTag: true,
+ errorTag: false,
title: ''
};
componentWillReceiveProps = (nextProps: any) => {
if (nextProps.open === true) {
- this.setState({ title: nextProps.selectedTag.title });
+ this.setState({
+ disableConfirmButton: !nextProps.selectedTag.title,
+ title: nextProps.selectedTag.title
+ });
}
};
@@ -78,17 +81,18 @@ class EditEntryTagDialog extends React.Component<Props, State> {
};
handleValidation() {
- if (this.state.title.length > 0) {
- this.setState({ inputError: false, disableConfirmButton: false });
+ const tagCheck = RegExp(/^[^\#\/\\ \[\]]{1,}$/);
+ if (this.state.title && tagCheck.test(this.state.title)) {
+ this.setState({ errorTag: false, disableConfirmButton: false });
} else {
- this.setState({ inputError: true, disableConfirmButton: true });
+ this.setState({ errorTag: true, disableConfirmButton: true });
}
}
onConfirm = () => {
if (!this.state.disableConfirmButton) {
this.props.editTagForEntry(this.props.currentEntryPath, this.props.selectedTag, this.state.title);
- this.setState({ inputError: false, disableConfirmButton: true });
+ this.setState({ errorTag: false, disableConfirmButton: true });
this.props.onClose();
}
};
@@ -113,7 +117,7 @@ class EditEntryTagDialog extends React.Component<Props, State> {
value={this.state.title}
data-tid="editTagEntryDialog_input"
/>
- {this.state.inputError && <FormHelperText>Can title could not be empty</FormHelperText>}
+ {this.state.errorTag && <FormHelperText>{i18n.t('core:tagTitleHelper')}</FormHelperText>}
</FormControl>
</DialogContent>
);
diff --git a/app/components/dialogs/EditTagDialog.js b/app/components/dialogs/EditTagDialog.js
index 92be71106..bec2a1777 100644
--- a/app/components/dialogs/EditTagDialog.js
+++ b/app/components/dialogs/EditTagDialog.js
@@ -85,7 +85,8 @@ class EditTagDialog extends React.Component<Props, State> {
};
handleValidation() {
- if (this.state.title && this.state.title.length > 0) {
+ const tagCheck = RegExp(/^[^\#\/\\ \[\]]{1,}$/);
+ if (this.state.title && tagCheck.test(this.state.title)) {
this.setState({ inputError: false, disableConfirmButton: false });
} else {
this.setState({ inputError: true, disableConfirmButton: true });
@@ -186,7 +187,7 @@ class EditTagDialog extends React.Component<Props, State> {
data-tid="editTagInput"
fullWidth={true}
/>
- {this.state.inputError && <FormHelperText style={styles.helpText}>{i18n.t('core:taggroupTitleHelper')}</FormHelperText>}
+ {this.state.inputError && <FormHelperText style={styles.helpText}>{i18n.t('core:tagTitleHelper')}</FormHelperText>}
</FormControl>
<FormControl
fullWidth={true}
diff --git a/app/locales/en/core.json b/app/locales/en/core.json
index df8e42c4b..3c66ac2eb 100644
--- a/app/locales/en/core.json
+++ b/app/locales/en/core.json
@@ -16,7 +16,6 @@
"selectDialogTitle": "Select Directory",
"selectDialogCurrentPath": "Current Path",
"editTagTitle": "Edit tag",
- "editTagNamesRestrictionsHelp": "Tags should have a minimum length of 2 characters and should not contain special characters such as spaces, #, / ,\\ and other.",
"tagOperationTitle": "Tag operation on multiple files",
"tagOperationTag": "Tags",
"tagOperationTagsPlaceholder": "Tag",
@@ -354,5 +353,6 @@
"loading": "Loading...",
"cancelEditing": "Cancel editing",
"upgradeToPro": "See what's in the PRO version",
+ "tagTitleHelper": "Tags should be at least 1 character long and should not contain: spaces, \\, / #",
"-": "-"
}