DenVdmj / htmlcompressor

Automatically exported from code.google.com/p/htmlcompressor
Apache License 2.0
0 stars 0 forks source link

Error in compressor js in html #7

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Error in compressor js:
# java -jar /home/user/workspace/inel/intranet/js/htmlcompressor-0.8.2.jar
--compress-js --compress-css index.phtml -o index.min.phtml 
java.lang.NullPointerException
    at org.mozilla.javascript.Parser.addError(Parser.java:146)
    at org.mozilla.javascript.Parser.reportError(Parser.java:160)
    at org.mozilla.javascript.Parser.primaryExpr(Parser.java:2464)
    at org.mozilla.javascript.Parser.memberExpr(Parser.java:1950)
    at org.mozilla.javascript.Parser.unaryExpr(Parser.java:1808)
    at org.mozilla.javascript.Parser.mulExpr(Parser.java:1737)
    at org.mozilla.javascript.Parser.addExpr(Parser.java:1718)
    at org.mozilla.javascript.Parser.shiftExpr(Parser.java:1698)
    at org.mozilla.javascript.Parser.relExpr(Parser.java:1672)
    at org.mozilla.javascript.Parser.eqExpr(Parser.java:1628)
    at org.mozilla.javascript.Parser.bitAndExpr(Parser.java:1617)
    at org.mozilla.javascript.Parser.bitXorExpr(Parser.java:1606)
    at org.mozilla.javascript.Parser.bitOrExpr(Parser.java:1595)
    at org.mozilla.javascript.Parser.andExpr(Parser.java:1583)
    at org.mozilla.javascript.Parser.orExpr(Parser.java:1571)
    at org.mozilla.javascript.Parser.condExpr(Parser.java:1554)
    at org.mozilla.javascript.Parser.assignExpr(Parser.java:1539)
    at org.mozilla.javascript.Parser.condExpr(Parser.java:1558)
    at org.mozilla.javascript.Parser.assignExpr(Parser.java:1539)
    at org.mozilla.javascript.Parser.expr(Parser.java:1518)
    at org.mozilla.javascript.Parser.statementHelper(Parser.java:1201)
    at org.mozilla.javascript.Parser.statement(Parser.java:708)
    at org.mozilla.javascript.Parser.parse(Parser.java:401)
    at org.mozilla.javascript.Parser.parse(Parser.java:359)
    at
com.yahoo.platform.yui.compressor.JavaScriptCompressor.parse(JavaScriptCompresso
r.java:312)
    at
com.yahoo.platform.yui.compressor.JavaScriptCompressor.<init>(JavaScriptCompress
or.java:533)
    at
com.googlecode.htmlcompressor.compressor.HtmlCompressor.compressJavaScript(HtmlC
ompressor.java:257)
    at
com.googlecode.htmlcompressor.compressor.HtmlCompressor.processScriptBlocks(Html
Compressor.java:236)
    at
com.googlecode.htmlcompressor.compressor.HtmlCompressor.compress(HtmlCompressor.
java:109)
    at
com.googlecode.htmlcompressor.CmdLineCompressor.main(CmdLineCompressor.java:200)

HTML in attach

Original issue reported on code.google.com by muriloel...@gmail.com on 8 Dec 2009 at 6:32

Attachments:

GoogleCodeExporter commented 8 years ago
This happens because php tags are interpreted as html tags. I am not using any 
deep
analysis for HTML (for speed sake), just regular expressions, so when it sees 
`<script type="text/javascript" src="<?php echo 
$this->arrayFiles['jquery.js']['url']
?>"></script>`
it takes '<' and '>' php symbols as html tag boundaries.

It was not intended to parse anything other than plain html. Sorry, I don't 
think I
will be able to do anything with this problem.

Btw a better way of doing html compression for php would be putting your html 
into
Smarty templates and then using `{strip}` tags. That's how I deal with php
compression and that's what inspired this project.

Original comment by serg472@gmail.com on 8 Dec 2009 at 7:17

GoogleCodeExporter commented 8 years ago
Actually, this issue is caused by any invalid javascript in a <script> tag. The 
YUI Compressor tries to write to its error reporter, but due to line 312 of 
HtmlCompressor.java:

JavaScriptCompressor compressor = new JavaScriptCompressor(new 
StringReader(source), null);

The error reporter is explicitly "null" so NullPointerException is thrown. I 
have attached a patch that allows the user to set the yuiErrorReporter

Original comment by erin....@gmail.com on 23 Jun 2010 at 1:43

Attachments:

GoogleCodeExporter commented 8 years ago
@erin.dru Thanks. Was added in 0.9.2 version.

Also custom preservation rules were added, php blocks can be preserved now.

Original comment by serg472@gmail.com on 28 Aug 2010 at 2:23