Skip to content

Commit 65cdb18

Browse files
ankitpatel96mx-psi
andauthored
Add length limit to component (#9901)
Changes component.Type validation regex to only allow a max of 63 characters in a type name. Fixes #9872 --------- Co-authored-by: Pablo Baeyens <[email protected]>
1 parent de3ef01 commit 65cdb18

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: breaking
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: component
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Restricts maximum length for `component.Type` to 63 characters.
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [9872]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# Optional: The change log or logs in which this entry should be included.
21+
# e.g. '[user]' or '[user, api]'
22+
# Include 'user' if the change is relevant to end users.
23+
# Include 'api' if there is a change to a library API.
24+
# Default: '[user]'
25+
change_logs: ['api']

cmd/mdatagen/validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (md *metadata) Validate() error {
3535
// can only contain ASCII alphanumeric characters and '_'.
3636
// We allow '/' for subcomponents.
3737
// This must be kept in sync with the regex in component/config.go.
38-
var typeRegexp = regexp.MustCompile(`^[a-zA-Z][0-9a-zA-Z_]*$`)
38+
var typeRegexp = regexp.MustCompile(`^[a-zA-Z][0-9a-zA-Z_]{0,62}$`)
3939

4040
func (md *metadata) validateType() error {
4141
if md.Type == "" {

component/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func (t Type) MarshalText() ([]byte, error) {
128128
// A type must start with an ASCII alphabetic character and
129129
// can only contain ASCII alphanumeric characters and '_'.
130130
// This must be kept in sync with the regex in cmd/mdatagen/validate.go.
131-
var typeRegexp = regexp.MustCompile(`^[a-zA-Z][0-9a-zA-Z_]*$`)
131+
var typeRegexp = regexp.MustCompile(`^[a-zA-Z][0-9a-zA-Z_]{0,62}$`)
132132

133133
// NewType creates a type. It returns an error if the type is invalid.
134134
// A type must

component/config_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"errors"
88
"fmt"
99
"reflect"
10+
"strings"
1011
"testing"
1112

1213
"github.com/stretchr/testify/assert"
@@ -397,6 +398,7 @@ func TestNewType(t *testing.T) {
397398
{name: "zipkin_encoding"},
398399
{name: "zookeeper"},
399400
{name: "zpages"},
401+
{name: strings.Repeat("a", 63)},
400402

401403
{name: "", shouldErr: true},
402404
{name: "contains spaces", shouldErr: true},
@@ -405,6 +407,7 @@ func TestNewType(t *testing.T) {
405407
{name: "contains/slash", shouldErr: true},
406408
{name: "contains:colon", shouldErr: true},
407409
{name: "contains#hash", shouldErr: true},
410+
{name: strings.Repeat("a", 64), shouldErr: true},
408411
}
409412

410413
for _, tt := range tests {

0 commit comments

Comments
 (0)