From 6e10586303fd90f0298c8086e754b35dfc3f01ba Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Wed, 27 Nov 2019 11:49:49 -0700 Subject: admin: Preserve "@id" fields through partial changes (fixes #2902) --- admin.go | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'admin.go') diff --git a/admin.go b/admin.go index b1ced18..981f2dc 100644 --- a/admin.go +++ b/admin.go @@ -27,6 +27,7 @@ import ( "net/url" "os" "path" + "regexp" "strconv" "strings" "sync" @@ -764,6 +765,12 @@ var ( } ) +// idRegexp is used to match ID fields and their associated values +// in the config. It also matches adjacent commas so that syntax +// can be preserved no matter where in the object the field appears. +// It supports string and most numeric values. +var idRegexp = regexp.MustCompile(`(?m),?\s*"` + idKey + `":\s?(-?[0-9]+(\.[0-9]+)?|(?U)".*")\s*,?`) + const ( rawConfigKey = "config" idKey = "@id" -- cgit v1.2.3