Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Smarty outputfilter.trimwhitespace order bug

 
Post new topic   Reply to topic    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
illvili
Smarty n00b


Joined: 30 Jul 2013
Posts: 2

PostPosted: Tue Jul 30, 2013 3:07 am    Post subject: Smarty outputfilter.trimwhitespace order bug Reply with quote

Hi, guys:

I'm using Smarty 3.1.6 in my project, but I notice that when using outputfilter.trimwhitespace, the page is broken. So I checked the HTML output, the script tag place is now IE CC.

I downloaded 3.1.14 and wrote an test. There still that bug.

Here is the test:

index.php
Code:

<?php
include 'libs/Smarty.class.php';

$smarty = new Smarty;
$smarty->loadFilter('output', 'trimwhitespace');
$smarty->display('index.tpl');


index.tpl
Code:
<!doctype html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <title>Smarty Bug</title>
   <!--[if lte IE 6]>@@1 this is ie cc block 1<![endif]-->
</head>
<body>
   <script>//@@2 script block 1</script>
   <script>//@@3 script block 2</script>
   <!--[if lte IE 6]>@@4 this is ie cc block 2<![endif]-->
   <script>//@@5 script block 3</script>
</body>
</html>


and output this:
Code:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Smarty Bug</title> <!--[if lte IE 6]>@@1 this is ie cc block 1<![endif]--> </head> <body> <!--[if lte IE 6]>@@4 this is ie cc block 2<![endif]--> <script>//@@2 script block 1</script> <script>//@@3 script block 2</script> <script>//@@5 script block 3</script> </body> </html>


please notice the order.

So I changed outputfilter.trimwhitespace.php:
Code:

--- X:\smarty_bug\libs\plugins\outputfilter.trimwhitespace.php Tue Jul 30 10:53:48 2013
+++ X:\smarty_bug\libs\plugins\outputfilter.trimwhitespace.php Tue Jul 30 10:53:50 2013
@@ -29,7 +29,7 @@
     // capture Internet Explorer Conditional Comments
     if (preg_match_all('#<!--\[[^\]]+\]>.*?<!\[[^\]]+\]-->#is', $source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
         foreach ($matches as $match) {
-            $store[] = $match[0][0];
+            $store[$_store] = $match[0][0];
             $_length = strlen($match[0][0]);
             $replace = '@!@SMARTY:' . $_store . ':SMARTY@!@';
             $source = substr_replace($source, $replace, $match[0][1] - $_offset, $_length);
@@ -47,7 +47,7 @@
     $_offset = 0;
     if (preg_match_all('#<(script|pre|textarea)[^>]*>.*?</\\1>#is', $source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
         foreach ($matches as $match) {
-            $store[] = $match[0][0];
+            $store[$_store] = $match[0][0];
             $_length = strlen($match[0][0]);
             $replace = '@!@SMARTY:' . $_store . ':SMARTY@!@';
             $source = substr_replace($source, $replace, $match[0][1] - $_offset, $_length);
@@ -78,9 +78,9 @@
     $_offset = 0;
     if (preg_match_all('#@!@SMARTY:([0-9]+):SMARTY@!@#is', $source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
         foreach ($matches as $match) {
-            $store[] = $match[0][0];
+            $store[$_store] = $match[0][0];
             $_length = strlen($match[0][0]);
-            $replace = array_shift($store);
+            $replace = $store[$match[1][0]];
             $source = substr_replace($source, $replace, $match[0][1] + $_offset, $_length);
 
             $_offset += strlen($replace) - $_length;


and now, it got the correct order.

Code:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Smarty Bug</title> <!--[if lte IE 6]>@@1 this is ie cc block 1<![endif]--> </head> <body> <script>//@@2 script block 1</script> <script>//@@3 script block 2</script> <!--[if lte IE 6]>@@4 this is ie cc block 2<![endif]--> <script>//@@5 script block 3</script> </body> </html>


Please fix it, and thanks all your works.
Back to top
View user's profile Send private message
illvili
Smarty n00b


Joined: 30 Jul 2013
Posts: 2

PostPosted: Tue Jul 30, 2013 3:19 am    Post subject: Reply with quote

Sorry for post here, because I can't open code.google.com from my network.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 4703
Location: Hamburg / Germany

PostPosted: Tue Jul 30, 2013 9:27 am    Post subject: Reply with quote

This bug was already fixed after the 3.1.14 release in the SVN trunk on july 2nd.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Bugs All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP