pytest-dev/pytest-testinfra

Incompatible arg quoting in windows

Open

#375 aberto em 17 de set. de 2018

Ver no GitHub
 (0 comments) (2 reactions) (0 assignees)Python (318 forks)batch import
help wantedwindows

Métricas do repositório

Stars
 (2.156 stars)
Métricas de merge de PR
 (Mesclagem média 87d 19h) (6 fundiu PRs em 30d)

Description

When running command with 1+ arguments against a docker host, the command automatically fails with line 1: syntax error: unterminated quoted string. The is because the quote method in backend/base.py is using pipes.quote (which is only compatible with posix systems) to generate quotes, and sometimes uses single quotes to enclose an arg. The default shell in windows is cmd, which does not accept single quoted args (only double quoted). On windows, a more accurate command would be something like this:

@staticmethod
def quote(command, *args):
    def anon_1(arg):
        if re.match(r'/("|\s|\')', arg) != None:
            return arg

        arg = re.sub('"', '\"', arg)
        return '"%s"' % (arg)

    if args:
        return command % tuple(anon_1(a) for a in args)
        # return command % tuple(pipes.quote(a) for a in args)
    return command

Guia do colaborador