diff --git a/change_log.txt b/change_log.txt index 4661f657..e581bf00 100644 --- a/change_log.txt +++ b/change_log.txt @@ -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. diff --git a/libs/sysplugins/smarty_resource.php b/libs/sysplugins/smarty_resource.php index f79373af..55f1497f 100644 --- a/libs/sysplugins/smarty_resource.php +++ b/libs/sysplugins/smarty_resource.php @@ -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