Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tenant run command, argument with spaces not work #1279

Open
galliroberto opened this issue Dec 30, 2024 · 0 comments
Open

Tenant run command, argument with spaces not work #1279

galliroberto opened this issue Dec 30, 2024 · 0 comments
Assignees
Labels
bug Something isn't working v4

Comments

@galliroberto
Copy link

Bug description

Run tenant aware command with argument with spaces is broken.

artisan tenants:run "make:company-plugin-resource user 'change email request'" --tenants=01JG6F1TDYG9075VK6H52WZ9QE

-tokens: array:5 [
  0 => "make:company-plugin-resource"
  1 => "user"
  2 => "'change"
  3 => "email"
  4 => "request'"
]

It splits into many arguments

this fix it

// Convert string command to array
$subCommand = $this->explodeIgnoringQuotes($commandName);

function explodeIgnoringQuotes($input) {
      preg_match_all('/[^\s"\']+|"(.*?)"|\'(.*?)\'|`(.*?)`/', $input, $matches);

      $result = array_map(function ($match) {
          return trim($match, "\"'`");
      }, array_filter(array_merge($matches[0])));

      return $result;
  }

With this it works with:

  • single quote (artisan tenants:run "make:company-plugin-resource user 'change email request'" --tenants=01JG6F1TDYG9075VK6H52WZ9QE)
  • double quote (artisan tenants:run 'make:company-plugin-resource user "change email request"' --tenants=01JG6F1TDYG9075VK6H52WZ9QE)
  • no quote (artisan tenants:run 'make:company-plugin-resource user XYZ' --tenants=01JG6F1TDYG9075VK6H52WZ9QE)

Steps to reproduce

Run a command with argument with space

artisan tenants:run "make:company-plugin-resource user 'change email request'" --tenants=01JG6F1TDYG9075VK6H52WZ9QE

artisan tenants:run 'make:company-plugin-resource user "change email request"' --tenants=01JG6F1TDYG9075VK6H52WZ9QE

Expected behavior

Run command with the right arguments

Laravel version

8.4

stancl/tenancy version

dev-master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working v4
Projects
None yet
Development

No branches or pull requests

2 participants