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 <schnhrr@cs.tu-berlin.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jan H. Schönherr committed Oct 18, 2012 at 16:43 UTC 25dc8dad3a7c9f5426f549701e22eec1f894fec8
1 file changed +66 -32
t/t4014-format-patch.sh
+66 -32
@@ -110,73 +110,107 @@ test_expect_success 'replay did not screw up the log message' '
110
111 test_expect_success 'extra headers' '
112
113 - git config format.headers "To: R. E. Cipient <rcipient@example.com>
113 + git config format.headers "To: R E Cipient <rcipient@example.com>
114 " &&
115 - git config --add format.headers "Cc: S. E. Cipient <scipient@example.com>
115 + git config --add format.headers "Cc: S E Cipient <scipient@example.com>
116 " &&
117 git format-patch --stdout master..side > patch2 &&
118 sed -e "/^\$/q" patch2 > hdrs2 &&
119 - grep "^To: R. E. Cipient <rcipient@example.com>\$" hdrs2 &&
120 - grep "^Cc: S. E. Cipient <scipient@example.com>\$" hdrs2
119 + grep "^To: R E Cipient <rcipient@example.com>\$" hdrs2 &&
120 + grep "^Cc: S E Cipient <scipient@example.com>\$" hdrs2
121
122 '
123
124 test_expect_success 'extra headers without newlines' '
125
126 - git config --replace-all format.headers "To: R. E. Cipient <rcipient@example.com>" &&
127 - git config --add format.headers "Cc: S. E. Cipient <scipient@example.com>" &&
126 + git config --replace-all format.headers "To: R E Cipient <rcipient@example.com>" &&
127 + git config --add format.headers "Cc: S E Cipient <scipient@example.com>" &&
128 git format-patch --stdout master..side >patch3 &&
129 sed -e "/^\$/q" patch3 > hdrs3 &&
130 - grep "^To: R. E. Cipient <rcipient@example.com>\$" hdrs3 &&
131 - grep "^Cc: S. E. Cipient <scipient@example.com>\$" hdrs3
130 + grep "^To: R E Cipient <rcipient@example.com>\$" hdrs3 &&
131 + grep "^Cc: S E Cipient <scipient@example.com>\$" hdrs3
132
133 '
134
135 test_expect_success 'extra headers with multiple To:s' '
136
137 - git config --replace-all format.headers "To: R. E. Cipient <rcipient@example.com>" &&
138 - git config --add format.headers "To: S. E. Cipient <scipient@example.com>" &&
137 + git config --replace-all format.headers "To: R E Cipient <rcipient@example.com>" &&
138 + git config --add format.headers "To: S E Cipient <scipient@example.com>" &&
139 git format-patch --stdout master..side > patch4 &&
140 sed -e "/^\$/q" patch4 > hdrs4 &&
141 - grep "^To: R. E. Cipient <rcipient@example.com>,\$" hdrs4 &&
142 - grep "^ *S. E. Cipient <scipient@example.com>\$" hdrs4
141 + grep "^To: R E Cipient <rcipient@example.com>,\$" hdrs4 &&
142 + grep "^ *S E Cipient <scipient@example.com>\$" hdrs4
143 '
144
145 -test_expect_success 'additional command line cc' '
145 +test_expect_success 'additional command line cc (ascii)' '
146
147 - git config --replace-all format.headers "Cc: R. E. Cipient <rcipient@example.com>" &&
147 + git config --replace-all format.headers "Cc: R E Cipient <rcipient@example.com>" &&
148 + git format-patch --cc="S E Cipient <scipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch5 &&
149 + grep "^Cc: R E Cipient <rcipient@example.com>,\$" patch5 &&
150 + grep "^ *S E Cipient <scipient@example.com>\$" patch5
151 +'
152 +
153 +test_expect_failure 'additional command line cc (rfc822)' '
154 +
155 + git config --replace-all format.headers "Cc: R E Cipient <rcipient@example.com>" &&
156 git format-patch --cc="S. E. Cipient <scipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch5 &&
149 - grep "^Cc: R. E. Cipient <rcipient@example.com>,\$" patch5 &&
150 - grep "^ *S. E. Cipient <scipient@example.com>\$" patch5
157 + grep "^Cc: R E Cipient <rcipient@example.com>,\$" patch5 &&
158 + grep "^ *"S. E. Cipient" <scipient@example.com>\$" patch5
159 '
160
161 test_expect_success 'command line headers' '
162
163 git config --unset-all format.headers &&
156 - git format-patch --add-header="Cc: R. E. Cipient <rcipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch6 &&
157 - grep "^Cc: R. E. Cipient <rcipient@example.com>\$" patch6
164 + git format-patch --add-header="Cc: R E Cipient <rcipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch6 &&
165 + grep "^Cc: R E Cipient <rcipient@example.com>\$" patch6
166 '
167
168 test_expect_success 'configuration headers and command line headers' '
169
162 - git config --replace-all format.headers "Cc: R. E. Cipient <rcipient@example.com>" &&
163 - git format-patch --add-header="Cc: S. E. Cipient <scipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch7 &&
164 - grep "^Cc: R. E. Cipient <rcipient@example.com>,\$" patch7 &&
165 - grep "^ *S. E. Cipient <scipient@example.com>\$" patch7
170 + git config --replace-all format.headers "Cc: R E Cipient <rcipient@example.com>" &&
171 + git format-patch --add-header="Cc: S E Cipient <scipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch7 &&
172 + grep "^Cc: R E Cipient <rcipient@example.com>,\$" patch7 &&
173 + grep "^ *S E Cipient <scipient@example.com>\$" patch7
174 '
175
168 -test_expect_success 'command line To: header' '
176 +test_expect_success 'command line To: header (ascii)' '
177
178 git config --unset-all format.headers &&
179 + git format-patch --to="R E Cipient <rcipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch8 &&
180 + grep "^To: R E Cipient <rcipient@example.com>\$" patch8
181 +'
182 +
183 +test_expect_failure 'command line To: header (rfc822)' '
184 +
185 git format-patch --to="R. E. Cipient <rcipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch8 &&
172 - grep "^To: R. E. Cipient <rcipient@example.com>\$" patch8
186 + grep "^To: "R. E. Cipient" <rcipient@example.com>\$" patch8
187 +'
188 +
189 +test_expect_failure 'command line To: header (rfc2047)' '
190 +
191 + git format-patch --to="R Ä Cipient <rcipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch8 &&
192 + grep "^To: =?UTF-8?q?R=20=C3=84=20Cipient?= <rcipient@example.com>\$" patch8
193 '
194
175 -test_expect_success 'configuration To: header' '
195 +test_expect_success 'configuration To: header (ascii)' '
196 +
197 + git config format.to "R E Cipient <rcipient@example.com>" &&
198 + git format-patch --stdout master..side | sed -e "/^\$/q" >patch9 &&
199 + grep "^To: R E Cipient <rcipient@example.com>\$" patch9
200 +'
201 +
202 +test_expect_failure 'configuration To: header (rfc822)' '
203
204 git config format.to "R. E. Cipient <rcipient@example.com>" &&
205 git format-patch --stdout master..side | sed -e "/^\$/q" >patch9 &&
179 - grep "^To: R. E. Cipient <rcipient@example.com>\$" patch9
206 + grep "^To: "R. E. Cipient" <rcipient@example.com>\$" patch9
207 +'
208 +
209 +test_expect_failure 'configuration To: header (rfc2047)' '
210 +
211 + git config format.to "R Ä Cipient <rcipient@example.com>" &&
212 + git format-patch --stdout master..side | sed -e "/^\$/q" >patch9 &&
213 + grep "^To: =?UTF-8?q?R=20=C3=84=20Cipient?= <rcipient@example.com>\$" patch9
214 '
215
216 # check_patch <patch>: Verify that <patch> looks like a half-sane
@@ -190,11 +224,11 @@ check_patch () {
224 test_expect_success '--no-to overrides config.to' '
225
226 git config --replace-all format.to \
193 - "R. E. Cipient <rcipient@example.com>" &&
227 + "R E Cipient <rcipient@example.com>" &&
228 git format-patch --no-to --stdout master..side |
229 sed -e "/^\$/q" >patch10 &&
230 check_patch patch10 &&
197 - ! grep "^To: R. E. Cipient <rcipient@example.com>\$" patch10
231 + ! grep "^To: R E Cipient <rcipient@example.com>\$" patch10
232 '
233
234 test_expect_success '--no-to and --to replaces config.to' '
@@ -212,21 +246,21 @@ test_expect_success '--no-to and --to replaces config.to' '
246 test_expect_success '--no-cc overrides config.cc' '
247
248 git config --replace-all format.cc \
215 - "C. E. Cipient <rcipient@example.com>" &&
249 + "C E Cipient <rcipient@example.com>" &&
250 git format-patch --no-cc --stdout master..side |
251 sed -e "/^\$/q" >patch12 &&
252 check_patch patch12 &&
219 - ! grep "^Cc: C. E. Cipient <rcipient@example.com>\$" patch12
253 + ! grep "^Cc: C E Cipient <rcipient@example.com>\$" patch12
254 '
255
256 test_expect_success '--no-add-header overrides config.headers' '
257
258 git config --replace-all format.headers \
225 - "Header1: B. E. Cipient <rcipient@example.com>" &&
259 + "Header1: B E Cipient <rcipient@example.com>" &&
260 git format-patch --no-add-header --stdout master..side |
261 sed -e "/^\$/q" >patch13 &&
262 check_patch patch13 &&
229 - ! grep "^Header1: B. E. Cipient <rcipient@example.com>\$" patch13
263 + ! grep "^Header1: B E Cipient <rcipient@example.com>\$" patch13
264 '
265
266 test_expect_success 'multiple files' '