bugfix resolving relative paths broke in some circumstances (Issue #114)

This commit is contained in:
rodneyrehm
2012-08-31 19:39:28 +00:00
parent 98c9862de4
commit 9ef8d6045f
2 changed files with 11 additions and 11 deletions

View File

@@ -1,4 +1,7 @@
===== trunk =====
31.08.2012
- bugfix resolving relative paths broke in some circumstances (Issue #114)
22.08.2012
- bugfix test MBString availability through mb_split, as it could've been compiled without regex support (--enable-mbregex).
Either we get MBstring's full package, or we pretend it's not there at all.

View File

@@ -159,16 +159,18 @@ abstract class Smarty_Resource {
$_path = str_replace('\\', '/', $_path);
}
$offset = 0;
// resolve simples
$_path = preg_replace('#(/\./(\./)*)|/{2,}#', '/', $_path);
// resolve parents
while (true) {
$_parent = strpos($_path, '/../');
if ($_parent === false) {
break;
} else if ($_parent === 0) {
$_path = substr($_path, 3);
$_parent = strpos($_path, '/../', $offset);
if (!$_parent) {
break;
} else if ($_path[$_parent - 1] === '.') {
$offset = $_parent + 3;
continue;
}
$_pos = strrpos($_path, '/', $_parent - strlen($_path) - 1);
@@ -226,7 +228,6 @@ abstract class Smarty_Resource {
if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $file)) {
// don't we all just love windows?
$_path = str_replace('\\', '/', $file);
$_was_relative_prefix = $file[0] == '.' ? substr($file, 0, strpos($_path, '/')) : null;
$_path = DS . trim($file, '/');
$_was_relative = true;
} else {
@@ -240,11 +241,7 @@ abstract class Smarty_Resource {
}
// revert to relative
if (isset($_was_relative)) {
if (isset($_was_relative_prefix)){
$_path = $_was_relative_prefix . $_path;
} else {
$_path = substr($_path, 1);
}
$_path = substr($_path, 1);
}
// this is only required for directories