Greatly improve variable parsing in WCF.Template
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 9 Jan 2015 00:26:35 +0000 (01:26 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 9 Jan 2015 00:27:01 +0000 (01:27 +0100)
wcfsetup/install/files/js/WCF.js

index 80ac3eb938d1fd4576fce88f71de7d5c1fbca9db..fdbda56b02e75b9f877de36a01fdda108d2ac801 100755 (executable)
@@ -4633,19 +4633,19 @@ WCF.Template = Class.extend({
                };
                
                template = template.replace(/\{(\$[^\}]+?)\}/g, function(_, content) {
-                       content = unescape(content.replace(/\$([^.\[\s]+)/g, "(v['$1'])"));
+                       content = unescape(content.replace(/\$([^.\[\(\)\]\s]+)/g, "(v['$1'])"));
                        
                        return "' + WCF.String.escapeHTML(" + content + ") + '";
                })
                // Numeric Variable
                .replace(/\{#(\$[^\}]+?)\}/g, function(_, content) {
-                       content = unescape(content.replace(/\$([^.\[\s]+)/g, "(v['$1'])"));
+                       content = unescape(content.replace(/\$([^.\[\(\)\]\s]+)/g, "(v['$1'])"));
                        
                        return "' + WCF.String.formatNumeric(" + content + ") + '";
                })
                // Variable without escaping
                .replace(/\{@(\$[^\}]+?)\}/g, function(_, content) {
-                       content = unescape(content.replace(/\$([^.\[\s]+)/g, "(v['$1'])"));
+                       content = unescape(content.replace(/\$([^.\[\(\)\]\s]+)/g, "(v['$1'])"));
                        
                        return "' + " + content + " + '";
                })
@@ -4655,7 +4655,7 @@ WCF.Template = Class.extend({
                })
                // {if}
                .replace(/\{if (.+?)\}/g, function(_, content) {
-                       content = unescape(content.replace(/\$([^.\[\s]+)/g, "(v['$1'])"));
+                       content = unescape(content.replace(/\$([^.\[\(\)\]\s]+)/g, "(v['$1'])"));
                        
                        return  "';\n" +
                                "if (" + content + ") {\n" +
@@ -4663,7 +4663,7 @@ WCF.Template = Class.extend({
                })
                // {elseif}
                .replace(/\{else ?if (.+?)\}/g, function(_, content) {
-                       content = unescape(content.replace(/\$([^.\[\s]+)/g, "(v['$1'])"));
+                       content = unescape(content.replace(/\$([^.\[\(\)\]\s]+)/g, "(v['$1'])"));
                        
                        return  "';\n" +
                                "}\n" +
@@ -4681,7 +4681,7 @@ WCF.Template = Class.extend({
                        if (typeof $parameters['item'] === 'undefined') throw new Error('Missing item attribute in implode-tag');
                        if (typeof $parameters['glue'] === 'undefined') $parameters['glue'] = "', '";
                        
-                       $parameters['from'] = $parameters['from'].replace(/\$([^.\[\s]+)/g, "(v.$1)");
+                       $parameters['from'] = $parameters['from'].replace(/\$([^.\[\(\)\]\s]+)/g, "(v.$1)");
                        
                        return  "';\n"+
                                "var $implode_" + $tagID + " = false;\n" +
@@ -4701,7 +4701,7 @@ WCF.Template = Class.extend({
                        
                        if (typeof $parameters['from'] === 'undefined') throw new Error('Missing from attribute in foreach-tag');
                        if (typeof $parameters['item'] === 'undefined') throw new Error('Missing item attribute in foreach-tag');
-                       $parameters['from'] = $parameters['from'].replace(/\$([^.\[\s]+)/g, "(v.$1)");
+                       $parameters['from'] = $parameters['from'].replace(/\$([^.\[\(\)\]\s]+)/g, "(v.$1)");
                        
                        return  "';\n" +
                                "$foreach_"+$tagID+" = false;\n" +