Skip to content

spec: more liberal separator for repository names#425

Merged
jdolitsky merged 1 commit intoopencontainers:mainfrom
rogpeppe-contrib:002-liberal-separators
Jun 22, 2023
Merged

spec: more liberal separator for repository names#425
jdolitsky merged 1 commit intoopencontainers:mainfrom
rogpeppe-contrib:002-liberal-separators

Conversation

@rogpeppe
Copy link
Copy Markdown
Contributor

This change makes the separators consistent with the implementation in the Docker distribution here.

Relevant parts from that code:

separator = `(?:[._]|__|[-]+)`
pathComponent = alphanumeric + anyTimes(separator+alphanumeric)
remoteName = pathComponent + anyTimes(`/`+pathComponent)
namePat    = optional(domainAndPort+`/`) + remoteName

This change makes the separators consistent with the implementation in the Docker distribution
[here](https://github.com/distribution/distribution/blob/97b1d649c4938d0f608d96454d6a8326b1f96acd/reference/regexp.go#L53).

Relevant parts from that code:

```
separator = `(?:[._]|__|[-]+)`
pathComponent = alphanumeric + anyTimes(separator+alphanumeric)
remoteName = pathComponent + anyTimes(`/`+pathComponent)
namePat    = optional(domainAndPort+`/`) + remoteName
```

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
@jdolitsky jdolitsky added this to the v1.1.0 milestone Jun 22, 2023
@jdolitsky jdolitsky merged commit a738357 into opencontainers:main Jun 22, 2023
Throughout this document, `<name>` MUST match the following regular expression:

`[a-z0-9]+([._-][a-z0-9]+)*(/[a-z0-9]+([._-][a-z0-9]+)*)*`
`[a-z0-9]+([._-][a-z0-9]+)*(/[a-z0-9]+(\.|_|__|-+)[a-z0-9]+)*)*`
Copy link
Copy Markdown

@andaaron andaaron Jun 22, 2023

Choose a reason for hiding this comment

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

Is this a valid regex? Is it just me or a new parenthesis is closed without being opened?

@rogpeppe ^^

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
`[a-z0-9]+([._-][a-z0-9]+)*(/[a-z0-9]+(\.|_|__|-+)[a-z0-9]+)*)*`
`[a-z0-9]+([._-][a-z0-9]+)*(/[a-z0-9]+((\.|_|__|-+)[a-z0-9]+)*)*`

I think this might've been the intent 👀

rogpeppe added a commit to rogpeppe-contrib/oci-distribution-spec that referenced this pull request Jun 23, 2023
As pointed out by @andaaron in opencontainers#425, the regular expression
proposed there was bogus. It was actually wrong in two different ways.
Mea culpa, my apologies.

This fixes it. I wrote a few test cases to check: https://go.dev/play/p/4_iYH4Hao1-

```go
package main

import (
	"regexp"
	"testing"
)

func TestRepoPattern(t *testing.T) {
	r := regexp.MustCompile(`^[a-z0-9]+((\.|_|__|-+)[a-z0-9]+)*(/[a-z0-9]+((\.|_|__|-+)[a-z0-9]+)*)*$`)
	for _, test := range []struct {
		s    string
		want bool
	}{
		{"foo", true},
		{"foo/bar", true},
		{"foo/bar__baz", true},
		{"foo/bar___baz", false},
		{"/foo", false},
		{"foo//bar", false},
		{"foo-------b__x.com", true},
		{"foo-------b__x.com/p----x", true},
		{"foo-", false},
		{"-foo", false},
		{"foo/-bar", false},
		{"foo/bar-", false},
		{"foo-bar", true},
		{"foo----_bar", false},
		{"foo----bar_/x", false},
	} {
		if got, want := r.MatchString(test.s), test.want; got != want {
			t.Errorf("mismatch on %q; got %v want %v", test.s, got, want)
		}
	}
}
```

Ideally something like the above would be committed for CI testing
but perhaps that's a stage too far.

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
@rogpeppe rogpeppe mentioned this pull request Jun 23, 2023
jdolitsky pushed a commit that referenced this pull request Jun 23, 2023
As pointed out by @andaaron in #425, the regular expression
proposed there was bogus. It was actually wrong in two different ways.
Mea culpa, my apologies.

This fixes it. I wrote a few test cases to check: https://go.dev/play/p/4_iYH4Hao1-

```go
package main

import (
	"regexp"
	"testing"
)

func TestRepoPattern(t *testing.T) {
	r := regexp.MustCompile(`^[a-z0-9]+((\.|_|__|-+)[a-z0-9]+)*(/[a-z0-9]+((\.|_|__|-+)[a-z0-9]+)*)*$`)
	for _, test := range []struct {
		s    string
		want bool
	}{
		{"foo", true},
		{"foo/bar", true},
		{"foo/bar__baz", true},
		{"foo/bar___baz", false},
		{"/foo", false},
		{"foo//bar", false},
		{"foo-------b__x.com", true},
		{"foo-------b__x.com/p----x", true},
		{"foo-", false},
		{"-foo", false},
		{"foo/-bar", false},
		{"foo/bar-", false},
		{"foo-bar", true},
		{"foo----_bar", false},
		{"foo----bar_/x", false},
	} {
		if got, want := r.MatchString(test.s), test.want; got != want {
			t.Errorf("mismatch on %q; got %v want %v", test.s, got, want)
		}
	}
}
```

Ideally something like the above would be committed for CI testing
but perhaps that's a stage too far.

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
@jdolitsky jdolitsky mentioned this pull request Jun 27, 2023
8 tasks
@jdolitsky jdolitsky mentioned this pull request Jul 6, 2023
8 tasks
sudo-bmitch pushed a commit to sudo-bmitch/distribution-spec that referenced this pull request Aug 18, 2023
This change makes the separators consistent with the implementation in the Docker distribution
[here](https://github.com/distribution/distribution/blob/97b1d649c4938d0f608d96454d6a8326b1f96acd/reference/regexp.go#L53).

Relevant parts from that code:

```
separator = `(?:[._]|__|[-]+)`
pathComponent = alphanumeric + anyTimes(separator+alphanumeric)
remoteName = pathComponent + anyTimes(`/`+pathComponent)
namePat    = optional(domainAndPort+`/`) + remoteName
```

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
sudo-bmitch pushed a commit to sudo-bmitch/distribution-spec that referenced this pull request Aug 18, 2023
As pointed out by @andaaron in opencontainers#425, the regular expression
proposed there was bogus. It was actually wrong in two different ways.
Mea culpa, my apologies.

This fixes it. I wrote a few test cases to check: https://go.dev/play/p/4_iYH4Hao1-

```go
package main

import (
	"regexp"
	"testing"
)

func TestRepoPattern(t *testing.T) {
	r := regexp.MustCompile(`^[a-z0-9]+((\.|_|__|-+)[a-z0-9]+)*(/[a-z0-9]+((\.|_|__|-+)[a-z0-9]+)*)*$`)
	for _, test := range []struct {
		s    string
		want bool
	}{
		{"foo", true},
		{"foo/bar", true},
		{"foo/bar__baz", true},
		{"foo/bar___baz", false},
		{"/foo", false},
		{"foo//bar", false},
		{"foo-------b__x.com", true},
		{"foo-------b__x.com/p----x", true},
		{"foo-", false},
		{"-foo", false},
		{"foo/-bar", false},
		{"foo/bar-", false},
		{"foo-bar", true},
		{"foo----_bar", false},
		{"foo----bar_/x", false},
	} {
		if got, want := r.MatchString(test.s), test.want; got != want {
			t.Errorf("mismatch on %q; got %v want %v", test.s, got, want)
		}
	}
}
```

Ideally something like the above would be committed for CI testing
but perhaps that's a stage too far.

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
@sudo-bmitch sudo-bmitch mentioned this pull request Feb 1, 2024
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants