git » chasquid » commit dea6f73

aliases: Treat empty pipe aliases as bad lines and skip them

author Alberto Bertogli
2019-10-22 21:05:52 UTC
committer Alberto Bertogli
2019-10-22 21:14:26 UTC
parent 5f72f723db84181428658f099201c0314c94b697

aliases: Treat empty pipe aliases as bad lines and skip them

A pipe alias must have a command, if it doesn't, we should treat the
line as bad and skip it like we do for others.

internal/aliases/aliases.go +4 -0
internal/aliases/aliases_test.go +4 -0

diff --git a/internal/aliases/aliases.go b/internal/aliases/aliases.go
index d20ab71..156e1d0 100644
--- a/internal/aliases/aliases.go
+++ b/internal/aliases/aliases.go
@@ -307,6 +307,10 @@ func parseReader(domain string, r io.Reader) (map[string][]Recipient, error) {
 
 		if rawalias[0] == '|' {
 			cmd := strings.TrimSpace(rawalias[1:])
+			if cmd == "" {
+				// A pipe alias without a command is invalid.
+				continue
+			}
 			aliases[addr] = []Recipient{{cmd, PIPE}}
 		} else {
 			rs := []Recipient{}
diff --git a/internal/aliases/aliases_test.go b/internal/aliases/aliases_test.go
index b25b9cc..9c778b6 100644
--- a/internal/aliases/aliases_test.go
+++ b/internal/aliases/aliases_test.go
@@ -198,6 +198,10 @@ func TestAddFile(t *testing.T) {
 
 		{"a: c@d, e@f, g\n",
 			[]Recipient{{"c@d", EMAIL}, {"e@f", EMAIL}, {"g@dom", EMAIL}}},
+
+		// Invalid pipe aliases, should be ignored.
+		{"a:|\n", []Recipient{{"a@dom", EMAIL}}},
+		{"a:| \n", []Recipient{{"a@dom", EMAIL}}},
 	}
 
 	for _, c := range cases {