From d5163d014345e3370bfa45aef8bb13ba5bd696b4 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 8 Jun 2017 05:53:39 -0700 Subject: [PATCH] Write patterns to "git grep" on stdin instead of passing them with "-e" Summary: Fixes T12807. Some shells may apparently mangle/strip UTF8 characters? Just dodge this whole problem by sending the pattern over stdin rather than actually figuring out the particulars. Related tasks, like T7339 and T5554, discuss finding broader fixes for this class of issue, and this definitely isn't exactly a fully legitimate fix, but in many cases (as here) we can reasonably just avoid the problem rather than actually fixing it, at least for a long time. Test Plan: Searched for emoji and non-emoji locally, but this worked fine (on OSX) for me before the patch too. Reviewers: chad Reviewed By: chad Maniphest Tasks: T12807 Differential Revision: https://secure.phabricator.com/D18105 --- .../conduit/DiffusionSearchQueryConduitAPIMethod.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/applications/diffusion/conduit/DiffusionSearchQueryConduitAPIMethod.php b/src/applications/diffusion/conduit/DiffusionSearchQueryConduitAPIMethod.php index e9b8f8d15e..389f931c0f 100644 --- a/src/applications/diffusion/conduit/DiffusionSearchQueryConduitAPIMethod.php +++ b/src/applications/diffusion/conduit/DiffusionSearchQueryConduitAPIMethod.php @@ -57,11 +57,14 @@ final class DiffusionSearchQueryConduitAPIMethod $results = array(); $future = $repository->getLocalCommandFuture( // NOTE: --perl-regexp is available only with libpcre compiled in. - 'grep --extended-regexp --null -n --no-color -e %s %s -- %s', - $grep, + 'grep --extended-regexp --null -n --no-color -f - %s -- %s', $drequest->getStableCommit(), $path); + // NOTE: We're writing the pattern on stdin to avoid issues with UTF8 + // being mangled by the shell. See T12807. + $future->write($grep); + $binary_pattern = '/Binary file [^:]*:(.+) matches/'; $lines = new LinesOfALargeExecFuture($future);