Skip to content

Commit

Permalink
feat: forbid importing '/r' from '/p'
Browse files Browse the repository at this point in the history
  • Loading branch information
harry-hov committed Nov 26, 2023
1 parent 8e2386a commit b9682dc
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions gnovm/pkg/gnolang/go2gno.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func MustParseExpr(expr string) Expr {
}

// filename must not include the path.
// Here?
func ParseFile(filename string, body string) (fn *FileNode, err error) {
// Parse src but stop after processing the imports.
fs := token.NewFileSet()
Expand Down
1 change: 1 addition & 0 deletions gnovm/pkg/gnolang/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,7 @@ func PrecompileMemPackage(memPkg *std.MemPackage) error {
}

// Returns the code fileset minus any spurious or test files.
// Here?
func ParseMemPackage(memPkg *std.MemPackage) (fset *FileSet) {
fset = &FileSet{}
for _, mfile := range memPkg.Files {
Expand Down
1 change: 1 addition & 0 deletions gnovm/pkg/gnolang/precompile.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func GetPrecompileFilenameAndTags(gnoFilePath string) (targetFilename, tags stri
return
}

// Here?
func PrecompileAndCheckMempkg(mempkg *std.MemPackage) error {
gofmt := "gofmt"

Expand Down
10 changes: 10 additions & 0 deletions gnovm/pkg/gnomod/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ func (f *File) Validate() error {
return errors.New("requires module")
}

isRealmPath := gnolang.IsRealmPath(f.Module.Mod.Path)
if !isRealmPath {
for _, req := range f.Require {
if gnolang.IsRealmPath(req.Mod.Path) {
return fmt.Errorf("package %s imports %s (pure packages cannot import realm directly)",
f.Module.Mod.Path, req.Mod.Path)
}

Check warning on line 142 in gnovm/pkg/gnomod/file.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnomod/file.go#L140-L142

Added lines #L140 - L142 were not covered by tests
}
}

return nil
}

Expand Down
1 change: 1 addition & 0 deletions tm2/pkg/std/memfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const (
// path must not contain any dots after the first domain component.
// file names must contain dots.
// NOTE: this is to prevent conflicts with nested paths.
// Here?
func (mempkg *MemPackage) Validate() error {
ok, _ := regexp.MatchString(rePkgName, mempkg.Name)
if !ok {
Expand Down

0 comments on commit b9682dc

Please sign in to comment.