Skip to content

Regression: empty argument in ExecTask cannot be escaped #1839

@lpd-au

Description

@lpd-au

Describe the bug
With Phing 2 it was possible to do this:

<target name="echo-old">
	<exec command="echo foo '' bar" passthru="true" />
</target>
<target name="php-old">
	<exec command="php -r 'var_dump($argv);' foo '' bar" passthru="true" />
</target>

This produced:

echo-old: foo  bar                                # Note: two spaces
php-old: array(4) {
  [0]=>
  string(19) "Standard input code"
  [1]=>
  string(3) "foo"
  [2]=>
  string(0) ""                                    # Note: length 0
  [3]=>
  string(3) "bar"
}

The documentation says it should still be possible with Phing 3:

To pass an empty argument, enclose two double quotes in single quotes ('""').

However, this produces a literal "" with any value of escape (including none); I cannot find a combination of attributes that produces the same behaviour as before.

Steps To Reproduce

<target name="echo">
	<exec executable="echo" passthru="true">
		<arg value="foo" />
		<arg value='""' />
		<arg value="bar" />
	</exec>
</target>
<target name="php">
	<exec executable="php" passthru="true">
		<arg value="-r" />
		<arg value="var_dump($argv);" escape="true" />
		<arg value="foo" />
		<arg value='""' />
		<arg value="bar" />
	</exec>
</target>

Expected behavior

echo: foo  bar
php: array(4) {
  [0]=>
  string(19) "Standard input code"
  [1]=>
  string(3) "foo"
  [2]=>
  string(0) ""
  [3]=>
  string(3) "bar"
}

Screenshots / terminal output

echo: foo "" bar
php: sh: 1: Syntax error: "(" unexpected
     [exec] Result: 2

Additional context
Replacing the inline php with a file still outputs a non-zero length string:

php-file: array(4) {
  [0]=>
  string(8) "test.php"
  [1]=>
  string(3) "foo"
  [2]=>
  string(2) """"
  [3]=>
  string(3) "bar"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions