Skip to content

Commit 25dc8da

Browse files
Jan H. Schönherrgitster
authored andcommitted
format-patch tests: check quoting/encoding in To: and Cc: headers
git-format-patch does currently not parse user supplied extra header values (e. g., --cc, --add-header) and just replays them. That forces users to add them RFC 2822/2047 conform in encoded form, e.g. --cc '=?UTF-8?q?Jan=20H=2E=20Sch=C3=B6nherr?= <...>' which is inconvenient. We would want to update git-format-patch to accept human-readable input --cc 'Jan H. Schönherr <...>' and handle the encoding, wrapping and quoting internally in the future, similar to what is already done in git-send-email. The necessary code should mostly exist in the code paths that handle the From: and Subject: headers. Whether we want to do this only for the git-format-patch options --to and --cc (and the corresponding config options) or also for user supplied headers via --add-header, is open for discussion. For now, add test_expect_failure tests for To: and Cc: headers as a reminder and fix tests that would otherwise fail should this get implemented. Signed-off-by: Jan H. Schönherr <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 41dd00b commit 25dc8da

File tree

1 file changed

+66
-32
lines changed

1 file changed

+66
-32
lines changed

t/t4014-format-patch.sh

Lines changed: 66 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -110,73 +110,107 @@ test_expect_success 'replay did not screw up the log message' '
110110

111111
test_expect_success 'extra headers' '
112112
113-
git config format.headers "To: R. E. Cipient <[email protected]>
113+
git config format.headers "To: R E Cipient <[email protected]>
114114
" &&
115-
git config --add format.headers "Cc: S. E. Cipient <[email protected]>
115+
git config --add format.headers "Cc: S E Cipient <[email protected]>
116116
" &&
117117
git format-patch --stdout master..side > patch2 &&
118118
sed -e "/^\$/q" patch2 > hdrs2 &&
119-
grep "^To: R. E. Cipient <[email protected]>\$" hdrs2 &&
120-
grep "^Cc: S. E. Cipient <[email protected]>\$" hdrs2
119+
grep "^To: R E Cipient <[email protected]>\$" hdrs2 &&
120+
grep "^Cc: S E Cipient <[email protected]>\$" hdrs2
121121
122122
'
123123

124124
test_expect_success 'extra headers without newlines' '
125125
126-
git config --replace-all format.headers "To: R. E. Cipient <[email protected]>" &&
127-
git config --add format.headers "Cc: S. E. Cipient <[email protected]>" &&
126+
git config --replace-all format.headers "To: R E Cipient <[email protected]>" &&
127+
git config --add format.headers "Cc: S E Cipient <[email protected]>" &&
128128
git format-patch --stdout master..side >patch3 &&
129129
sed -e "/^\$/q" patch3 > hdrs3 &&
130-
grep "^To: R. E. Cipient <[email protected]>\$" hdrs3 &&
131-
grep "^Cc: S. E. Cipient <[email protected]>\$" hdrs3
130+
grep "^To: R E Cipient <[email protected]>\$" hdrs3 &&
131+
grep "^Cc: S E Cipient <[email protected]>\$" hdrs3
132132
133133
'
134134

135135
test_expect_success 'extra headers with multiple To:s' '
136136
137-
git config --replace-all format.headers "To: R. E. Cipient <[email protected]>" &&
138-
git config --add format.headers "To: S. E. Cipient <[email protected]>" &&
137+
git config --replace-all format.headers "To: R E Cipient <[email protected]>" &&
138+
git config --add format.headers "To: S E Cipient <[email protected]>" &&
139139
git format-patch --stdout master..side > patch4 &&
140140
sed -e "/^\$/q" patch4 > hdrs4 &&
141-
grep "^To: R. E. Cipient <[email protected]>,\$" hdrs4 &&
142-
grep "^ *S. E. Cipient <[email protected]>\$" hdrs4
141+
grep "^To: R E Cipient <[email protected]>,\$" hdrs4 &&
142+
grep "^ *S E Cipient <[email protected]>\$" hdrs4
143143
'
144144

145-
test_expect_success 'additional command line cc' '
145+
test_expect_success 'additional command line cc (ascii)' '
146146
147-
git config --replace-all format.headers "Cc: R. E. Cipient <[email protected]>" &&
147+
git config --replace-all format.headers "Cc: R E Cipient <[email protected]>" &&
148+
git format-patch --cc="S E Cipient <[email protected]>" --stdout master..side | sed -e "/^\$/q" >patch5 &&
149+
grep "^Cc: R E Cipient <[email protected]>,\$" patch5 &&
150+
grep "^ *S E Cipient <[email protected]>\$" patch5
151+
'
152+
153+
test_expect_failure 'additional command line cc (rfc822)' '
154+
155+
git config --replace-all format.headers "Cc: R E Cipient <[email protected]>" &&
148156
git format-patch --cc="S. E. Cipient <[email protected]>" --stdout master..side | sed -e "/^\$/q" >patch5 &&
149-
grep "^Cc: R. E. Cipient <[email protected]>,\$" patch5 &&
150-
grep "^ *S. E. Cipient <[email protected]>\$" patch5
157+
grep "^Cc: R E Cipient <[email protected]>,\$" patch5 &&
158+
grep "^ *"S. E. Cipient" <[email protected]>\$" patch5
151159
'
152160

153161
test_expect_success 'command line headers' '
154162
155163
git config --unset-all format.headers &&
156-
git format-patch --add-header="Cc: R. E. Cipient <[email protected]>" --stdout master..side | sed -e "/^\$/q" >patch6 &&
157-
grep "^Cc: R. E. Cipient <[email protected]>\$" patch6
164+
git format-patch --add-header="Cc: R E Cipient <[email protected]>" --stdout master..side | sed -e "/^\$/q" >patch6 &&
165+
grep "^Cc: R E Cipient <[email protected]>\$" patch6
158166
'
159167

160168
test_expect_success 'configuration headers and command line headers' '
161169
162-
git config --replace-all format.headers "Cc: R. E. Cipient <[email protected]>" &&
163-
git format-patch --add-header="Cc: S. E. Cipient <[email protected]>" --stdout master..side | sed -e "/^\$/q" >patch7 &&
164-
grep "^Cc: R. E. Cipient <[email protected]>,\$" patch7 &&
165-
grep "^ *S. E. Cipient <[email protected]>\$" patch7
170+
git config --replace-all format.headers "Cc: R E Cipient <[email protected]>" &&
171+
git format-patch --add-header="Cc: S E Cipient <[email protected]>" --stdout master..side | sed -e "/^\$/q" >patch7 &&
172+
grep "^Cc: R E Cipient <[email protected]>,\$" patch7 &&
173+
grep "^ *S E Cipient <[email protected]>\$" patch7
166174
'
167175

168-
test_expect_success 'command line To: header' '
176+
test_expect_success 'command line To: header (ascii)' '
169177
170178
git config --unset-all format.headers &&
179+
git format-patch --to="R E Cipient <[email protected]>" --stdout master..side | sed -e "/^\$/q" >patch8 &&
180+
grep "^To: R E Cipient <[email protected]>\$" patch8
181+
'
182+
183+
test_expect_failure 'command line To: header (rfc822)' '
184+
171185
git format-patch --to="R. E. Cipient <[email protected]>" --stdout master..side | sed -e "/^\$/q" >patch8 &&
172-
grep "^To: R. E. Cipient <[email protected]>\$" patch8
186+
grep "^To: "R. E. Cipient" <[email protected]>\$" patch8
187+
'
188+
189+
test_expect_failure 'command line To: header (rfc2047)' '
190+
191+
git format-patch --to="R Ä Cipient <[email protected]>" --stdout master..side | sed -e "/^\$/q" >patch8 &&
192+
grep "^To: =?UTF-8?q?R=20=C3=84=20Cipient?= <[email protected]>\$" patch8
173193
'
174194

175-
test_expect_success 'configuration To: header' '
195+
test_expect_success 'configuration To: header (ascii)' '
196+
197+
git config format.to "R E Cipient <[email protected]>" &&
198+
git format-patch --stdout master..side | sed -e "/^\$/q" >patch9 &&
199+
grep "^To: R E Cipient <[email protected]>\$" patch9
200+
'
201+
202+
test_expect_failure 'configuration To: header (rfc822)' '
176203
177204
git config format.to "R. E. Cipient <[email protected]>" &&
178205
git format-patch --stdout master..side | sed -e "/^\$/q" >patch9 &&
179-
grep "^To: R. E. Cipient <[email protected]>\$" patch9
206+
grep "^To: "R. E. Cipient" <[email protected]>\$" patch9
207+
'
208+
209+
test_expect_failure 'configuration To: header (rfc2047)' '
210+
211+
git config format.to "R Ä Cipient <[email protected]>" &&
212+
git format-patch --stdout master..side | sed -e "/^\$/q" >patch9 &&
213+
grep "^To: =?UTF-8?q?R=20=C3=84=20Cipient?= <[email protected]>\$" patch9
180214
'
181215

182216
# check_patch <patch>: Verify that <patch> looks like a half-sane
@@ -190,11 +224,11 @@ check_patch () {
190224
test_expect_success '--no-to overrides config.to' '
191225
192226
git config --replace-all format.to \
193-
"R. E. Cipient <[email protected]>" &&
227+
"R E Cipient <[email protected]>" &&
194228
git format-patch --no-to --stdout master..side |
195229
sed -e "/^\$/q" >patch10 &&
196230
check_patch patch10 &&
197-
! grep "^To: R. E. Cipient <[email protected]>\$" patch10
231+
! grep "^To: R E Cipient <[email protected]>\$" patch10
198232
'
199233

200234
test_expect_success '--no-to and --to replaces config.to' '
@@ -212,21 +246,21 @@ test_expect_success '--no-to and --to replaces config.to' '
212246
test_expect_success '--no-cc overrides config.cc' '
213247
214248
git config --replace-all format.cc \
215-
"C. E. Cipient <[email protected]>" &&
249+
"C E Cipient <[email protected]>" &&
216250
git format-patch --no-cc --stdout master..side |
217251
sed -e "/^\$/q" >patch12 &&
218252
check_patch patch12 &&
219-
! grep "^Cc: C. E. Cipient <[email protected]>\$" patch12
253+
! grep "^Cc: C E Cipient <[email protected]>\$" patch12
220254
'
221255

222256
test_expect_success '--no-add-header overrides config.headers' '
223257
224258
git config --replace-all format.headers \
225-
"Header1: B. E. Cipient <[email protected]>" &&
259+
"Header1: B E Cipient <[email protected]>" &&
226260
git format-patch --no-add-header --stdout master..side |
227261
sed -e "/^\$/q" >patch13 &&
228262
check_patch patch13 &&
229-
! grep "^Header1: B. E. Cipient <[email protected]>\$" patch13
263+
! grep "^Header1: B E Cipient <[email protected]>\$" patch13
230264
'
231265

232266
test_expect_success 'multiple files' '

0 commit comments

Comments
 (0)