fix: caplet code is loaded entirely and comments are only skipped while evaluating it

This commit is contained in:
evilsocket 2019-03-24 01:21:27 +01:00
parent bf8a7659b5
commit 08d85251dd
No known key found for this signature in database
GPG key ID: 1564D7F30393A456
2 changed files with 4 additions and 3 deletions

View file

@ -44,6 +44,10 @@ func (cap *Caplet) Eval(argv []string, lineCb func(line string) error) error {
// temporarily change the working directory // temporarily change the working directory
return fs.Chdir(filepath.Dir(cap.Path), func() error { return fs.Chdir(filepath.Dir(cap.Path), func() error {
for _, line := range cap.Code { for _, line := range cap.Code {
// skip empty lines and comments
if line == "" || line[0] == '#' {
continue
}
// replace $0 with argv[0], $1 with argv[1] and so on // replace $0 with argv[0], $1 with argv[1] and so on
for i, arg := range argv { for i, arg := range argv {
what := fmt.Sprintf("$%d", i) what := fmt.Sprintf("$%d", i)

View file

@ -79,9 +79,6 @@ func Load(name string) (error, *Caplet) {
return fmt.Errorf("error reading caplet %s: %v", fileName, err), nil return fmt.Errorf("error reading caplet %s: %v", fileName, err), nil
} else { } else {
for line := range reader { for line := range reader {
if line == "" || line[0] == '#' {
continue
}
cap.Code = append(cap.Code, line) cap.Code = append(cap.Code, line)
} }