-
Notifications
You must be signed in to change notification settings - Fork 372
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
feat(gnovm): forbid importing realms in packages #3042
base: master
Are you sure you want to change the base?
Changes from 37 commits
f2fb5f7
112daa1
144f4a2
29d018e
4b733e3
9f6f5cb
1f12e19
aab9d55
4fbe93d
8f61825
d2f0200
7b026d1
e26a293
91aa244
794b5a9
a54975d
da09313
d52969c
eccc2e4
a0fc9f6
0fc525c
49828e8
9af0e68
5459c2d
c92d714
fde9ddd
b28d1bd
7116ef1
90190a0
7b64799
c5512bc
ad1c8df
cf90c37
dd1bd94
21f15fe
128f7f4
530edfb
63be6b3
6081a7b
8d97af3
8f0bbc1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
module gno.land/p/demo/groups | ||
|
||
require ( | ||
gno.land/p/demo/rat v0.0.0-latest | ||
gno.land/r/demo/boards v0.0.0-latest | ||
) | ||
require gno.land/p/demo/rat v0.0.0-latest |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
import ( | ||
"fmt" | ||
"go/parser" | ||
"go/token" | ||
"regexp" | ||
"sort" | ||
"strings" | ||
|
@@ -87,6 +89,28 @@ | |
prev = file.Name | ||
} | ||
|
||
pIndex := strings.Index(mempkg.Path, "/p/") | ||
if pIndex > 0 && !strings.ContainsRune(mempkg.Path[:pIndex], '/') { | ||
for _, file := range mempkg.Files { | ||
if !strings.HasSuffix(file.Name, ".gno") { | ||
continue | ||
} | ||
fset := token.NewFileSet() | ||
astFile, err := parser.ParseFile(fset, file.Name, file.Body, parser.ImportsOnly) | ||
if err != nil { | ||
return fmt.Errorf("failed to parse imports in file %q of package %q: %w", file.Name, mempkg.Path, err) | ||
} | ||
for _, imp := range astFile.Imports { | ||
// ensure the pkg is a realm by checking if the path contains /r/ and no other / character before it (i.e protect from gno.land/p/demo/r/) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we should add a test for the case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
importPath := strings.TrimPrefix(strings.TrimSuffix(imp.Path.Value, `"`), `"`) | ||
rIndex := strings.Index(importPath, "/r/") | ||
if rIndex > 0 && !strings.ContainsRune(importPath[:rIndex], '/') { | ||
return fmt.Errorf("package %q imports realm %q", mempkg.Path, importPath) | ||
} | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
order and index do not match the actual tests below