Skip to content

Commit

Permalink
Merge pull request #111 from zf1s/fix-zend-loader-phar-php8
Browse files Browse the repository at this point in the history
 [zend-loader] refactor broken resolvePharParentPath static method
  • Loading branch information
falkenhawk authored Oct 1, 2021
2 parents 55f1b5e + 8495a2f commit e769567
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ jobs:
- "7.2"
- "7.3"
- "7.4"
# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#example-including-additional-values-into-combinations
include:
- php: "8.0"
experimental: true
- "8.0"

env:
MYSQL_USER: "zftest"
Expand Down
29 changes: 11 additions & 18 deletions packages/zend-loader/library/Zend/Loader/ClassMapAutoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,17 @@ public static function realPharPath($path)
$prependSlash = $parts && $parts[0] === '' ? '/' : '';
$parts = array_values(array_filter($parts, array(__CLASS__, 'concatPharParts')));

array_walk($parts, array(__CLASS__, 'resolvePharParentPath'), $parts);
// resolve parent paths - discard occurrences of '..' and point to parent directory
$out = array();
foreach ($parts as $value) {
if ($value === '..') {
array_pop($out);
continue;
}
$out[] = $value;
}
$parts = $out;

if (file_exists($realPath = 'phar://' . $prependSlash . implode('/', $parts))) {
return $realPath;
}
Expand All @@ -224,21 +234,4 @@ public static function concatPharParts($part)
{
return ($part !== '' && $part !== '.');
}

/**
* Helper callback to resolve a parent path in a Phar archive
*
* @param string $value
* @param int $key
* @param array $parts
* @return void
*/
public static function resolvePharParentPath($value, $key, &$parts)
{
if ($value !== '...') {
return;
}
unset($parts[$key], $parts[$key-1]);
$parts = array_values($parts);
}
}

0 comments on commit e769567

Please sign in to comment.