Specify characters allowed in metadata keys (#1299)

This commit is contained in:
Menghan Li 2017-06-12 15:05:52 -07:00 коммит произвёл GitHub
Родитель ba30de56b8
Коммит 0c68d6e2f2
1 изменённых файлов: 14 добавлений и 2 удалений

Просмотреть файл

@ -37,7 +37,13 @@ func DecodeKeyValue(k, v string) (string, string, error) {
type MD map[string][]string
// New creates an MD from a given key-value map.
// Keys are automatically converted to lowercase.
//
// Only the following ASCII characters are allowed in keys:
// - digits: 0-9
// - uppercase letters: A-Z (normalized to lower)
// - lowercase letters: a-z
// - special characters: -_.
// Uppercase letters are automatically converted to lowercase.
func New(m map[string]string) MD {
md := MD{}
for k, val := range m {
@ -49,7 +55,13 @@ func New(m map[string]string) MD {
// Pairs returns an MD formed by the mapping of key, value ...
// Pairs panics if len(kv) is odd.
// Keys are automatically converted to lowercase.
//
// Only the following ASCII characters are allowed in keys:
// - digits: 0-9
// - uppercase letters: A-Z (normalized to lower)
// - lowercase letters: a-z
// - special characters: -_.
// Uppercase letters are automatically converted to lowercase.
func Pairs(kv ...string) MD {
if len(kv)%2 == 1 {
panic(fmt.Sprintf("metadata: Pairs got the odd number of input pairs for metadata: %d", len(kv)))