<commit_before>require "specinfra/backend/extension/ssh_su/version"
require "specinfra/backend/ssh"

module Specinfra
  module Backend
    module Extension
      module SshSu
      end
    end

    class SshSu < Ssh
      def initialize
        Specinfra.configuration.disable_sudo = true
      end

      def run_command(cmd, opt={})
        cmd = build_command(cmd)
        res = super(cmd)

        if su?
          stdout = res.instance_variable_get(:@stdout).gsub!(/\A\n/, "")

          if @example
            @example.metadata[:stdout] = stdout
          end
        end

        res
      end

      def build_command(cmd)
        cmd = super(cmd)
        if su?
          su_user = Specinfra.configuration.su_user || 'root'
          cmd = "#{su} #{su_user} -c #{cmd}"
        end
        cmd
      end

      private
      def prompt
        Specinfra.configuration.su_prompt || 'Password: '
      end<commit_msg>Fix shellescaping the command string<commit_after>require "specinfra/backend/extension/ssh_su/version"
require "specinfra/backend/ssh"

module Specinfra
  module Backend
    module Extension
      module SshSu
      end
    end

    class SshSu < Ssh
      def initialize
        Specinfra.configuration.disable_sudo = true
      end

      def run_command(cmd, opt={})
        cmd = build_command(cmd)
        res = super(cmd)

        if su?
          stdout = res.instance_variable_get(:@stdout).gsub!(/\A\n/, "")

          if @example
            @example.metadata[:stdout] = stdout
          end
        end

        res
      end

      def build_command(cmd)
        cmd = super(cmd)
        if su?
          su_user = Specinfra.configuration.su_user || 'root'
          cmd = "#{su} - #{su_user} -c #{cmd.shellescape}"
        end
        cmd
      end

      private
      def prompt
        Specinfra.configuration.su_prompt || 'Password: '
      end
{'fraction_non_alphanumeric': 0.09336870026525199, 'fraction_numerical': 0.0, 'mean_word_length': 1.7899408284023668, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4926893', 'n_tokens_mistral': 582, 'n_tokens_neox': 544, 'n_words': 131}