[#744] util/attributes: Support escaped symbols

To encode attributes with semicolon or slash, use
backslash as escaped character.

Example:
  User-Agent:NeoFS\/0.23
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-08-04 12:21:40 +03:00 committed by Alex Vanin
parent c3e2738a46
commit 6527f9157c
2 changed files with 44 additions and 1 deletions

View file

@ -57,4 +57,16 @@ func TestParseV2Attributes(t *testing.T) {
require.NoError(t, err)
require.Len(t, attrs, 5)
})
t.Run("escape characters", func(t *testing.T) {
from := []string{
`/K\:ey1:V\/alue\\/Ke\/y2:Va\:lue`,
}
attrs, err := attributes.ParseV2Attributes(from, nil)
require.NoError(t, err)
require.Equal(t, attrs[0].Key(), `K:ey1`)
require.Equal(t, attrs[0].Value(), `V/alue\`)
require.Equal(t, attrs[1].Key(), `Ke/y2`)
require.Equal(t, attrs[1].Value(), `Va:lue`)
})
}