From 49dcdfb8607aac1343acfa0bc44c5ab6b17a042a Mon Sep 17 00:00:00 2001 From: bruce Date: Wed, 28 Sep 2022 18:03:29 +0800 Subject: [PATCH] feat: Reduce the character restriction of the name field Add characters :;= to reduce the character restriction. - In BACNet protocol, the user might combine object type and property as the resourceName, for example, analog_input_0:present-value - In OPC_UA protocol, the user might use NodeId as the resourceName, for example, ns=10;s=Hello:World Close #750 Signed-off-by: bruce --- common/validator.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/validator.go b/common/validator.go index 4cef6584..affa3277 100644 --- a/common/validator.go +++ b/common/validator.go @@ -34,7 +34,7 @@ const ( const ( // Per https://tools.ietf.org/html/rfc3986#section-2.3, unreserved characters= ALPHA / DIGIT / "-" / "." / "_" / "~" // Also due to names used in topics for Redis Pub/Sub, "."are not allowed - rFC3986UnreservedCharsRegexString = "^[a-zA-Z0-9-_~]+$" + rFC3986UnreservedCharsRegexString = "^[a-zA-Z0-9-_~:;=]+$" intervalDatetimeLayout = "20060102T150405" name = "Name" ) @@ -95,7 +95,7 @@ func getErrorMessage(e validator.FieldError) string { case dtoNoneEmptyStringTag: msg = fmt.Sprintf("%s field should not be empty string", fieldName) case dtoRFC3986UnreservedCharTag: - msg = fmt.Sprintf("%s field only allows unreserved characters which are ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_~", fieldName) + msg = fmt.Sprintf("%s field only allows unreserved characters which are ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_~:;=", fieldName) default: msg = fmt.Sprintf("%s field validation failed on the %s tag", fieldName, tag) }