From e15d353dd8ba455a4012ff054bc37fd64d683270 Mon Sep 17 00:00:00 2001 From: angrykirc Date: Fri, 9 Feb 2024 23:08:03 +0300 Subject: [PATCH] Fix for broken line in Nox Demo --- things/thing.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/things/thing.go b/things/thing.go index 2deb8c0..a16c269 100644 --- a/things/thing.go +++ b/things/thing.go @@ -8,7 +8,9 @@ import ( "reflect" "strconv" "strings" + "regexp" + "github.com/noxworld-dev/opennox-lib/log" "github.com/noxworld-dev/opennox-lib/strman" "github.com/noxworld-dev/opennox-lib/types" ) @@ -17,6 +19,7 @@ var ( reflThing = reflect.TypeOf(Thing{}) reflProcFunc = reflect.TypeOf(ProcFunc{}) reflThingKeys = make(map[string]reflect.StructField) + regexAlphanum = regexp.MustCompile(`^[A-Za-z0-9_]+`) ) func init() { @@ -279,6 +282,11 @@ func (f *Reader) ReadThingSect() (*Thing, error) { if len(kv) == 2 { val = strings.TrimSpace(kv[1]) } + // workaround for single bugged entry in demo + if !regexAlphanum.MatchString(key) { + log.Printf("failed to parse thing attr entry: %s", kv) + continue + } switch key { case "DRAW": if val != "" {