Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-1.30] fix: allow special char in tag value #2247

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions pkg/azuredisk/azure_managedDiskController.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,8 @@ func (c *ManagedDiskController) CreateManagedDisk(ctx context.Context, options *
newTags[consts.CreatedByTag] = &azureDDTag
if options.Tags != nil {
for k, v := range options.Tags {
// Azure won't allow / (forward slash) in tags
newKey := strings.Replace(k, "/", "-", -1)
newValue := strings.Replace(v, "/", "-", -1)
newTags[newKey] = &newValue
value := v
newTags[k] = &value
}
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ func ConvertTagsToMap(tags string) (map[string]string, error) {
if key == "" {
return nil, fmt.Errorf("Tags '%s' are invalid, the format should like: 'key1=value1,key2=value2'", tags)
}
// <>%&?/. are not allowed in tag key
if strings.ContainsAny(key, "<>%&?/.") {
return nil, fmt.Errorf("Tag key '%s' contains invalid characters", key)
}
value := strings.TrimSpace(kv[1])
m[key] = value
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ func TestConvertTagsToMap(t *testing.T) {
expectedOutput: nil,
expectedError: true,
},
{
desc: "should return error for invalid characters in key",
tags: "key/1=value1,<bar",
expectedOutput: nil,
expectedError: true,
},
{
desc: "should return success for special characters in value",
tags: "key1=value1,key2=<>%&?/.",
expectedOutput: map[string]string{"key1": "value1", "key2": "<>%&?/."},
expectedError: false,
},
}

for i, c := range testCases {
Expand Down
Loading