Browse Source

Merge branch 'jk/sq-dequote-on-bogus-input'

Code to unquote single-quoted string (used in the parser for
configuration files, etc.) did not diagnose bogus input correctly
and produced bogus results instead.

* jk/sq-dequote-on-bogus-input:
  sq_dequote: fix extra consumption of source string
maint
Junio C Hamano 7 years ago
parent
commit
5aebb3e0ef
  1. 12
      quote.c
  2. 23
      t/t1300-repo-config.sh

12
quote.c

@ -118,9 +118,15 @@ static char *sq_dequote_step(char *arg, char **next) @@ -118,9 +118,15 @@ static char *sq_dequote_step(char *arg, char **next)
*next = NULL;
return arg;
case '\\':
c = *++src;
if (need_bs_quote(c) && *++src == '\'') {
*dst++ = c;
/*
* Allow backslashed characters outside of
* single-quotes only if they need escaping,
* and only if we resume the single-quoted part
* afterward.
*/
if (need_bs_quote(src[1]) && src[2] == '\'') {
*dst++ = src[1];
src += 2;
continue;
}
/* Fallthrough */

23
t/t1300-repo-config.sh

@ -1206,6 +1206,29 @@ test_expect_success 'git -c is not confused by empty environment' ' @@ -1206,6 +1206,29 @@ test_expect_success 'git -c is not confused by empty environment' '
GIT_CONFIG_PARAMETERS="" git -c x.one=1 config --list
'

sq="'"
test_expect_success 'detect bogus GIT_CONFIG_PARAMETERS' '
cat >expect <<-\EOF &&
env.one one
env.two two
EOF
GIT_CONFIG_PARAMETERS="${sq}env.one=one${sq} ${sq}env.two=two${sq}" \
git config --get-regexp "env.*" >actual &&
test_cmp expect actual &&

cat >expect <<-EOF &&
env.one one${sq}
env.two two
EOF
GIT_CONFIG_PARAMETERS="${sq}env.one=one${sq}\\$sq$sq$sq ${sq}env.two=two${sq}" \
git config --get-regexp "env.*" >actual &&
test_cmp expect actual &&

test_must_fail env \
GIT_CONFIG_PARAMETERS="${sq}env.one=one${sq}\\$sq ${sq}env.two=two${sq}" \
git config --get-regexp "env.*"
'

test_expect_success 'git config --edit works' '
git config -f tmp test.value no &&
echo test.value=yes >expect &&

Loading…
Cancel
Save