From 07de9164b7782c0a92ec45f282b168ae67a7ef49 Mon Sep 17 00:00:00 2001 From: Simon Wisselink Date: Mon, 22 Mar 2021 10:27:58 +0100 Subject: [PATCH 1/2] Fixed render crash when using inline include with a string template. Fixed #639 --- CHANGELOG.md | 3 +++ libs/sysplugins/smarty_internal_template.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c4e93e89..30d022db7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - modifier escape now triggers a E_USER_NOTICE when an unsupported escape type is used https://github.com/smarty-php/smarty/pull/649 +### Fixed +- Fixed render crash when using inline include with a string template https://github.com/smarty-php/smarty/issues/639 + ## [3.1.39] - 2021-02-17 ### Security diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php index bae22a7d5..d6f24c8ff 100644 --- a/libs/sysplugins/smarty_internal_template.php +++ b/libs/sysplugins/smarty_internal_template.php @@ -317,7 +317,7 @@ public function _subTemplateRender( $tpl->template_resource = $template; $tpl->cache_id = $cache_id; $tpl->compile_id = $compile_id; - if (isset($uid)) { + if (isset($uid) && isset($tpl->compiled->file_dependency[ $uid ])) { // for inline templates we can get all resource information from file dependency list($filepath, $timestamp, $type) = $tpl->compiled->file_dependency[ $uid ]; $tpl->source = new Smarty_Template_Source($smarty, $filepath, $type, $filepath); From 5c0072430c38879f9e746b0b5040a8a986c26f23 Mon Sep 17 00:00:00 2001 From: Simon Wisselink Date: Mon, 22 Mar 2021 10:35:05 +0100 Subject: [PATCH 2/2] Add unit test --- .../TagTests/Include/CompileIncludeTest.php | 8 ++++++++ .../TagTests/Include/templates/inline_string_include.tpl | 1 + 2 files changed, 9 insertions(+) create mode 100644 tests/UnitTests/TemplateSource/TagTests/Include/templates/inline_string_include.tpl diff --git a/tests/UnitTests/TemplateSource/TagTests/Include/CompileIncludeTest.php b/tests/UnitTests/TemplateSource/TagTests/Include/CompileIncludeTest.php index 830089aef..c07f11007 100644 --- a/tests/UnitTests/TemplateSource/TagTests/Include/CompileIncludeTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/Include/CompileIncludeTest.php @@ -324,4 +324,12 @@ public function dataTestSpacing() array("A{include file='include_spacing3.tpl'}B\nC", "AbarB\nC", '3_Newline3', $i++), ); } + + /** + * Test Inline Include with string template + */ + public function testInlineStringInclude() + { + $this->assertEquals('include-inline', $this->smarty->fetch('inline_string_include.tpl')); + } } diff --git a/tests/UnitTests/TemplateSource/TagTests/Include/templates/inline_string_include.tpl b/tests/UnitTests/TemplateSource/TagTests/Include/templates/inline_string_include.tpl new file mode 100644 index 000000000..44d7eb3a6 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/Include/templates/inline_string_include.tpl @@ -0,0 +1 @@ +{include "string:include-inline" inline} \ No newline at end of file