Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow empty annotation layer names and names starting with a '.' #8244

Merged
merged 4 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
### Fixed
- Fixed performance bottleneck when deleting a lot of trees at once. [#8176](https://github.com/scalableminds/webknossos/pull/8176)
- Fixed that listing datasets with the `api/datasets` route without compression failed due to missing permissions regarding public datasets. [#8249](https://github.com/scalableminds/webknossos/pull/8249)
- Fixed that the frontend did not ensure a minium length for annotation layer names. Moreover, names starting with a `.` are also disallowed now. [#8244](https://github.com/scalableminds/webknossos/pull/8244)
- Fixed a bug where changing the color of a segment via the menu in the segments tab would update the segment color of the previous segment, on which the context menu was opened. [#8225](https://github.com/scalableminds/webknossos/pull/8225)
- Fixed a bug where in the add remote dataset view the dataset name setting was not in sync with the datasource setting of the advanced tab making the form not submittable. [#8245](https://github.com/scalableminds/webknossos/pull/8245)
- Fixed a bug when importing an NML with groups when only groups but no trees exist in an annotation. [#8176](https://github.com/scalableminds/webknossos/pull/8176)
Expand Down
2 changes: 2 additions & 0 deletions frontend/javascripts/messages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ instead. Only enable this option if you understand its effect. All layers will n
} "${disallowedCharacters}". Please remove ${
disallowedCharacters.length > 1 ? "them" : "it"
} to set the layer name.`,
"tracing.volume_layer_name_too_short": "The layer name must be at least one character long.",
"tracing.volume_layer_name_starts_with_dot": "The layer name must not start with a dot.",
"tracing.delete_initial_node": "Do you really want to delete the initial node?",
"tracing.delete_tree": "Do you really want to delete the whole tree?",
"tracing.delete_tree_with_initial_node":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import FastTooltip from "components/fast_tooltip";
type Rule = {
message?: string;
type?: string;
min?: number;
validator?: (arg0: string) => ValidationResult;
};
export type EditableTextLabelProp = {
Expand Down Expand Up @@ -118,6 +119,11 @@ class EditableTextLabel extends React.PureComponent<EditableTextLabelProp, State
Toast.error(validationResult.message);
return false;
}
} else if (rule.min != null) {
if (this.state.value.length < rule.min) {
Toast.error(`Length must at least be ${rule.min}.`);
return false;
}
philippotto marked this conversation as resolved.
Show resolved Hide resolved
}
return true;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ export function checkForLayerNameDuplication(
}

export function checkLayerNameForInvalidCharacters(readableLayerName: string): ValidationResult {
// A layer name is not allowed to start with a dot.
if (readableLayerName.startsWith(".")) {
return {
isValid: false,
message: messages["tracing.volume_layer_name_starts_with_dot"],
};
}
const uriSafeCharactersRegex = /[0-9a-zA-Z-._]+/g;
// Removing all URISaveCharacters from readableLayerName. The leftover chars are all invalid.
const allInvalidChars = readableLayerName.replace(uriSafeCharactersRegex, "");
Expand All @@ -62,6 +69,12 @@ export function validateReadableLayerName(
allReadableLayerNames: string[],
nameNotToCount?: string,
): ValidationResult {
if (readableLayerName.length < 1) {
return {
isValid: false,
message: messages["tracing.volume_layer_name_too_short"],
};
}
if (nameNotToCount) {
// nameNotToCount needs to be removed once if it is included in allReadableLayerNames.
// This is needed in case of saving an existing volume layer's name when the name was not modified.
Expand Down