[#787] util/attributes: Restore escape characters after caching the result
As soon as resulting list and cache operate with the attribute pointer, we can add attribute structure immediately and set restored key and value of the attribute later. Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
f09b7e48af
commit
f9218bf84f
2 changed files with 11 additions and 4 deletions
|
@ -59,16 +59,16 @@ func ParseV2Attributes(attrs []string, excl []string) ([]*netmap.NodeAttribute,
|
||||||
}
|
}
|
||||||
|
|
||||||
if !present {
|
if !present {
|
||||||
|
attribute = netmap.NewNodeAttribute()
|
||||||
|
cache[key] = attribute
|
||||||
|
result = append(result, attribute)
|
||||||
|
|
||||||
// replace non-printable symbols with escaped symbols without escape character
|
// replace non-printable symbols with escaped symbols without escape character
|
||||||
key = replaceEscaping(key, true)
|
key = replaceEscaping(key, true)
|
||||||
value = replaceEscaping(value, true)
|
value = replaceEscaping(value, true)
|
||||||
|
|
||||||
attribute = netmap.NewNodeAttribute()
|
|
||||||
attribute.SetKey(key)
|
attribute.SetKey(key)
|
||||||
attribute.SetValue(value)
|
attribute.SetValue(value)
|
||||||
|
|
||||||
cache[key] = attribute
|
|
||||||
result = append(result, attribute)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if parentKey != "" {
|
if parentKey != "" {
|
||||||
|
|
|
@ -74,6 +74,13 @@ func TestParseV2Attributes(t *testing.T) {
|
||||||
attrs, err := attributes.ParseV2Attributes(from, nil)
|
attrs, err := attributes.ParseV2Attributes(from, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Len(t, attrs, 1)
|
require.Len(t, attrs, 1)
|
||||||
|
|
||||||
|
t.Run("with escape characters", func(t *testing.T) {
|
||||||
|
from = []string{`/a\::b\/`, `/a\::b\/`}
|
||||||
|
attrs, err := attributes.ParseV2Attributes(from, nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Len(t, attrs, 1)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("multiple parents", func(t *testing.T) {
|
t.Run("multiple parents", func(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue