summaryrefslogtreecommitdiff
path: root/admin.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-12-12 14:30:22 -0700
committerMatthew Holt <mholt@users.noreply.github.com>2019-12-12 14:30:22 -0700
commitf935458e3e30a8d9f47f37ad35fe9c546b841fa3 (patch)
tree25c2e6365d8f1934bd9cb5b9e8faeee0b8a2ce3f /admin.go
parent2e0615270d157beb293bfce832a8a39bc6f2e749 (diff)
cmd: Fix validate command when JSON contains "@id" fields
Also, don't run admin server when validating...
Diffstat (limited to 'admin.go')
-rw-r--r--admin.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/admin.go b/admin.go
index fcbb62e..570d94c 100644
--- a/admin.go
+++ b/admin.go
@@ -734,6 +734,20 @@ traverseLoop:
return nil
}
+// RemoveMetaFields removes meta fields like "@id" from a JSON message.
+func RemoveMetaFields(rawJSON []byte) []byte {
+ return idRegexp.ReplaceAllFunc(rawJSON, func(in []byte) []byte {
+ // matches with a comma on both sides (when "@id" property is
+ // not the first or last in the object) need to keep exactly
+ // one comma for correct JSON syntax
+ comma := []byte{','}
+ if bytes.HasPrefix(in, comma) && bytes.HasSuffix(in, comma) {
+ return comma
+ }
+ return []byte{}
+ })
+}
+
// AdminHandler is like http.Handler except ServeHTTP may return an error.
//
// If any handler encounters an error, it should be returned for proper