git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Put quotes around branch names to prevent special characters from being interpreted by the shell.

From
Jay Soffian <jaysoffian@gmail.com>
Date
Jun 7, 2010, 05:10 UTC
Message-ID
<AANLkTinZc1jiBmTJRsJXDe7A4ZAe001zJIWILGKQ8YoA@mail.gmail.com>
In-Reply-To
<20100606215505.GB6993@coredump.intra.peff.net>
On Sun, Jun 6, 2010 at 5:55 PM, Jeff King <peff@peff.net> wrote:
Show 11 quoted lines
> On Fri, Jun 04, 2010 at 11:53:20AM -0400, Benjamin C Meyer wrote:
>
>> Perforce branch names with spaces (and other special characters) were
>> causing issues.
>> [...]
>> -            details = p4Cmd("branch -o %s" % info["branch"])
>> +            details = p4Cmd("branch -o \"%s\"" % info["branch"])
>
> Won't this still fail if your branch name contains quotation marks or
> backslashes? Does python have some equivalent to perl's quotemeta to
> just shell-escape the problematic characters

from commands import mkarg mkarg(arg)

will enclose arg in single quotes if it contains none; else it will enclose arg in double quotes and backslash escape shell meta characters (any of \ $ " `).

BTW, quotemeta is technically intended for use with regular expressions, isn't it?

> (or even a way of just
> using a straight list in p4Cmd and avoiding the shell altogether)?
The subprocess module.
> I know those characters may not be common, but if we are going to quote,
> perhaps we should make it foolproof.
+1.
j.
Previous: Jeff KingNext: Ævar Arnfjörð Bjarmason
Message 3 of 6 in “Put quotes around branch names to prevent special characters from being interpreted by the shell.”
  1. Put quotes around branch names to prevent special characters from being interpreted by the shell.Benjamin C Meyer, Jun 4, 2010
  2. Jeff KingJun 6, 2010
  3. Jay SoffianJun 7, 2010
  4. Ævar Arnfjörð BjarmasonJun 7, 2010
  5. Ian Ward ComfortJun 7, 2010
  6. Jeff KingJun 7, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.