|
760 | 760 | }, |
761 | 761 | }, |
762 | 762 |
|
| 763 | + // Two consecutive boundaries - represents an empty part between them |
| 764 | + { |
| 765 | + name: "two consecutive boundaries", |
| 766 | + sep: "gc0p4Jq0M2Yt08jU534c0p", |
| 767 | + in: "--gc0p4Jq0M2Yt08jU534c0p\r\nContent-Type: text/plain\r\n\r\nfirst part\r\n--gc0p4Jq0M2Yt08jU534c0p\r\n--gc0p4Jq0M2Yt08jU534c0p\r\nContent-Type: text/html\r\n\r\nlast part\r\n--gc0p4Jq0M2Yt08jU534c0p--", |
| 768 | + want: []headerBody{ |
| 769 | + {textproto.MIMEHeader{"Content-Type": {"text/plain"}}, "first part"}, |
| 770 | + {textproto.MIMEHeader{}, ""}, // Empty part from consecutive boundaries |
| 771 | + {textproto.MIMEHeader{"Content-Type": {"text/html"}}, "last part"}, |
| 772 | + }, |
| 773 | + }, |
| 774 | + |
| 775 | + // Three consecutive boundaries - represents two empty parts |
| 776 | + { |
| 777 | + name: "three consecutive boundaries", |
| 778 | + sep: "gc0p4Jq0M2Yt08jU534c0p", |
| 779 | + in: "--gc0p4Jq0M2Yt08jU534c0p\r\n--gc0p4Jq0M2Yt08jU534c0p\r\n--gc0p4Jq0M2Yt08jU534c0p\r\nContent-Type: text/plain\r\n\r\nfinal part body\r\n--gc0p4Jq0M2Yt08jU534c0p--", |
| 780 | + want: []headerBody{ |
| 781 | + {textproto.MIMEHeader{}, ""}, // First empty part |
| 782 | + {textproto.MIMEHeader{}, ""}, // Second empty part |
| 783 | + {textproto.MIMEHeader{"Content-Type": {"text/plain"}}, "final part body"}, |
| 784 | + }, |
| 785 | + }, |
| 786 | + |
763 | 787 | roundTripParseTest(), |
764 | 788 | } |
765 | 789 |
|
@@ -853,3 +877,14 @@ func TestNoBoundary(t *testing.T) { |
853 | 877 | t.Errorf("NextPart error = %v; want %v", got, want) |
854 | 878 | } |
855 | 879 | } |
| 880 | + |
| 881 | +func TestInvalidLineAfterBoundary(t *testing.T) { |
| 882 | + testBody := "--MyBoundary\r\nThis is not a valid header line\r\n" |
| 883 | + bodyReader := strings.NewReader(testBody) |
| 884 | + reader := NewMultipartReader(bodyReader, "MyBoundary") |
| 885 | + _, err := reader.NextPart() |
| 886 | + |
| 887 | + if err == nil { |
| 888 | + t.Error("Expected an error when parsing invalid line after boundary, got nil") |
| 889 | + } |
| 890 | +} |
0 commit comments