Skip to content

Use of sub! in run_command results in spurious capture/replacement of \& sequences. #131

Closed

Description

@ksubrama

def run_command(shell_id, command, arguments = [], cmd_opts = {})

run_command performs xml.sub!(escaped_cmd, escaped_cmd.gsub(/'/, "'")) to work around a framework issue from #73 but sub looks for backreferences in the replacement string. Doing Regexp.escape on the replacement string should correct this but this seems like going around one's head to touch one's nose but I can't think of a simpler way to do it.

A real-life example of this occurring is when you pass "" anywhere in your command because it gets escaped to "" which causes & to be captured.

Activity

  1. mwrock commented on Mar 24, 2015

    @mwrock
    Member

    Hey @ksubrama do you think you could add a test for this in https://github.com/WinRb/WinRM/blob/master/spec/cmd_spec.rb ? In addition to defending from regressions it would also better illustrate your example above. Thanks!

  2. ksubrama commented on Mar 24, 2015

    @ksubrama
    Author

    Done! Let me know if this is enough. I actually found an issue with my initial implementation in the process. The current version passes all tests.

  3. ksubrama commented on Mar 26, 2015

    @ksubrama
    Author

    @mwrock =^.^=

  4. sneal commented on Mar 31, 2015

    @sneal
    Member

    Merged the PR, thanks guys.

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