Problem/Motivation

Experimented in #3414412: [experimental] remove locale swapping.

Currently the module performs a lot of locale swapping to escape command line parameters. Symfony Process manages this seamlessly.

Proposed resolution

Switch to use Symfony Process with an array of parameters (natively) instead of escaping arguments and composing a stringed command line.

API changes

The escaping of the command line parameters is no longer executed by the module. Symfony Process is now invoked with an array of command line parameters, and each one is escaped by Symfony directly. This makes the escaping methods no longer relevant, and requires some adjustments to the parameters building and the command execution parameters.

The following code is deprecated:

  1. src/ImagemagickExecArguments::add(), for adding strings. Arrays should be added instead.
  2. src/ImagemagickExecArguments::escape(), no replacement.
  3. src/ImagemagickExecManager::PERCENTAGE_REPLACE, no replacement.
  4. src/ImagemagickExecManager::toString(), Use ::toArray() for command execution or ::toDebugString() to get a string representing the command parameters for debug purposes.
  5. src/ImagemagickExecManager::runOsShell(), use ::runProcess() instead.
  6. src/ImagemagickExecManager::escapeShellArg(), no replacement.
  7. src/Plugin/ImageToolkit/Operation/imagemagick/ImagemagickImageToolkitOperationBase::addArgument(), use ::addArguments() instead.
  8. src/Plugin/ImageToolkit/Operation/imagemagick/ImagemagickImageToolkitOperationBase::escapeArgument(), no replacement.

Modules that provide image toolkit operation plugins need to adjust their calls to building arguments, from adding strings to adding array of strings, each one being an individual command line parameter for the process execution.

Example:

Before:

    $this->addArgument(sprintf('-crop %dx%d%+d%+d +repage', $arguments['width'], $arguments['height'], $arguments['x'], $arguments['y']));

After:

    $this->addArguments([
      '-crop',
      sprintf('%dx%d%+d%+d', $arguments['width'], $arguments['height'], $arguments['x'], $arguments['y']),
      '+repage',
    ]);
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mondrake created an issue. See original summary.

mondrake’s picture

  • mondrake committed 8057b5d8 on 8.x-3.x
    Issue #3414601 by mondrake: Switch command line escaping to Symfony...
mondrake’s picture

Status: Active » Patch (to be ported)

to be ported to 4.0.x

mondrake changed the visibility of the branch 3414601-switch-command-line to hidden.

  • mondrake committed d1c7a078 on 4.0.x
    Issue #3414601 by mondrake: Switch command line escaping to Symfony...

mondrake’s picture

Status: Patch (to be ported) » Active

Some tweaks needed.

  • mondrake committed 5a12fa00 on 8.x-3.x
    Issue #3414601 by mondrake: Switch command line escaping to Symfony...

  • mondrake committed a71ad97e on 4.0.x
    Issue #3414601 by mondrake: Switch command line escaping to Symfony...

mondrake changed the visibility of the branch 3414601-II to hidden.

mondrake’s picture

Issue summary: View changes
mondrake’s picture

Issue summary: View changes
mondrake’s picture

Issue summary: View changes
Status: Active » Fixed
mondrake’s picture

Issue summary: View changes

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.