Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f5dc03d

Browse files
havvgfabpot
authored andcommitted
fix xargs pipe to work with spaces in dir names
1 parent 62f3d2a commit f5dc03d

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

src/Symfony/Component/Finder/Adapter/BsdFindAdapter.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,12 @@ protected function buildContentFiltering(Command $command, array $contains, $not
9292
// todo: avoid forking process for each $pattern by using multiple -e options
9393
$command
9494
->add('| grep -v \'^$\'')
95-
->add('| xargs grep -I')
95+
->add('| xargs -I{} grep -I')
9696
->add($expr->isCaseSensitive() ? null : '-i')
9797
->add($not ? '-L' : '-l')
98-
->add('-Ee')->arg($expr->renderPattern());
98+
->add('-Ee')->arg($expr->renderPattern())
99+
->add('{}')
100+
;
99101
}
100102
}
101103
}

src/Symfony/Component/Finder/Adapter/GnuFindAdapter.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,12 @@ protected function buildContentFiltering(Command $command, array $contains, $not
9393

9494
// todo: avoid forking process for each $pattern by using multiple -e options
9595
$command
96-
->add('| xargs -r grep -I')
96+
->add('| xargs -I{} -r grep -I')
9797
->add($expr->isCaseSensitive() ? null : '-i')
9898
->add($not ? '-L' : '-l')
99-
->add('-Ee')->arg($expr->renderPattern());
99+
->add('-Ee')->arg($expr->renderPattern())
100+
->add('{}')
101+
;
100102
}
101103
}
102104
}

src/Symfony/Component/Finder/Tests/FinderTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,11 @@ public function getTestPathData()
707707
'copy'.DIRECTORY_SEPARATOR.'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C'.DIRECTORY_SEPARATOR.'abc.dat.copy',
708708
)
709709
),
710+
array('/^with space\//', 'foobar',
711+
array(
712+
'with space'.DIRECTORY_SEPARATOR.'foo.txt',
713+
)
714+
),
710715
);
711716

712717
return $this->buildTestData($tests);

src/Symfony/Component/Finder/Tests/Fixtures/with space/foo.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)