Changeset 1d9734c


Ignore:
Timestamp:
01/29/12 16:07:12 (4 months ago)
Author:
mrook
Branches:
master
Children:
3286322, 9c52445
Parents:
aaec053
git-author:
Michiel Rook <mrook@…> (01/29/12 16:07:12)
git-committer:
Michiel Rook <mrook@…> (01/29/12 16:07:12)
Message:

Fixes #833 - always escape arguments when escape is set to true

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • classes/phing/tasks/system/ExecTask.php

    • Property mode changed from 100644 to 100755
    rddc113f r1d9734c  
    211211            ); 
    212212        } else if ($this->command === null) { 
    213             $this->command = (string)$this->commandline; 
     213            $this->command = Commandline::toString($this->commandline->getCommandline(), $this->escape); 
    214214        } else if ($this->commandline->getExecutable() === null) { 
    215215            //we need to escape the command only if it's specified directly 
  • classes/phing/types/Commandline.php

    • Property mode changed from 100644 to 100755
    r9ac2bee r1d9734c  
    158158     *                           and double quotes. 
    159159     */ 
    160     public static function quoteArgument($argument) { 
    161         if (strpos($argument, "\"") !== false) { 
     160    public static function quoteArgument($argument, $escape = false) { 
     161        if ($escape) { 
     162            return escapeshellarg($argument); 
     163        } elseif (strpos($argument, "\"") !== false) { 
    162164            if (strpos($argument, "'") !== false) { 
    163165                throw new BuildException("Can't handle single and double quotes in same argument"); 
     
    177179     * usable as command line arguments. 
    178180     */ 
    179     public static function toString($lines) { 
     181    public static function toString($lines, $escape = false) { 
    180182        // empty path return empty string 
    181183        if (!$lines) { 
     
    189191                $result .= ' '; 
    190192            } 
    191             $result .= self::quoteArgument($lines[$i]); 
     193            $result .= self::quoteArgument($lines[$i], $escape); 
    192194        } 
    193195        return $result; 
  • test/classes/phing/tasks/system/ExecTaskTest.php

    • Property mode changed from 100644 to 100755
    r74ddb43 r1d9734c  
    350350        $this->executeTarget(__FUNCTION__); 
    351351    } 
     352     
     353    /** 
     354     * Inspired by {@link http://www.phing.info/trac/ticket/833} 
     355     */ 
     356    public function testEscapedArg() 
     357    { 
     358        $this->executeTarget(__FUNCTION__); 
     359        $this->assertPropertyEquals('outval', 'abc$b3!SB'); 
     360    } 
    352361} 
    353362 
  • test/etc/tasks/system/ExecTest.xml

    r74ddb43 r1d9734c  
    151151        </exec> 
    152152    </target> 
     153     
     154    <target name="testEscapedArg"> 
     155        <exec executable="echo" escape="true" outputProperty="outval"> 
     156            <arg value="abc$b3!SB"/> 
     157        </exec> 
     158    </target> 
    153159 
    154160</project> 
Note: See TracChangeset for help on using the changeset viewer.