From 12901b26818612cd9e5669a03b65a02450d0d60e Mon Sep 17 00:00:00 2001 From: topnuomi <1130395124@qq.com> Date: Sat, 30 May 2020 22:53:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E7=89=88=E6=A0=87=E7=AD=BE=E7=9A=84?= =?UTF-8?q?=E5=80=BC=E5=8F=AF=E4=BB=A5=E5=85=81=E8=AE=B8=E5=8D=95/?= =?UTF-8?q?=E5=8F=8C=E5=BC=95=E5=8F=B7=E5=AD=98=E5=9C=A8=EF=BC=8C=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E5=BC=95=E5=8F=B7=E4=B9=9F=E5=85=81=E8=AE=B8=E5=8D=95?= =?UTF-8?q?/=E5=8F=8C=E5=BC=95=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../library/template/driver/engine/Engine.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/framework/library/template/driver/engine/Engine.php b/framework/library/template/driver/engine/Engine.php index 2e62eb1..2f7dca1 100644 --- a/framework/library/template/driver/engine/Engine.php +++ b/framework/library/template/driver/engine/Engine.php @@ -2,6 +2,7 @@ namespace top\library\template\driver\engine; +use Exception; use top\traits\Instance; /** @@ -315,8 +316,11 @@ class Engine } } else { // 自闭合标签处理 $template = preg_replace_callback($pattern, function ($matches) use ($name, $item) { - $attr = $item['attr'] ? $this->getAttr($matches[0], explode(',', $item['attr'])) : []; - return $this->getTagParseResult($name, $attr); + if (!isset($matches[2])) { + $attr = $item['attr'] ? $this->getAttr($matches[0], explode(',', $item['attr'])) : []; + return $this->getTagParseResult($name, $attr); + } + return $matches[0]; }, $template); } } @@ -332,13 +336,13 @@ class Engine private function getAttr($string, $tags = []) { $attr = []; - $attrPattern = '/[ +](.*?)=["](.*?)["]/is'; + $attrPattern = '/[ +](.*?)=([\'"])(.*?)\\2/is'; preg_match_all($attrPattern, $string, $result); if (isset($result[0]) && !empty($result[0])) { foreach ($result[1] as $key => $value) { $name = trim($value, ' '); if (in_array($name, $tags)) { - $attr[$name] = $result[2][$key]; + $attr[$name] = $result[3][$key]; } } } @@ -469,7 +473,8 @@ class Engine private function _assign($tag) { - $parse = ''; + $quot = (strstr($tag['value'], '\'')) ? '"' : '\''; + $parse = ''; return $parse; }