From 6a9e073f03b9362958a7ae9cb5217fc3f4aaed09 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Sun, 21 Jul 2024 12:41:55 +0200 Subject: [PATCH] fix command prefix parsing #1884 --- interface/src/project/validators.ts | 16 ++++++++-------- src/command.cpp | 16 +++++++++++----- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/interface/src/project/validators.ts b/interface/src/project/validators.ts index d1b5a4795..b5bb94c9b 100644 --- a/interface/src/project/validators.ts +++ b/interface/src/project/validators.ts @@ -307,8 +307,8 @@ export const schedulerItemValidation = ( name: [ { type: 'string', - pattern: /^[a-zA-Z0-9_\\.]{0,19}$/, - message: "Must be <20 characters: alphanumeric, '_' or '.'" + pattern: /^[a-zA-Z0-9_]{0,19}$/, + message: "Must be <20 characters: alphanumeric or '_'" }, ...[uniqueNameValidator(schedule, scheduleItem.o_name)] ], @@ -349,8 +349,8 @@ export const entityItemValidation = (entity: EntityItem[], entityItem: EntityIte { required: true, message: 'Name is required' }, { type: 'string', - pattern: /^[a-zA-Z0-9_\\.]{1,19}$/, - message: "Must be <20 characters: alphanumeric, '_' or '.'" + pattern: /^[a-zA-Z0-9_]{1,19}$/, + message: "Must be <20 characters: alphanumeric or '_'" }, ...[uniqueCustomNameValidator(entity, entityItem.o_name)] ], @@ -403,8 +403,8 @@ export const temperatureSensorItemValidation = (sensors: TemperatureSensor[]) => n: [ { type: 'string', - pattern: /^[a-zA-Z0-9_\\.]{0,19}$/, - message: "Must be <20 characters: alphanumeric, '_' or '.'" + pattern: /^[a-zA-Z0-9_]{0,19}$/, + message: "Must be <20 characters: alphanumeric or '_'" }, ...[uniqueTemperatureNameValidator(sensors)] ] @@ -443,8 +443,8 @@ export const analogSensorItemValidation = ( n: [ { type: 'string', - pattern: /^[a-zA-Z0-9_\\.]{0,19}$/, - message: "Must be <20 characters: alphanumeric, '_' or '.'" + pattern: /^[a-zA-Z0-9_]{0,19}$/, + message: "Must be <20 characters: alphanumeric or '_'" }, ...[uniqueAnalogNameValidator(sensors)] ], diff --git a/src/command.cpp b/src/command.cpp index d6d12fb88..851d8682f 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -235,6 +235,10 @@ const char * Command::parse_command_string(const char * command, int8_t & id) { return nullptr; } + // remember unchanged command + const char * cmd_org = command; + int8_t id_org = id; + // convert cmd to lowercase and compare char * lowerCmd = strdup(command); for (char * p = lowerCmd; *p; p++) { @@ -271,13 +275,15 @@ const char * Command::parse_command_string(const char * command, int8_t & id) { command += 3; } - // remove separator - if (command[0] == '/' || command[0] == '.' || command[0] == '_') { - command++; - } - free(lowerCmd); + // return original if no seperator + if (command[0] != '/' && command[0] != '.') { + id = id_org; + return cmd_org; + } + command++; + // return null for empty command if (command[0] == '\0') { return nullptr;