Skip to content

Commit 7021928

Browse files
fix doc: metadata.annotations keys should not allow spaces (#5013)
- the validation logic in app/messages/metadata_validator_helper.rb does not allow spaces in keys - added a relevant test case - fixed the examples provided in doc
1 parent 983daee commit 7021928

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

docs/v3/source/includes/concepts/_metadata.md.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ Only annotations with a prefix (e.g. `company.com/contacts`) are sent to service
3737

3838
Examples may include (but are not limited to):
3939

40-
- `"contact info": "bob@example.com jane@example.com"`
41-
- `"library versions": "Spring: 5.1, Redis Client: a184098. yaml parser: 38"`
40+
- `"contact-info": "bob@example.com jane@example.com"`
41+
- `"library-versions": "Spring: 5.1, Redis Client: a184098. yaml parser: 38"`
4242
- `"git-sha": "d56fe0367554ae5e878e37ed6c5b9a82f5995512"`
4343

4444
#### Annotation keys

spec/unit/messages/validators/metadata_validator_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ def annotations
8181
end
8282

8383
describe 'invalid keys' do
84+
context 'when the key contains a space' do
85+
let(:labels) { { 'potato mashed' => 'value' } }
86+
87+
it 'is invalid' do
88+
expect(subject).not_to be_valid
89+
expect(subject.errors_on(:metadata)).to include("label key error: 'potato mashed' contains invalid characters")
90+
end
91+
end
92+
8493
context 'when the key contains one invalid character' do
8594
# for the 32nd-126th characters, excluding the ones inside of the %r()
8695
(32.chr..126.chr).to_a.reject { |c| %r{[\w\-._/\s]}.match(c) }.each do |c|
@@ -366,6 +375,15 @@ def annotations
366375
end
367376
end
368377

378+
context 'when the annotations key contains a space' do
379+
let(:annotations) { { 'potato mashed' => 'value' } }
380+
381+
it 'is invalid' do
382+
expect(subject).not_to be_valid
383+
expect(subject.errors_on(:metadata)).to include("annotation key error: 'potato mashed' contains invalid characters")
384+
end
385+
end
386+
369387
context 'when the annotations key is an empty string' do
370388
let(:annotations) do
371389
{

0 commit comments

Comments
 (0)