fix: disallow non-ascii chars in bed_mesh name (#1311)

This commit is contained in:
Stefan Dej authored and GitHub committed 2023-04-01 15:55:16 +02:00
1 parent 0f01a8f994
commit 7301ae986a
2 files changed
+27 -4

No files matched your search

+1
View File
@@ -280,6 +280,7 @@
"Flat": "Flat",
"Heightmap": "Heightmap",
"InvalidNameAlreadyExists": "Profile name already exists, please choose another profile name.",
"InvalidNameAscii": "Name is invalid. Only ascii character are allowed.",
"InvalidNameEmpty": "Input must not be empty!",
"InvalidNameReserved": "Profile 'default' is reserved, please choose another profile name.",
"Later": "Later",
+26 -4
View File
@@ -291,8 +291,12 @@
:label="$t('Heightmap.Name')"
required
:rules="renameInputRules"
@update:error="isInvalidName = !isInvalidName"
@keyup.enter="renameProfile"></v-text-field>
@update:error="
(bool) => {
isInvalidName = bool
}
"
@keyup.enter="renameProfile" />
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
@@ -323,13 +327,21 @@
ref="inputFieldCalibrateBedMeshName"
v-model="calibrateDialog.name"
:label="$t('Heightmap.Name')"
:rules="createInputRules"
required
@keyup.enter="calibrateMesh"></v-text-field>
@update:error="
(bool) => {
calibrateDialog.isInvalidName = bool
}
"
@keyup.enter="calibrateMesh" />
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn text @click="calibrateDialog.boolShow = false">{{ $t('Heightmap.Abort') }}</v-btn>
<v-btn color="primary" text @click="calibrateMesh">{{ $t('Heightmap.Calibrate') }}</v-btn>
<v-btn :disabled="calibrateDialog.isInvalidName" color="primary" text @click="calibrateMesh">
{{ $t('Heightmap.Calibrate') }}
</v-btn>
</v-card-actions>
</panel>
</v-dialog>
@@ -465,17 +477,26 @@ export default class PageHeightmap extends Mixins(BaseMixin, ControlMixin) {
private calibrateDialog: {
boolShow: boolean
name: string
isInvalidName: boolean
} = {
boolShow: false,
name: 'default',
isInvalidName: false,
}
private newName = ''
private oldName = ''
private isInvalidName = true
private createInputRules = [
(value: string) => !!value || this.$t('Heightmap.InvalidNameEmpty'),
// eslint-disable-next-line no-control-regex
(value: string) => value === value.replace(/[^\x00-\x7F]/g, '') || this.$t('Heightmap.InvalidNameAscii'),
]
private renameInputRules = [
(value: string) => !!value || this.$t('Heightmap.InvalidNameEmpty'),
(value: string) => value !== 'default' || this.$t('Heightmap.InvalidNameReserved'),
(value: string) => !this.existsProfileName(value) || this.$t('Heightmap.InvalidNameAlreadyExists'),
// eslint-disable-next-line no-control-regex
(value: string) => value === value.replace(/[^\x00-\x7F]/g, '') || this.$t('Heightmap.InvalidNameAscii'),
]
private probedOpacity = 1
@@ -1038,6 +1059,7 @@ export default class PageHeightmap extends Mixins(BaseMixin, ControlMixin) {
this.newName = this.bed_mesh?.profile_name ?? ''
this.oldName = this.bed_mesh.profile_name
this.renameDialog = true
this.isInvalidName = false
setTimeout(() => {
this.$refs.inputDialogRenameHeightmapName?.focus()