phingofficial /
phing
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||
| 5 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||
| 6 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||
| 7 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||
| 8 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||
| 9 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||
| 10 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
| 11 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
| 12 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
| 13 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||
| 14 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
| 15 | * |
||
| 16 | * This software consists of voluntary contributions made by many individuals |
||
| 17 | * and is licensed under the LGPL. For more information please see |
||
| 18 | * <http://phing.info>. |
||
| 19 | */ |
||
| 20 | |||
| 21 | namespace Phing\Mapper; |
||
| 22 | |||
| 23 | use Phing\Exception\BuildException; |
||
| 24 | use Phing\Util\StringHelper; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Uses glob patterns to perform filename transformations. |
||
| 28 | * |
||
| 29 | * @author Andreas Aderhold, [email protected] |
||
| 30 | */ |
||
| 31 | class GlobMapper implements FileNameMapper |
||
| 32 | { |
||
| 33 | /** |
||
| 34 | * Part of "from" pattern before the <code>.*</code>. |
||
| 35 | * |
||
| 36 | * @var string |
||
| 37 | */ |
||
| 38 | private $fromPrefix; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Part of "from" pattern after the <code>.*</code>. |
||
| 42 | * |
||
| 43 | * @var string |
||
| 44 | */ |
||
| 45 | private $fromPostfix; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Length of the prefix ("from" pattern). |
||
| 49 | * |
||
| 50 | * @var int |
||
| 51 | */ |
||
| 52 | private $prefixLength; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Length of the postfix ("from" pattern). |
||
| 56 | * |
||
| 57 | * @var int |
||
| 58 | */ |
||
| 59 | private $postfixLength; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Part of "to" pattern before the <code>*.</code>. |
||
| 63 | * |
||
| 64 | * @var string |
||
| 65 | */ |
||
| 66 | private $toPrefix; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Part of "to" pattern after the <code>*.</code>. |
||
| 70 | * |
||
| 71 | * @var string |
||
| 72 | */ |
||
| 73 | private $toPostfix; |
||
| 74 | |||
| 75 | private $fromContainsStar = false; |
||
| 76 | private $toContainsStar = false; |
||
| 77 | private $handleDirSep = false; |
||
| 78 | private $caseSensitive = true; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Attribute specifying whether to ignore the difference |
||
| 82 | * between / and \ (the two common directory characters). |
||
| 83 | * |
||
| 84 | * @param bool $handleDirSep a boolean, default is false |
||
| 85 | */ |
||
| 86 | public function setHandleDirSep($handleDirSep) |
||
| 87 | { |
||
| 88 | $this->handleDirSep = $handleDirSep; |
||
| 89 | } |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Attribute specifying whether to ignore the difference |
||
| 93 | * between / and \ (the two common directory characters). |
||
| 94 | */ |
||
| 95 | public function getHandleDirSep() |
||
| 96 | { |
||
| 97 | return $this->handleDirSep; |
||
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Attribute specifying whether to ignore the case difference |
||
| 102 | * in the names. |
||
| 103 | * |
||
| 104 | * @param bool $caseSensitive a boolean, default is false |
||
| 105 | */ |
||
| 106 | public function setCaseSensitive($caseSensitive) |
||
| 107 | { |
||
| 108 | $this->caseSensitive = $caseSensitive; |
||
| 109 | } |
||
| 110 | |||
| 111 | /** |
||
| 112 | * {@inheritdoc} |
||
| 113 | * |
||
| 114 | * @return null|array |
||
| 115 | */ |
||
| 116 | 7 | public function main($sourceFileName) |
|
| 117 | { |
||
| 118 | 7 | $modName = $this->modifyName($sourceFileName); |
|
| 119 | if ( |
||
| 120 | 7 | null === $this->fromPrefix |
|
| 121 | 7 | || (strlen($sourceFileName) < ($this->prefixLength + $this->postfixLength) |
|
| 122 | 7 | || (!$this->fromContainsStar |
|
| 123 | 7 | && !$modName === $this->modifyName($this->fromPrefix))) |
|
| 124 | 7 | || ($this->fromContainsStar |
|
| 125 | 7 | && (!StringHelper::startsWith($this->modifyName($this->fromPrefix), $modName) |
|
| 126 | 7 | || !StringHelper::endsWith($this->modifyName($this->fromPostfix), $modName))) |
|
| 127 | ) { |
||
| 128 | 3 | return null; |
|
| 129 | } |
||
| 130 | |||
| 131 | 7 | return [ |
|
| 132 | 7 | $this->toPrefix . ( |
|
| 133 | 7 | $this->toContainsStar |
|
| 134 | 7 | ? $this->extractVariablePart($sourceFileName) . $this->toPostfix |
|
| 135 | 7 | : '' |
|
| 136 | 7 | ), |
|
| 137 | 7 | ]; |
|
| 138 | } |
||
| 139 | |||
| 140 | /** |
||
| 141 | * {@inheritdoc} |
||
| 142 | * |
||
| 143 | * @param string $from |
||
| 144 | */ |
||
| 145 | 7 | public function setFrom($from) |
|
| 146 | { |
||
| 147 | 7 | if (null === $from) { |
|
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 148 | throw new BuildException("this mapper requires a 'from' attribute"); |
||
| 149 | } |
||
| 150 | |||
| 151 | 7 | $index = strrpos($from, '*'); |
|
| 152 | |||
| 153 | 7 | if (false === $index) { |
|
| 154 | $this->fromPrefix = $from; |
||
| 155 | $this->fromPostfix = ''; |
||
| 156 | } else { |
||
| 157 | 7 | $this->fromPrefix = substr($from, 0, $index); |
|
| 158 | 7 | $this->fromPostfix = substr($from, $index + 1); |
|
| 159 | 7 | $this->fromContainsStar = true; |
|
| 160 | } |
||
| 161 | 7 | $this->prefixLength = strlen($this->fromPrefix); |
|
| 162 | 7 | $this->postfixLength = strlen($this->fromPostfix); |
|
| 163 | } |
||
| 164 | |||
| 165 | /** |
||
| 166 | * Sets the "to" pattern. Required. |
||
| 167 | * {@inheritdoc} |
||
| 168 | * |
||
| 169 | * @param string $to |
||
| 170 | */ |
||
| 171 | 7 | public function setTo($to) |
|
| 172 | { |
||
| 173 | 7 | if (null === $to) { |
|
|
0 ignored issues
–
show
|
|||
| 174 | throw new BuildException("this mapper requires a 'to' attribute"); |
||
| 175 | } |
||
| 176 | |||
| 177 | 7 | $index = strrpos($to, '*'); |
|
| 178 | 7 | if (false === $index) { |
|
| 179 | $this->toPrefix = $to; |
||
| 180 | $this->toPostfix = ''; |
||
| 181 | } else { |
||
| 182 | 7 | $this->toPrefix = substr($to, 0, $index); |
|
| 183 | 7 | $this->toPostfix = substr($to, $index + 1); |
|
| 184 | 7 | $this->toContainsStar = true; |
|
| 185 | } |
||
| 186 | } |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Extracts the variable part. |
||
| 190 | * |
||
| 191 | * @param string $name |
||
| 192 | * |
||
| 193 | * @return string |
||
| 194 | */ |
||
| 195 | 7 | private function extractVariablePart($name) |
|
| 196 | { |
||
| 197 | 7 | return StringHelper::substring($name, $this->prefixLength, strlen($name) - $this->postfixLength - 1); |
|
| 198 | } |
||
| 199 | |||
| 200 | /** |
||
| 201 | * modify string based on dir char mapping and case sensitivity. |
||
| 202 | * |
||
| 203 | * @param string $name the name to convert |
||
| 204 | * |
||
| 205 | * @return string the converted name |
||
| 206 | */ |
||
| 207 | 7 | private function modifyName($name) |
|
| 208 | { |
||
| 209 | 7 | if (!$this->caseSensitive) { |
|
| 210 | $name = strtolower($name); |
||
| 211 | } |
||
| 212 | 7 | if ($this->handleDirSep) { |
|
| 213 | if (false !== strpos('\\', $name)) { |
||
| 214 | $name = str_replace('\\', '/', $name); |
||
| 215 | } |
||
| 216 | } |
||
| 217 | |||
| 218 | 7 | return $name; |
|
| 219 | } |
||
| 220 | } |
||
| 221 |