Merge pull request #1885 from MichaelDvP/dev

fix command prefix parsing #1884
This commit is contained in:
Proddy
2024-07-23 10:49:11 +02:00
committed by GitHub
2 changed files with 19 additions and 13 deletions

View File

@@ -307,8 +307,8 @@ export const schedulerItemValidation = (
name: [ name: [
{ {
type: 'string', type: 'string',
pattern: /^[a-zA-Z0-9_\\.]{0,19}$/, pattern: /^[a-zA-Z0-9_]{0,19}$/,
message: "Must be <20 characters: alphanumeric, '_' or '.'" message: "Must be <20 characters: alphanumeric or '_'"
}, },
...[uniqueNameValidator(schedule, scheduleItem.o_name)] ...[uniqueNameValidator(schedule, scheduleItem.o_name)]
], ],
@@ -349,8 +349,8 @@ export const entityItemValidation = (entity: EntityItem[], entityItem: EntityIte
{ required: true, message: 'Name is required' }, { required: true, message: 'Name is required' },
{ {
type: 'string', type: 'string',
pattern: /^[a-zA-Z0-9_\\.]{1,19}$/, pattern: /^[a-zA-Z0-9_]{1,19}$/,
message: "Must be <20 characters: alphanumeric, '_' or '.'" message: "Must be <20 characters: alphanumeric or '_'"
}, },
...[uniqueCustomNameValidator(entity, entityItem.o_name)] ...[uniqueCustomNameValidator(entity, entityItem.o_name)]
], ],
@@ -403,8 +403,8 @@ export const temperatureSensorItemValidation = (sensors: TemperatureSensor[]) =>
n: [ n: [
{ {
type: 'string', type: 'string',
pattern: /^[a-zA-Z0-9_\\.]{0,19}$/, pattern: /^[a-zA-Z0-9_]{0,19}$/,
message: "Must be <20 characters: alphanumeric, '_' or '.'" message: "Must be <20 characters: alphanumeric or '_'"
}, },
...[uniqueTemperatureNameValidator(sensors)] ...[uniqueTemperatureNameValidator(sensors)]
] ]
@@ -443,8 +443,8 @@ export const analogSensorItemValidation = (
n: [ n: [
{ {
type: 'string', type: 'string',
pattern: /^[a-zA-Z0-9_\\.]{0,19}$/, pattern: /^[a-zA-Z0-9_]{0,19}$/,
message: "Must be <20 characters: alphanumeric, '_' or '.'" message: "Must be <20 characters: alphanumeric or '_'"
}, },
...[uniqueAnalogNameValidator(sensors)] ...[uniqueAnalogNameValidator(sensors)]
], ],

View File

@@ -235,6 +235,10 @@ const char * Command::parse_command_string(const char * command, int8_t & id) {
return nullptr; return nullptr;
} }
// remember unchanged command
const char * cmd_org = command;
int8_t id_org = id;
// convert cmd to lowercase and compare // convert cmd to lowercase and compare
char * lowerCmd = strdup(command); char * lowerCmd = strdup(command);
for (char * p = lowerCmd; *p; p++) { for (char * p = lowerCmd; *p; p++) {
@@ -271,13 +275,15 @@ const char * Command::parse_command_string(const char * command, int8_t & id) {
command += 3; command += 3;
} }
// remove separator
if (command[0] == '/' || command[0] == '.' || command[0] == '_') {
command++;
}
free(lowerCmd); free(lowerCmd);
// return original if no seperator
if (command[0] != '/' && command[0] != '.') {
id = id_org;
return cmd_org;
}
command++;
// return null for empty command // return null for empty command
if (command[0] == '\0') { if (command[0] == '\0') {
return nullptr; return nullptr;