|
23 | 23 | (function($, window, document) {
|
24 | 24 | 'use strict';
|
25 | 25 |
|
| 26 | + var escapeEntities = $.sceditor.escapeEntities; |
| 27 | + var escapeUriScheme = $.sceditor.escapeUriScheme; |
| 28 | + |
26 | 29 | /**
|
27 | 30 | * SCEditor BBCode parser class
|
28 | 31 | *
|
|
874 | 877 | content += '<br />';
|
875 | 878 | }
|
876 | 879 |
|
877 |
| - if($.isFunction(bbcode.html)) |
878 |
| - html = bbcode.html.call(base, token, token.attrs, content); |
| 880 | + if(!$.isFunction(bbcode.html)) |
| 881 | + { |
| 882 | + token.attrs['0'] = content; |
| 883 | + html = $.sceditor.plugins.bbcode.formatBBCodeString(bbcode.html, token.attrs); |
| 884 | + } |
879 | 885 | else
|
880 |
| - html = $.sceditor.plugins.bbcode.formatString(bbcode.html, content); |
| 886 | + html = bbcode.html.call(base, token, token.attrs, content); |
881 | 887 | }
|
882 | 888 | else
|
883 | 889 | html = token.val + content + (token.closing ? token.closing.val : '');
|
|
926 | 932 | else // content
|
927 | 933 | {
|
928 | 934 | needsBlockWrap = isRoot;
|
929 |
| - html = $.sceditor.escapeEntities(token.val); |
| 935 | + html = escapeEntities(token.val, true); |
930 | 936 | }
|
931 | 937 |
|
932 | 938 | if(needsBlockWrap && !blockWrapOpen)
|
|
1760 | 1766 | * @since v1.4.0
|
1761 | 1767 | */
|
1762 | 1768 | $.sceditor.plugins.bbcode.formatString = function() {
|
1763 |
| - var args = arguments; |
| 1769 | + var undef, |
| 1770 | + args = arguments; |
| 1771 | + |
1764 | 1772 | return args[0].replace(/\{(\d+)\}/g, function(str, p1) {
|
1765 |
| - return typeof args[p1-0+1] !== 'undefined' ? |
| 1773 | + return args[p1-0+1] !== undef ? |
1766 | 1774 | args[p1-0+1] :
|
1767 | 1775 | '{' + p1 + '}';
|
1768 | 1776 | });
|
1769 | 1777 | };
|
1770 | 1778 |
|
| 1779 | + /** |
| 1780 | + * Formats a string replacing {name} with the values of |
| 1781 | + * obj.name properties. |
| 1782 | + * |
| 1783 | + * If there is no property for the specified {name} then |
| 1784 | + * it will be left intact. |
| 1785 | + * |
| 1786 | + * @param {String} str |
| 1787 | + * @param {Object} obj |
| 1788 | + * @return {String} |
| 1789 | + * @since 1.4.5 |
| 1790 | + */ |
| 1791 | + $.sceditor.plugins.bbcode.formatBBCodeString = function(str, obj) { |
| 1792 | + return str.replace(/\{(!?[^}]+)\}/g, function(match, group) { |
| 1793 | + var undef, |
| 1794 | + escape = true; |
| 1795 | + |
| 1796 | + if (group[0] === '!') |
| 1797 | + { |
| 1798 | + escape = false; |
| 1799 | + group = group.substring(1); |
| 1800 | + } |
| 1801 | + |
| 1802 | + if (group[0] === '0') |
| 1803 | + escape = false; |
| 1804 | + |
| 1805 | + if (obj[group] === undef) |
| 1806 | + return match; |
| 1807 | + |
| 1808 | + return escape ? |
| 1809 | + escapeEntities(obj[group], true) : |
| 1810 | + obj[group]; |
| 1811 | + }); |
| 1812 | + }; |
| 1813 | + |
1771 | 1814 | /**
|
1772 | 1815 | * Converts CSS RGB and hex shorthand into hex
|
1773 | 1816 | *
|
|
1898 | 1941 |
|
1899 | 1942 | return '[font=' + this.stripQuotes(font) + ']' + content + '[/font]';
|
1900 | 1943 | },
|
1901 |
| - html: function(token, attrs, content) { |
1902 |
| - return '<font face="' + attrs.defaultattr + '">' + content + '</font>'; |
1903 |
| - } |
| 1944 | + html: '<font face="{defaultattr}">{0}</font>' |
1904 | 1945 | },
|
1905 | 1946 | // END_COMMAND
|
1906 | 1947 |
|
|
1944 | 1985 |
|
1945 | 1986 | return '[size=' + size + ']' + content + '[/size]';
|
1946 | 1987 | },
|
1947 |
| - html: function(token, attrs, content) { |
1948 |
| - return '<font size="' + attrs.defaultattr + '">' + content + '</font>'; |
1949 |
| - } |
| 1988 | + html: '<font size="{defaultattr}">{!0}</font>' |
1950 | 1989 | },
|
1951 | 1990 | // END_COMMAND
|
1952 | 1991 |
|
|
1971 | 2010 | return '[color=' + normaliseColour(color) + ']' + content + '[/color]';
|
1972 | 2011 | },
|
1973 | 2012 | html: function(token, attrs, content) {
|
1974 |
| - return '<font color="' + normaliseColour(attrs.defaultattr) + '">' + content + '</font>'; |
| 2013 | + return '<font color="' + |
| 2014 | + escapeEntities(normaliseColour(attrs.defaultattr), true) + |
| 2015 | + '">' + content + '</font>'; |
1975 | 2016 | }
|
1976 | 2017 | },
|
1977 | 2018 | // END_COMMAND
|
|
2068 | 2109 | 'data-sceditor-emoticon': null
|
2069 | 2110 | }
|
2070 | 2111 | },
|
2071 |
| - format: function(element, content) { |
2072 |
| - return element.data('sceditor-emoticon') + content; |
| 2112 | + format: function($elm, content) { |
| 2113 | + return $elm.data('sceditor-emoticon') + content; |
2073 | 2114 | },
|
2074 | 2115 | html: '{0}'
|
2075 | 2116 | },
|
|
2096 | 2137 | src: null
|
2097 | 2138 | }
|
2098 | 2139 | },
|
| 2140 | + allowedChildren: ['#'], |
2099 | 2141 | quoteType: $.sceditor.BBCodeParser.QuoteType.never,
|
2100 | 2142 | format: function($element, content) {
|
2101 | 2143 | var w, h,
|
|
2119 | 2161 | return '[img' + attribs + ']' + $element.attr('src') + '[/img]';
|
2120 | 2162 | },
|
2121 | 2163 | html: function(token, attrs, content) {
|
2122 |
| - var parts, |
| 2164 | + var undef, w, h, parts, |
2123 | 2165 | attribs = '';
|
2124 | 2166 |
|
2125 | 2167 | // handle [img width=340 height=240]url[/img]
|
2126 |
| - if(typeof attrs.width !== 'undefined') |
2127 |
| - attribs += ' width="' + attrs.width + '"'; |
2128 |
| - if(typeof attrs.height !== 'undefined') |
2129 |
| - attribs += ' height="' + attrs.height + '"'; |
| 2168 | + if(attrs.width !== undef) |
| 2169 | + w = attrs.width; |
| 2170 | + if(attrs.height !== undef) |
| 2171 | + h = attrs.height; |
2130 | 2172 |
|
2131 | 2173 | // handle [img=340x240]url[/img]
|
2132 | 2174 | if(attrs.defaultattr) {
|
2133 | 2175 | parts = attrs.defaultattr.split(/x/i);
|
2134 | 2176 |
|
2135 |
| - attribs = ' width="' + parts[0] + '"' + |
2136 |
| - ' height="' + (parts.length === 2 ? parts[1] : parts[0]) + '"'; |
| 2177 | + w = parts[0]; |
| 2178 | + h = (parts.length === 2 ? parts[1] : parts[0]); |
2137 | 2179 | }
|
2138 | 2180 |
|
2139 |
| - return '<img' + attribs + ' src="' + content + '" />'; |
| 2181 | + if (w !== undef) |
| 2182 | + attribs += ' width="' + escapeEntities(w, true) + '"'; |
| 2183 | + if (h !== undef) |
| 2184 | + attribs += ' height="' + escapeEntities(h, true) + '"'; |
| 2185 | + |
| 2186 | + return '<img' + attribs + ' src="' + escapeUriScheme(content) + '" />'; |
2140 | 2187 | }
|
2141 | 2188 | },
|
2142 | 2189 | // END_COMMAND
|
|
2157 | 2204 | if(url.substr(0, 7) === 'mailto:')
|
2158 | 2205 | return '[email="' + url.substr(7) + '"]' + content + '[/email]';
|
2159 | 2206 |
|
2160 |
| - return '[url=' + decodeURI(url) + ']' + content + '[/url]'; |
| 2207 | + return '[url=' + url + ']' + content + '[/url]'; |
2161 | 2208 | },
|
2162 | 2209 | html: function(token, attrs, content) {
|
2163 |
| - return '<a href="' + encodeURI(attrs.defaultattr || content) + '">' + content + '</a>'; |
| 2210 | + attrs.defaultattr = escapeEntities(attrs.defaultattr, true) || content; |
| 2211 | + |
| 2212 | + return '<a href="' + escapeUriScheme(attrs.defaultattr) + '">' + content + '</a>'; |
2164 | 2213 | }
|
2165 | 2214 | },
|
2166 | 2215 | // END_COMMAND
|
|
2169 | 2218 | email: {
|
2170 | 2219 | quoteType: $.sceditor.BBCodeParser.QuoteType.never,
|
2171 | 2220 | html: function(token, attrs, content) {
|
2172 |
| - return '<a href="mailto:' + (attrs.defaultattr || content) + '">' + content + '</a>'; |
| 2221 | + return '<a href="mailto:' + (escapeEntities(attrs.defaultattr, true) || content) + '">' + content + '</a>'; |
2173 | 2222 | }
|
2174 | 2223 | },
|
2175 | 2224 | // END_COMMAND
|
|
2203 | 2252 | },
|
2204 | 2253 | html: function(token, attrs, content) {
|
2205 | 2254 | if(attrs.defaultattr)
|
2206 |
| - content = '<cite>' + attrs.defaultattr + '</cite>' + content; |
| 2255 | + content = '<cite>' + escapeEntities(attrs.defaultattr) + '</cite>' + content; |
2207 | 2256 |
|
2208 | 2257 | return '<blockquote>' + content + '</blockquote>';
|
2209 | 2258 | }
|
|
0 commit comments