Skip to content

Commit c6b0831

Browse files
larsxschneidergitster
authored andcommitted
docs: warn about possible '=' in clean/smudge filter process values
A pathname value in a clean/smudge filter process "key=value" pair can contain the '=' character (introduced in edcc858). Make the user aware of this issue in the docs, add a corresponding test case, and fix the issue in filter process value parser of the example implementation in contrib. Signed-off-by: Lars Schneider <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a0d8b60 commit c6b0831

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

Documentation/gitattributes.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,9 @@ to filter relative to the repository root. Right after the flush packet
435435
Git sends the content split in zero or more pkt-line packets and a
436436
flush packet to terminate content. Please note, that the filter
437437
must not send any response before it received the content and the
438-
final flush packet.
438+
final flush packet. Also note that the "value" of a "key=value" pair
439+
can contain the "=" character whereas the key would never contain
440+
that character.
439441
------------------------
440442
packet: git> command=smudge
441443
packet: git> pathname=path/testfile.dat

contrib/long-running-filter/example.pl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,12 @@ sub packet_flush {
8181
packet_flush();
8282

8383
while (1) {
84-
my ($command) = packet_txt_read() =~ /^command=([^=]+)$/;
85-
my ($pathname) = packet_txt_read() =~ /^pathname=([^=]+)$/;
84+
my ($command) = packet_txt_read() =~ /^command=(.+)$/;
85+
my ($pathname) = packet_txt_read() =~ /^pathname=(.+)$/;
86+
87+
if ( $pathname eq "" ) {
88+
die "bad pathname '$pathname'";
89+
}
8690

8791
packet_bin_read();
8892

t/t0021-conversion.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ test_expect_success setup '
9191
git checkout -- test test.t test.i &&
9292
9393
echo "content-test2" >test2.o &&
94-
echo "content-test3 - filename with special characters" >"test3 '\''sq'\'',\$x.o"
94+
echo "content-test3 - filename with special characters" >"test3 '\''sq'\'',\$x=.o"
9595
'
9696

9797
script='s/^\$Id: \([0-9a-f]*\) \$/\1/p'
@@ -357,12 +357,12 @@ test_expect_success PERL 'required process filter should filter data' '
357357
cp "$TEST_ROOT/test.o" test.r &&
358358
cp "$TEST_ROOT/test2.o" test2.r &&
359359
mkdir testsubdir &&
360-
cp "$TEST_ROOT/test3 '\''sq'\'',\$x.o" "testsubdir/test3 '\''sq'\'',\$x.r" &&
360+
cp "$TEST_ROOT/test3 '\''sq'\'',\$x=.o" "testsubdir/test3 '\''sq'\'',\$x=.r" &&
361361
>test4-empty.r &&
362362
363363
S=$(file_size test.r) &&
364364
S2=$(file_size test2.r) &&
365-
S3=$(file_size "testsubdir/test3 '\''sq'\'',\$x.r") &&
365+
S3=$(file_size "testsubdir/test3 '\''sq'\'',\$x=.r") &&
366366
367367
filter_git add . &&
368368
cat >expected.log <<-EOF &&
@@ -371,7 +371,7 @@ test_expect_success PERL 'required process filter should filter data' '
371371
IN: clean test.r $S [OK] -- OUT: $S . [OK]
372372
IN: clean test2.r $S2 [OK] -- OUT: $S2 . [OK]
373373
IN: clean test4-empty.r 0 [OK] -- OUT: 0 [OK]
374-
IN: clean testsubdir/test3 '\''sq'\'',\$x.r $S3 [OK] -- OUT: $S3 . [OK]
374+
IN: clean testsubdir/test3 '\''sq'\'',\$x=.r $S3 [OK] -- OUT: $S3 . [OK]
375375
STOP
376376
EOF
377377
test_cmp_count expected.log rot13-filter.log &&
@@ -383,23 +383,23 @@ test_expect_success PERL 'required process filter should filter data' '
383383
IN: clean test.r $S [OK] -- OUT: $S . [OK]
384384
IN: clean test2.r $S2 [OK] -- OUT: $S2 . [OK]
385385
IN: clean test4-empty.r 0 [OK] -- OUT: 0 [OK]
386-
IN: clean testsubdir/test3 '\''sq'\'',\$x.r $S3 [OK] -- OUT: $S3 . [OK]
386+
IN: clean testsubdir/test3 '\''sq'\'',\$x=.r $S3 [OK] -- OUT: $S3 . [OK]
387387
IN: clean test.r $S [OK] -- OUT: $S . [OK]
388388
IN: clean test2.r $S2 [OK] -- OUT: $S2 . [OK]
389389
IN: clean test4-empty.r 0 [OK] -- OUT: 0 [OK]
390-
IN: clean testsubdir/test3 '\''sq'\'',\$x.r $S3 [OK] -- OUT: $S3 . [OK]
390+
IN: clean testsubdir/test3 '\''sq'\'',\$x=.r $S3 [OK] -- OUT: $S3 . [OK]
391391
STOP
392392
EOF
393393
test_cmp_count expected.log rot13-filter.log &&
394394
395-
rm -f test2.r "testsubdir/test3 '\''sq'\'',\$x.r" &&
395+
rm -f test2.r "testsubdir/test3 '\''sq'\'',\$x=.r" &&
396396
397397
filter_git checkout --quiet --no-progress . &&
398398
cat >expected.log <<-EOF &&
399399
START
400400
init handshake complete
401401
IN: smudge test2.r $S2 [OK] -- OUT: $S2 . [OK]
402-
IN: smudge testsubdir/test3 '\''sq'\'',\$x.r $S3 [OK] -- OUT: $S3 . [OK]
402+
IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $S3 [OK] -- OUT: $S3 . [OK]
403403
STOP
404404
EOF
405405
test_cmp_exclude_clean expected.log rot13-filter.log &&
@@ -420,14 +420,14 @@ test_expect_success PERL 'required process filter should filter data' '
420420
IN: smudge test.r $S [OK] -- OUT: $S . [OK]
421421
IN: smudge test2.r $S2 [OK] -- OUT: $S2 . [OK]
422422
IN: smudge test4-empty.r 0 [OK] -- OUT: 0 [OK]
423-
IN: smudge testsubdir/test3 '\''sq'\'',\$x.r $S3 [OK] -- OUT: $S3 . [OK]
423+
IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $S3 [OK] -- OUT: $S3 . [OK]
424424
STOP
425425
EOF
426426
test_cmp_exclude_clean expected.log rot13-filter.log &&
427427
428428
test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.r &&
429429
test_cmp_committed_rot13 "$TEST_ROOT/test2.o" test2.r &&
430-
test_cmp_committed_rot13 "$TEST_ROOT/test3 '\''sq'\'',\$x.o" "testsubdir/test3 '\''sq'\'',\$x.r"
430+
test_cmp_committed_rot13 "$TEST_ROOT/test3 '\''sq'\'',\$x=.o" "testsubdir/test3 '\''sq'\'',\$x=.r"
431431
)
432432
'
433433

t/t0021/rot13-filter.pl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,18 @@ sub packet_flush {
109109
$debug->flush();
110110

111111
while (1) {
112-
my ($command) = packet_txt_read() =~ /^command=([^=]+)$/;
112+
my ($command) = packet_txt_read() =~ /^command=(.+)$/;
113113
print $debug "IN: $command";
114114
$debug->flush();
115115

116-
my ($pathname) = packet_txt_read() =~ /^pathname=([^=]+)$/;
116+
my ($pathname) = packet_txt_read() =~ /^pathname=(.+)$/;
117117
print $debug " $pathname";
118118
$debug->flush();
119119

120+
if ( $pathname eq "" ) {
121+
die "bad pathname '$pathname'";
122+
}
123+
120124
# Flush
121125
packet_bin_read();
122126

0 commit comments

Comments
 (0)