format-patch: rfc2047-encode newlines in headers
These should generally never happen, as we already concatenate multiples in subjects into a single line. But let's be defensive, since not encoding them means we will output malformed headers. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Feb 23, 2011 at 04:59 UTC
c22e7de340df2e0ebc0e98347aa02a32a459835f
1 file changed
+2
-2
pretty.c
+2
-2
@@ -228,7 +228,7 @@ static void add_rfc2047(struct strbuf *sb, const char *line, int len,
228
229
for (i = 0; i < len; i++) {
230
int ch = line[i];
231
- if (non_ascii(ch))
231
+ if (non_ascii(ch) || ch == '\n')
232
goto needquote;
233
if ((i + 1 < len) && (ch == '=' && line[i+1] == '?'))
234
goto needquote;
@@ -254,7 +254,7 @@ needquote:
254
* many programs do not understand this and just
255
* leave the underscore in place.
256
*/
257
- if (is_rfc2047_special(ch) || ch == ' ') {
257
+ if (is_rfc2047_special(ch) || ch == ' ' || ch == '\n') {
258
strbuf_addf(sb, "=%02X", ch);
259
line_len += 3;
260
}