mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 04:30:05 +00:00
🐛 fixed #105
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"time"
|
||||
@@ -25,5 +26,10 @@ type Server struct {
|
||||
}
|
||||
|
||||
func (s Server) Marshal() template.JS {
|
||||
return template.JS(fmt.Sprintf(`{"ID":%d,"Name":"%s","Secret":"%s","DisplayIndex":%d,"Tag":"%s","Note":"%s"}`, s.ID, s.Name, s.Secret, s.DisplayIndex, s.Tag, s.Note))
|
||||
name, _ := json.Marshal(s.Name)
|
||||
tag, _ := json.Marshal(s.Tag)
|
||||
note, _ := json.Marshal(s.Note)
|
||||
secret, _ := json.Marshal(s.Secret)
|
||||
return template.JS(fmt.Sprintf(`{"ID":%d,"Name":%s,"Secret":%s,"DisplayIndex":%d,"Tag":%s,"Note":%s}`,
|
||||
s.ID, name, secret, s.DisplayIndex, tag, note))
|
||||
}
|
||||
|
||||
27
model/server_test.go
Normal file
27
model/server_test.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestServerMarshal(t *testing.T) {
|
||||
patterns := []string{
|
||||
"asd > asd",
|
||||
"asd \" asd",
|
||||
"asd } asd",
|
||||
}
|
||||
|
||||
for i := 0; i < len(patterns); i++ {
|
||||
server := Server{
|
||||
Name: patterns[i],
|
||||
Tag: patterns[i],
|
||||
}
|
||||
serverStr := string(server.Marshal())
|
||||
var serverRestore Server
|
||||
assert.Nil(t, json.Unmarshal([]byte(serverStr), &serverRestore))
|
||||
assert.Equal(t, server, serverRestore)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user