Skip to content

Commit 90dce21

Browse files
peffgitster
authored andcommitted
remote-curl: unquote incoming push-options
The transport-helper protocol c-style quotes the value of any options passed to the helper via the "option <key> <value>" directive. However, remote-curl doesn't actually unquote the push-option values, meaning that we will send the quoted version to the other side (whereas git-over-ssh would send the raw value). The pack-protocol.txt documentation defines the push-options as a series of VCHARs, which excludes most characters that would need quoting. But: 1. You can still see the bug with a valid push-option that starts with a double-quote (since that triggers quoting). 2. We do currently handle any non-NUL characters correctly in git-over-ssh. So even though the spec does not say that we need to handle most quoted characters, it's nice if our behavior is consistent between protocols. There are two new tests: the "direct" one shows that this already works in the non-http case, and the http one covers this bugfix. Reported-by: Jon Simons <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6cdffd0 commit 90dce21

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

remote-curl.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "credential.h"
1414
#include "sha1-array.h"
1515
#include "send-pack.h"
16+
#include "quote.h"
1617

1718
static struct remote *remote;
1819
/* always ends with a trailing slash */
@@ -142,7 +143,15 @@ static int set_option(const char *name, const char *value)
142143
return -1;
143144
return 0;
144145
} else if (!strcmp(name, "push-option")) {
145-
string_list_append(&options.push_options, value);
146+
if (*value != '"')
147+
string_list_append(&options.push_options, value);
148+
else {
149+
struct strbuf unquoted = STRBUF_INIT;
150+
if (unquote_c_style(&unquoted, value, NULL) < 0)
151+
die("invalid quoting in push-option value");
152+
string_list_append_nodup(&options.push_options,
153+
strbuf_detach(&unquoted, NULL));
154+
}
146155
return 0;
147156

148157
#if LIBCURL_VERSION_NUM >= 0x070a08

t/t5545-push-options.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,15 @@ test_expect_success 'invalid push option in config' '
217217
test_refs master HEAD@{1}
218218
'
219219

220+
test_expect_success 'push options keep quoted characters intact (direct)' '
221+
mk_repo_pair &&
222+
git -C upstream config receive.advertisePushOptions true &&
223+
test_commit -C workbench one &&
224+
git -C workbench push --push-option="\"embedded quotes\"" up master &&
225+
echo "\"embedded quotes\"" >expect &&
226+
test_cmp expect upstream/.git/hooks/pre-receive.push_options
227+
'
228+
220229
. "$TEST_DIRECTORY"/lib-httpd.sh
221230
start_httpd
222231

@@ -260,6 +269,15 @@ test_expect_success 'push options work properly across http' '
260269
test_cmp expect actual
261270
'
262271

272+
test_expect_success 'push options keep quoted characters intact (http)' '
273+
mk_http_pair true &&
274+
275+
test_commit -C test_http_clone one &&
276+
git -C test_http_clone push --push-option="\"embedded quotes\"" origin master &&
277+
echo "\"embedded quotes\"" >expect &&
278+
test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/pre-receive.push_options
279+
'
280+
263281
stop_httpd
264282

265283
test_done

0 commit comments

Comments
 (0)