Skip to content

Allow applications to opt out of shell-style backslash escaping #88

Description

@h3zh1

Thank you for creating and maintaining this project.

Problem

line.Parse parses and reprints the input with mvdan.cc/sh/v3/syntax, then calls shellquote.Split. As a result, unquoted backslashes are interpreted as shell escape characters.

For example:

ls C:\Windows\Temp

is passed to Cobra as:

[]string{"ls", "C:WindowsTemp"}

instead of:

[]string{"ls", `C:\Windows\Temp`}

With the current parser, users must instead quote the entire value, as in ls 'C:\Windows\Temp', or escape every backslash, as in ls C:\\Windows\\Temp. Both forms work, but they are cumbersome when arguments are intended to be passed to Cobra literally.

If the value ends in a backslash, such as ls C:\Windows\Temp\, AcceptMultiline also treats the input as incomplete and waits for another line.

Quoting the value or doubling every backslash works, but is inconvenient when the console is used as a general Cobra frontend rather than as a shell.

Request

Would you consider exposing a configurable execution parser, or providing a mode that preserves literal backslashes?

The current shell-compatible behavior could remain the default. Applications should be able to select matching parsing and line-completeness semantics so that a trailing literal backslash is not always treated as a continuation marker.

cmd/internal/quoted.Split could be one
implementation option for a literal-backslash mode, although it is an internal package and
multiline detection would still need to be handled separately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions