mirror of
https://github.com/siyuan-note/siyuan
synced 2026-04-21 13:37:52 +00:00
🐛 Escaping issues in attribute panel https://github.com/siyuan-note/siyuan/issues/17345
Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
parent
c060539136
commit
83bd6acf68
4 changed files with 28 additions and 29 deletions
|
|
@ -2816,14 +2816,14 @@ func (tx *Transaction) doRemoveAttrViewView(operation *Operation) (ret *TxErr) {
|
|||
if blockViewID == viewID {
|
||||
attrs[av.NodeAttrView] = attrView.ViewID
|
||||
node.AttributeViewType = string(view.LayoutType)
|
||||
oldAttrsUnEsc, e := setNodeAttrs0(node, attrs)
|
||||
oldAttrs, e := setNodeAttrs0(node, attrs)
|
||||
if nil != e {
|
||||
logging.LogErrorf("set node attrs failed: %s", e)
|
||||
continue
|
||||
}
|
||||
|
||||
cache.PutBlockIAL(node.ID, parse.IAL2Map(node.KramdownIAL))
|
||||
pushBlockAttrs(oldAttrsUnEsc, node)
|
||||
pushBlockAttrs(oldAttrs, node)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -3254,9 +3254,9 @@ func (tx *Transaction) setAttributeViewName(operation *Operation) (err error) {
|
|||
_, nodes := tx.getAttrViewBoundNodes(attrView)
|
||||
for _, node := range nodes {
|
||||
avNames := getAvNames(node.IALAttr(av.NodeAttrNameAvs))
|
||||
oldAttrsUnEsc := parse.IAL2MapUnEsc(node.KramdownIAL)
|
||||
oldAttrs := parse.IAL2Map(node.KramdownIAL)
|
||||
node.SetIALAttr(av.NodeAttrViewNames, avNames)
|
||||
pushBlockAttrs(oldAttrsUnEsc, node)
|
||||
pushBlockAttrs(oldAttrs, node)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
@ -5826,12 +5826,12 @@ func updateBoundBlockAvsAttribute(avIDs []string) {
|
|||
attrs[av.NodeAttrViewNames] = avNames
|
||||
}
|
||||
|
||||
oldAttrsUnEsc, setErr := setNodeAttrs0(node, attrs)
|
||||
oldAttrs, setErr := setNodeAttrs0(node, attrs)
|
||||
if nil != setErr {
|
||||
continue
|
||||
}
|
||||
cache.PutBlockIAL(node.ID, parse.IAL2Map(node.KramdownIAL))
|
||||
pushBlockAttrs(oldAttrsUnEsc, node)
|
||||
pushBlockAttrs(oldAttrs, node)
|
||||
if "" != avNames {
|
||||
node.RemoveIALAttr(av.NodeAttrViewNames)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ package model
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
|
@ -126,13 +125,13 @@ func BatchSetBlockAttrs(blockAttrs []map[string]interface{}) (err error) {
|
|||
}
|
||||
|
||||
attrs := blockAttr["attrs"].(map[string]string)
|
||||
oldAttrsUnEsc, e := setNodeAttrs0(node, attrs)
|
||||
oldAttrs, e := setNodeAttrs0(node, attrs)
|
||||
if nil != e {
|
||||
return e
|
||||
}
|
||||
|
||||
cache.PutBlockIAL(node.ID, parse.IAL2Map(node.KramdownIAL))
|
||||
pushBlockAttrs(oldAttrsUnEsc, node)
|
||||
pushBlockAttrs(oldAttrs, node)
|
||||
nodes = append(nodes, node)
|
||||
}
|
||||
|
||||
|
|
@ -169,7 +168,7 @@ func SetBlockAttrs(id string, nameValues map[string]string) (err error) {
|
|||
}
|
||||
|
||||
func setNodeAttrs(node *ast.Node, tree *parse.Tree, nameValues map[string]string) (err error) {
|
||||
oldAttrsUnEsc, err := setNodeAttrs0(node, nameValues)
|
||||
oldAttrs, err := setNodeAttrs0(node, nameValues)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
@ -181,7 +180,7 @@ func setNodeAttrs(node *ast.Node, tree *parse.Tree, nameValues map[string]string
|
|||
IncSync()
|
||||
cache.PutBlockIAL(node.ID, parse.IAL2Map(node.KramdownIAL))
|
||||
|
||||
pushBlockAttrs(oldAttrsUnEsc, node)
|
||||
pushBlockAttrs(oldAttrs, node)
|
||||
|
||||
go func() {
|
||||
sql.FlushQueue()
|
||||
|
|
@ -191,7 +190,7 @@ func setNodeAttrs(node *ast.Node, tree *parse.Tree, nameValues map[string]string
|
|||
}
|
||||
|
||||
func setNodeAttrsWithTx(tx *Transaction, node *ast.Node, tree *parse.Tree, nameValues map[string]string) (err error) {
|
||||
oldAttrsUnEsc, err := setNodeAttrs0(node, nameValues)
|
||||
oldAttrs, err := setNodeAttrs0(node, nameValues)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
@ -200,13 +199,13 @@ func setNodeAttrsWithTx(tx *Transaction, node *ast.Node, tree *parse.Tree, nameV
|
|||
|
||||
IncSync()
|
||||
cache.PutBlockIAL(node.ID, parse.IAL2Map(node.KramdownIAL))
|
||||
pushBlockAttrs(oldAttrsUnEsc, node)
|
||||
pushBlockAttrs(oldAttrs, node)
|
||||
return
|
||||
}
|
||||
|
||||
func setNodeAttrs0(node *ast.Node, nameValues map[string]string) (oldAttrsUnEsc map[string]string, err error) {
|
||||
oldAttrsUnEsc = parse.IAL2MapUnEsc(node.KramdownIAL)
|
||||
newAttrsUnEsc := maps.Clone(oldAttrsUnEsc)
|
||||
func setNodeAttrs0(node *ast.Node, nameValues map[string]string) (oldAttrs map[string]string, err error) {
|
||||
oldAttrs = parse.IAL2Map(node.KramdownIAL)
|
||||
newAttrsUnEsc := parse.IAL2MapUnEsc(node.KramdownIAL)
|
||||
|
||||
for name, value := range nameValues {
|
||||
value = util.RemoveInvalidRetainCtrl(value)
|
||||
|
|
@ -257,7 +256,7 @@ func setNodeAttrs0(node *ast.Node, nameValues map[string]string) (oldAttrsUnEsc
|
|||
|
||||
node.KramdownIAL = parse.Map2IAL(newAttrsUnEsc)
|
||||
|
||||
if oldAttrsUnEsc["tags"] != newAttrsUnEsc["tags"] {
|
||||
if html.EscapeAttrVal(oldAttrs["tags"]) != newAttrsUnEsc["tags"] {
|
||||
ReloadTag()
|
||||
}
|
||||
return
|
||||
|
|
@ -280,7 +279,7 @@ func ResetBlockAttrs(id string, nameValues map[string]string) (err error) {
|
|||
return errors.New(fmt.Sprintf(Conf.Language(15), id))
|
||||
}
|
||||
|
||||
oldAttrsUnEsc := parse.IAL2MapUnEsc(node.KramdownIAL)
|
||||
oldAttrs := parse.IAL2Map(node.KramdownIAL)
|
||||
node.ClearIALAttrs()
|
||||
|
||||
_, err = setNodeAttrs0(node, nameValues)
|
||||
|
|
@ -295,7 +294,7 @@ func ResetBlockAttrs(id string, nameValues map[string]string) (err error) {
|
|||
IncSync()
|
||||
cache.PutBlockIAL(node.ID, parse.IAL2Map(node.KramdownIAL))
|
||||
|
||||
pushBlockAttrs(oldAttrsUnEsc, node)
|
||||
pushBlockAttrs(oldAttrs, node)
|
||||
|
||||
go func() {
|
||||
sql.FlushQueue()
|
||||
|
|
@ -349,9 +348,9 @@ func validateChars(name string, startIdx, n int) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func pushBlockAttrs(oldAttrsUnEsc map[string]string, node *ast.Node) {
|
||||
func pushBlockAttrs(oldAttrs map[string]string, node *ast.Node) {
|
||||
newAttrs := parse.IAL2Map(node.KramdownIAL)
|
||||
data := map[string]interface{}{"old": oldAttrsUnEsc, "new": newAttrs}
|
||||
data := map[string]interface{}{"old": oldAttrs, "new": newAttrs}
|
||||
if "" != node.AttributeViewType {
|
||||
data["data-av-type"] = node.AttributeViewType
|
||||
}
|
||||
|
|
|
|||
|
|
@ -802,7 +802,7 @@ func (tx *Transaction) removeBlocksDeckAttr(blockIDs []string, deckID string) (e
|
|||
continue
|
||||
}
|
||||
|
||||
oldAttrsUnEsc := parse.IAL2MapUnEsc(node.KramdownIAL)
|
||||
oldAttrs := parse.IAL2Map(node.KramdownIAL)
|
||||
|
||||
deckAttrs := node.IALAttr(NodeAttrRiffDecks)
|
||||
var deckIDs []string
|
||||
|
|
@ -828,7 +828,7 @@ func (tx *Transaction) removeBlocksDeckAttr(blockIDs []string, deckID string) (e
|
|||
tx.writeTree(tree)
|
||||
|
||||
cache.PutBlockIAL(blockID, parse.IAL2Map(node.KramdownIAL))
|
||||
pushBlockAttrs(oldAttrsUnEsc, node)
|
||||
pushBlockAttrs(oldAttrs, node)
|
||||
}
|
||||
|
||||
return
|
||||
|
|
@ -908,7 +908,7 @@ func (tx *Transaction) doAddFlashcards(operation *Operation) (ret *TxErr) {
|
|||
continue
|
||||
}
|
||||
|
||||
oldAttrsUnEsc := parse.IAL2MapUnEsc(node.KramdownIAL)
|
||||
oldAttrs := parse.IAL2Map(node.KramdownIAL)
|
||||
|
||||
deckAttrs := node.IALAttr(NodeAttrRiffDecks)
|
||||
deckIDs := strings.Split(deckAttrs, ",")
|
||||
|
|
@ -922,7 +922,7 @@ func (tx *Transaction) doAddFlashcards(operation *Operation) (ret *TxErr) {
|
|||
tx.writeTree(tree)
|
||||
|
||||
cache.PutBlockIAL(blockID, parse.IAL2Map(node.KramdownIAL))
|
||||
pushBlockAttrs(oldAttrsUnEsc, node)
|
||||
pushBlockAttrs(oldAttrs, node)
|
||||
}
|
||||
|
||||
deck := Decks[deckID]
|
||||
|
|
|
|||
|
|
@ -1061,9 +1061,9 @@ func (tx *Transaction) syncDelete2Block(node *ast.Node, nodeTree *parse.Tree) (c
|
|||
}
|
||||
}
|
||||
avNames := getAvNames(toChangNode.IALAttr(av.NodeAttrNameAvs))
|
||||
oldAttrsUnEsc := parse.IAL2MapUnEsc(toChangNode.KramdownIAL)
|
||||
oldAttrs := parse.IAL2Map(toChangNode.KramdownIAL)
|
||||
toChangNode.SetIALAttr(av.NodeAttrViewNames, avNames)
|
||||
pushBlockAttrs(oldAttrsUnEsc, toChangNode)
|
||||
pushBlockAttrs(oldAttrs, toChangNode)
|
||||
}
|
||||
|
||||
for _, tree := range trees {
|
||||
|
|
@ -1546,9 +1546,9 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) {
|
|||
// updateBlock 会清空数据库角标 https://github.com/siyuan-note/siyuan/issues/16549
|
||||
go func() {
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
oldAttrsUnEsc := parse.IAL2MapUnEsc(updatedNode.KramdownIAL)
|
||||
oldAttrs := parse.IAL2Map(updatedNode.KramdownIAL)
|
||||
updatedNode.SetIALAttr(av.NodeAttrViewNames, avNames)
|
||||
pushBlockAttrs(oldAttrsUnEsc, updatedNode)
|
||||
pushBlockAttrs(oldAttrs, updatedNode)
|
||||
}()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue