Skip to content

Commit

Permalink
Support '~' in label repo (#1518)
Browse files Browse the repository at this point in the history
* Support '~' in label repo

* ~ first to avoid regex range

* Everything but ~ is allowed as first letter
  • Loading branch information
mark-thm committed May 1, 2023
1 parent 824d01b commit 07882db
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion label/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ func New(repo, pkg, name string) Label {
var NoLabel = Label{}

var (
labelRepoRegexp = regexp.MustCompile(`^@$|^[A-Za-z.-][A-Za-z0-9_.-]*$`)
// This was taken from https://github.com/bazelbuild/bazel/blob/71fb1e4188b01e582a308cfe4bcbf1c730eded1b/src/main/java/com/google/devtools/build/lib/cmdline/RepositoryName.java#L159C1-L164
labelRepoRegexp = regexp.MustCompile(`^@$|^[A-Za-z0-9_.-][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
labelNameRegexp = regexp.MustCompile("^[A-Za-z0-9!%-@^_` \"#$&'()*-+,;<=>?\\[\\]{|}~/.]*$")
Expand Down
2 changes: 2 additions & 0 deletions label/label_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ func TestParse(t *testing.T) {
{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"}},
{str: "@rules_python~0.0.0~pip~name_dep//:_pkg", want: Label{Repo: "rules_python~0.0.0~pip~name_dep", Name: "_pkg"}},
{str: "@rules_python~0.0.0~pip~name//:dep_pkg", want: Label{Repo: "rules_python~0.0.0~pip~name", Name: "dep_pkg"}},
} {
got, err := Parse(tc.str)
if err != nil && !tc.wantErr {
Expand Down

0 comments on commit 07882db

Please sign in to comment.