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 type MD map[string][]string
// New creates an MD from a given key-value map. // 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 { func New(m map[string]string) MD {
md := MD{} md := MD{}
for k, val := range m { 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 returns an MD formed by the mapping of key, value ...
// Pairs panics if len(kv) is odd. // 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 { func Pairs(kv ...string) MD {
if len(kv)%2 == 1 { if len(kv)%2 == 1 {
panic(fmt.Sprintf("metadata: Pairs got the odd number of input pairs for metadata: %d", len(kv))) panic(fmt.Sprintf("metadata: Pairs got the odd number of input pairs for metadata: %d", len(kv)))