diff --git a/storage/driver/boltdb.go b/storage/driver/boltdb.go
index 8c3516b..80d1872 100644
--- a/storage/driver/boltdb.go
+++ b/storage/driver/boltdb.go
@@ -16,10 +16,6 @@ import (
"go.mongodb.org/mongo-driver/bson/primitive"
)
-var (
- errModifiedReserved = errors.New("cannot modify reserved field " + entity.Name)
-)
-
type BoltDB struct {
db *bolt.DB
}
@@ -247,9 +243,6 @@ func apply(doc bson.M, operator interface{}) (bson.M, error) {
if err := bson.Unmarshal(b, &op); err != nil {
return nil, err
}
- if _, ok := op[entity.Name]; ok {
- return nil, errModifiedReserved
- }
for k, v := range op {
operateBM, ok := v.(bson.M)
if !ok {
@@ -282,7 +275,7 @@ func apply(doc bson.M, operator interface{}) (bson.M, error) {
func applyUnset(doc, operator bson.M) (bson.M, error) {
for k := range operator {
if k == entity.Name {
- return nil, errModifiedReserved
+ continue
}
nesting := strings.Split(k, ".")
if len(nesting) > 1 {
@@ -315,7 +308,7 @@ func applyUnset(doc, operator bson.M) (bson.M, error) {
func applySet(doc, operator bson.M) (bson.M, error) {
for k, v := range operator {
if k == entity.Name {
- return nil, errModifiedReserved
+ continue
}
nesting := strings.Split(k, ".")
if len(nesting) > 1 {
diff --git a/storage/driver/boltdb_test.go b/storage/driver/boltdb_test.go
index 826de8f..833d2f0 100644
--- a/storage/driver/boltdb_test.go
+++ b/storage/driver/boltdb_test.go
@@ -188,10 +188,6 @@ func TestBoltDBUpdate(t *testing.T) {
i++
}
- if err := bdb.Update(context.TODO(), testNS, ones[0].Query(), operator.Set{Key: entity.Name, Value: "NEWNAME"}); err == nil {
- t.Fatal(err)
- }
-
if err := bdb.Update(context.TODO(), testNS, ones[0].Query(), operator.Set{Key: entity.Title, Value: "NEWTITLE"}); err != nil {
t.Fatal(err)
}
diff --git a/view/markdown.go b/view/markdown.go
new file mode 100644
index 0000000..596365f
--- /dev/null
+++ b/view/markdown.go
@@ -0,0 +1,10 @@
+package view
+
+const (
+ markdownHead = `
+
+ `
+ markdownTail = `
`
+)
diff --git a/view/who.go b/view/who.go
index 4c763df..df3fe39 100644
--- a/view/who.go
+++ b/view/who.go
@@ -18,7 +18,6 @@ import (
"sort"
"strings"
- "github.com/buger/jsonparser"
"github.com/gomarkdown/markdown"
"github.com/gomarkdown/markdown/html"
"github.com/gomarkdown/markdown/parser"
@@ -133,7 +132,7 @@ func whoGet(namespace string, g storage.RateLimitedGraph, w http.ResponseWriter,
renderer := html.NewRenderer(html.RendererOptions{Flags: html.CommonFlags | html.TOC})
parser := parser.NewWithExtensions(parser.CommonExtensions | parser.HeadingIDs | parser.AutoHeadingIDs | parser.Titleblock)
- m["md"] = string(markdown.ToHTML([]byte(one.Text), parser, renderer))
+ m["md"] = markdownHead + string(markdown.ToHTML([]byte(one.Text), parser, renderer)) + markdownTail
b, err = json.MarshalIndent(m, "", " ")
if err != nil {
@@ -156,8 +155,10 @@ func whoPut(namespace string, g storage.RateLimitedGraph, w http.ResponseWriter,
if err != nil {
return err
}
+ reader := bytes.NewReader(body)
+
operation := entity.One{}
- if err := json.Unmarshal(body, &operation); err != nil {
+ if err := json.NewDecoder(reader).Decode(&operation); err != nil {
return err
}
if operation.Name != "" && operation.Name != id {
@@ -168,19 +169,13 @@ func whoPut(namespace string, g storage.RateLimitedGraph, w http.ResponseWriter,
http.Error(w, `{"error":"cannot specify modified in request body"}`, http.StatusBadRequest)
return nil
}
- b, err := bson.Marshal(operation)
- if err != nil {
- return err
- }
+
+ body = bytes.ReplaceAll(body, []byte(`"`+entity.JSONName+`"`), []byte(`"`+entity.Name+`"`))
op := bson.M{}
- if err := bson.Unmarshal(b, &op); err != nil {
+ if err := json.Unmarshal(body, &op); err != nil {
return err
}
- for k := range op {
- if _, _, _, err := jsonparser.Get(body, k); err != nil {
- delete(op, k)
- }
- }
+
if err := g.Update(r.Context(), namespace, entity.One{Name: id}, operator.SetMany{Value: op}); err != nil {
return err
}
diff --git a/view/who_test.go b/view/who_test.go
index 9036e73..d453e42 100644
--- a/view/who_test.go
+++ b/view/who_test.go
@@ -4,7 +4,6 @@ import (
"bytes"
"context"
"encoding/json"
- "encoding/xml"
"fmt"
"io/ioutil"
"local/dndex/config"
@@ -150,13 +149,10 @@ func TestWho(t *testing.T) {
if fmt.Sprint(o) != fmt.Sprint(iwant) {
t.Fatalf("after resolving connections and modified, iwant and got differ: \nwant %+v\n got %+v", iwant, o)
}
- var paragraphContent string
- if v, err := jsonparser.GetString(w.Body.Bytes(), "md"); err != nil {
+ if md, err := jsonparser.GetString(w.Body.Bytes(), "md"); err != nil {
t.Fatal(err)
- } else if err := xml.Unmarshal([]byte(v), ¶graphContent); err != nil {
- t.Fatal(err)
- } else if paragraphContent != iwant.Text {
- t.Fatal(iwant.Text, paragraphContent, v)
+ } else if !strings.HasPrefix(strings.TrimSpace(md), "<") || !strings.Contains(md, iwant.Text) {
+ t.Fatal(iwant.Text, md)
}
b, _ := json.MarshalIndent(o, "", " ")
t.Logf("POST GET:\n%s", b)
@@ -780,7 +776,9 @@ func TestWho(t *testing.T) {
}
o.Attachments = want.Attachments
if fmt.Sprint(o) != fmt.Sprint(want) {
- t.Fatalf("GET put != expected: want:\n%+v, got \n%+v", want, o)
+ wantjs, _ := json.MarshalIndent(want, "", " ")
+ ojs, _ := json.MarshalIndent(o, "", " ")
+ t.Fatalf("GET put != expected: want:\n%s, got \n%s", wantjs, ojs)
}
forget := want.Peers()[0]