Browse Source

- empty content-type param parsing
- fix test

flashmob 6 years ago
parent
commit
61481f174a
2 changed files with 12 additions and 3 deletions
  1. 7 0
      mail/mime/mime.go
  2. 5 3
      mail/mime/mime_test.go

+ 7 - 0
mail/mime/mime.go

@@ -135,6 +135,10 @@ func (c *contentType) params() (ret string) {
 		c.b.Reset()
 	}()
 	for k := range c.parameters {
+		if c.parameters[k] == "" {
+			c.b.WriteString("; " + k)
+			continue
+		}
 		c.b.WriteString("; " + k + "=\"" + c.parameters[k] + "\"")
 	}
 	return c.b.String()
@@ -679,6 +683,9 @@ func (p *Parser) parameter() (attribute, value string, err error) {
 		return "", "", err
 	}
 	if p.ch != '=' {
+		if len(attribute) > 0 {
+			return
+		}
 		return "", "", errors.New("expecting =")
 	}
 	p.next()

+ 5 - 3
mail/mime/mime_test.go

@@ -61,7 +61,7 @@ func TestMimeContentType(t *testing.T) {
 		<-p.consumed
 		p.gotNewSlice <- false
 	}()
-	subject := "text/plain; charset=\"us-ascii\"; boundary=\"foo\""
+	subject := "text/plain; charset=\"us-ascii\"; moo; boundary=\"foo\""
 	p.inject([]byte(subject))
 	contentType, err := p.contentType()
 	if err != nil {
@@ -491,9 +491,11 @@ func TestNonMineEmail(t *testing.T) {
 		}
 	}
 	p.Close()
+
+	// what if we pass an empty string?
 	p.inject([]byte{' '})
-	if err := p.mime(nil, ""); err != nil && err != NotMime && err != io.EOF {
-		t.Error(err)
+	if err := p.mime(nil, ""); err == nil || err == NotMime || err == io.EOF {
+		t.Error("unexpected error", err)
 	}
 
 }