Skip to content

Commit

Permalink
Correctly validate package/realm path
Browse files Browse the repository at this point in the history
  • Loading branch information
harry-hov committed Apr 9, 2024
1 parent e3de09b commit 0d5de3d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
4 changes: 1 addition & 3 deletions tm2/pkg/std/memfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ func (mempkg *MemPackage) IsEmpty() bool {
return len(mempkg.Files) == 0
}

const rePathPart = `[a-z][a-z0-9_]*`

var (
rePkgName = regexp.MustCompile(`^[a-z][a-z0-9_]*$`)
rePkgOrRlmPath = regexp.MustCompile(`gno\.land/(?:p|r)(?:/` + rePathPart + `)+`)
rePkgOrRlmPath = regexp.MustCompile(`^gno\.land\/(?:p|r)(?:\/_?[a-z]+[a-z0-9_]*)+$`)
reFileName = regexp.MustCompile(`^([a-zA-Z0-9_]*\.[a-z0-9_\.]*|LICENSE|README)$`)
)

Expand Down
28 changes: 14 additions & 14 deletions tm2/pkg/std/memfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,22 @@ func TestRePkgOrRlmPath(t *testing.T) {
{
desc: "Invalid With Underscore 1",
in: "gno.land/r/path/_",
expected: false, // fails
expected: false,
},
{
desc: "Invalid With Underscore 2",
in: "gno.land/r/path/_/_",
expected: false, // fails
expected: false,
},
{
desc: "Invalid With Underscore 3",
in: "gno.land/r/path/__/path",
expected: false, // fails
expected: false,
},
{
desc: "Invalid With Hyphen",
in: "gno.land/r/path/pa-th",
expected: false, // fails
expected: false,
},
{
desc: "Invalid x",
Expand All @@ -127,17 +127,17 @@ func TestRePkgOrRlmPath(t *testing.T) {
{
desc: "Special Character 1",
in: "gno.land/p/p@th/abc/def",
expected: false, // fails
expected: false,
},
{
desc: "Special Character 2",
in: "gno.land/p/p&th/abc/def",
expected: false, // fails
expected: false,
},
{
desc: "Special Character 3",
in: "gno.land/p/p&%$#h/abc/def",
expected: false, // fails
expected: false,
},
{
desc: "Leading Number",
Expand All @@ -152,17 +152,17 @@ func TestRePkgOrRlmPath(t *testing.T) {
{
desc: "Empty Path Part",
in: "gno.land/p/path//def",
expected: false, // fails
expected: false,
},
{
desc: "Trailing Slash",
in: "gno.land/p/path/abc/def/",
expected: false, // fails
expected: false,
},
{
desc: "Extra Slash(s)",
in: "gno.land/p/path///abc/def",
expected: false, // fails
expected: false,
},
{
desc: "Valid Long path",
Expand All @@ -172,22 +172,22 @@ func TestRePkgOrRlmPath(t *testing.T) {
{
desc: "Long Path With Special Character 1",
in: "gno.land/r/very/very/very/long/p@th",
expected: false, // fails
expected: false,
},
{
desc: "Long Path With Special Character 2",
in: "gno.land/r/very/very/v%ry/long/path",
expected: false, // fails
expected: false,
},
{
desc: "Long Path With Trailing Slash",
in: "gno.land/r/very/very/very/long/path/",
expected: false, // fails
expected: false,
},
{
desc: "Long Path With Empty Path Part",
in: "gno.land/r/very/very/very//long/path/",
expected: false, // fails
expected: false,
},
} {
t.Run(tc.desc, func(t *testing.T) {
Expand Down

0 comments on commit 0d5de3d

Please sign in to comment.