AndersDJohnson / AndersDJohnson/htmlcompressor
Event-handler preservation breaks script compression
- 主要语言
- Java
- 星标
- 1
- 派生
- 0
- PR 合并指标
- 30 天内没有已合并 PR
描述
```
The code that finds inline event handlers in the HTML using a couple of regexps
(eventPattern1 and eventPattern2) is also finding them inside literals in
script blocks and breaking those scripts because of it.
Example input:
function t() {
var myvarname = 1;
return ' onclick="test('+myvarname+')"/>';
}
This should compress like this:
function t(){var a=1;return ' onclick="test('+a+')"/>';}
but instead becomes:
function t(){var a=1;return ' onclick="test('+myvarname+')"/>';}
This breaks the Javascript code, as 'myvarname' doesn't exist after
compression. It was the HTML event handling code that put it back.
This same regexp can break compression entirely. Example:
var a='a', b='b', x=' onclick="t('+"'"+a+"','"+b+"'"+')"';
This is a legitimate javascript statement, setting x to the string
onclick="t('a','b')"
HtmlCompressor goes ahead and breaks it because it tried to parse HTML with
regexps.
[ERROR] HtmlCompressor: "missing ; before statement" at line [2:62] during
JavaScript compression: var a='a', b='b', x='
onclick="%%%~COMPRESS~EVENT~0~%%%"'"+a+"','"+b+"'"+')"';
[ERROR] HtmlCompressor: "unterminated string literal" at line [2:78] during
JavaScript compression: var a='a', b='b', x='
onclick="%%%~COMPRESS~EVENT~0~%%%"'"+a+"','"+b+"'"+')"';
[ERROR] HtmlCompressor: "Compilation produced 2 syntax errors." at line [1:0]
during JavaScript compression
It doesn't even have to be a known event handler, any word beginning "on" will
do:
var x=' one="'+"'";
This is using htmlcompressor 1.5.3 on all platforms, configured to use
YUICompressor for JS compression.
```
Original issue reported on code.google.com by `stuart.c...@gmail.com` on 10 Apr 2012 at 1:25
贡献指南
这个仓库没有索引到贡献指南
评估
这个 Issue 还没有评估数据。