Commit 34639138 authored by Chris Graham's avatar Chris Graham
Browse files

Fixed MANTIS-4609 (Don't allow formatting errors in block/module code to cause errors)

parent 3e002d93
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -1847,13 +1847,28 @@ function extract_module_functions($path, $functions, $params = null, $prefer_dir
            $end = min($end1, $end2) + 2 + $spaces;
            $func = substr($file, $start, $end - $start);

            $new_func = str_replace('function ' . $function . '(', 'function ' . $function . $r . '(', $func) . 'return ' . filter_naughty_harsh($function) . $r . '(' . $_params . '); ';
            $new_func = str_replace('function ' . $function . '(', 'if (!function_exists(\'' . $function . $r . '\')) { function ' . $function . $r . '(', $func) . ' } return ' . filter_naughty_harsh($function) . $r . '(' . $_params . '); ';
            $out[] = $pre . "\n\n" . $new_func;

            if ((strpos($new_func, 'parent::') !== false) || (strpos($new_func, '$this->') !== false)) {
                return extract_module_functions($path, $functions, $params, true, $class_name);
            }

            $parse_error = false;
            try {
                if (@eval('return true;' . $pre . $new_func) === false) {
                    $parse_error = true;
                }
            } catch (ParseError $e) {
                $parse_error = true;
            } catch (Exception $e) {
                $parse_error = true;
            }

            if ($parse_error) {
                return extract_module_functions($path, $functions, $params, true, $class_name);
            }

            $pre = ''; // Can only load that bit once
        }
    }