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

Don't exclude spaces from the label name regex #1271

Merged
merged 1 commit into from
Jun 21, 2022
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
4 changes: 1 addition & 3 deletions label/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ var (
labelRepoRegexp = regexp.MustCompile(`^@$|^[A-Za-z.-][A-Za-z0-9_.-]*$`)
labelPkgRegexp = regexp.MustCompile(`^[A-Za-z0-9/._@-]*$`)
// This was taken from https://docs.bazel.build/versions/main/build-ref.html#name
// Note: We've manually removed space from the regex, because though these technically parse
// with Bazel (and can appear in query results), they cannot actually be used in practice.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why this comment is no longer true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was never really true - I made a limiting assumption which was incorrect. bazelbuild/bazel#4327 is an issue tracking fixing gaps in this support elsewhere in Bazel, too, which is an open and accepted issue, not something closed as working as intended.

labelNameRegexp = regexp.MustCompile("^[A-Za-z0-9!%-@^_`\"#$&'()*-+,;<=>?\\[\\]{|}~/.]*$")
labelNameRegexp = regexp.MustCompile("^[A-Za-z0-9!%-@^_` \"#$&'()*-+,;<=>?\\[\\]{|}~/.]*$")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been bitten one too many times by "a small change to a regex that is trivial to visually validate". Could we add some test cases to prove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test :)

)

// Parse reads a label from a string.
Expand Down
1 change: 1 addition & 0 deletions label/label_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func TestParse(t *testing.T) {
{str: "//api_proto:api.gen.pb.go_checkshtest", want: Label{Pkg: "api_proto", Name: "api.gen.pb.go_checkshtest"}},
{str: "@go_sdk//:src/cmd/go/testdata/mod/rsc.io_!q!u!o!t!e_v1.5.2.txt", want: Label{Repo: "go_sdk", Name: "src/cmd/go/testdata/mod/rsc.io_!q!u!o!t!e_v1.5.2.txt"}},
{str: "//:a][b", want: Label{Name: "a][b"}},
{str: "//:a b", want: Label{Name: "a b"}},
} {
got, err := Parse(tc.str)
if err != nil && !tc.wantErr {
Expand Down