Skip to content

rtk rewrite leaves a bash -c script unrewritten when escaped double quotes hold RTK_DISABLED= as data #5175

Open

Description

@KuSh

rtk rewrite does not rewrite a bash -c "…" script when a double-quoted assignment inside it holds RTK_DISABLED= as data in escaped double quotes. The same script with the data in single quotes is rewritten.

Reproduction

export LC_ALL=C

rtk rewrite "bash -c \"MSG='use RTK_DISABLED=1'; git status\""
# bash -c "MSG='use RTK_DISABLED=1'; rtk git status"     (rc 3, rewritten)

rtk rewrite 'bash -c "MSG=\"use RTK_DISABLED=1\"; git status"'
# (nothing, rc 1)                                          <- not rewritten

Built from develop at 3ab08be with #5100 applied.

Mechanism

shell_wrapper_script_opts_out in src/discover/registry.rs reads the script from its raw text, before the outer double quotes are unescaped. In MSG=\"use RTK_DISABLED=1\"; git status the \" pairs are escaped characters outside any quote, so word_end_from splits the value at its blanks and the word RTK_DISABLED=1\"; starts with RTK_DISABLED=. The wrapper is taken as opted out.

Effect

Conservative: nothing is wrongly rewritten, the command runs as typed, and its output is not filtered. The cost is the lost savings for that shape.

Open question

Reading the script after its outer quotes are resolved would give both quoting depths the same words. I am offering the work, not asking anyone to take it on.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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