Export to GitHub

htmlcompressor - issue #7

Error in compressor js in html


Posted on Dec 8, 2009 by Quick Wombat

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(JavaScriptCompressor.java:312) at com.yahoo.platform.yui.compressor.JavaScriptCompressor.<init>(JavaScriptCompressor.java:533) at com.googlecode.htmlcompressor.compressor.HtmlCompressor.compressJavaScript(HtmlCompressor.java:257) at com.googlecode.htmlcompressor.compressor.HtmlCompressor.processScriptBlocks(HtmlCompressor.java:236) at com.googlecode.htmlcompressor.compressor.HtmlCompressor.compress(HtmlCompressor.java:109) at com.googlecode.htmlcompressor.CmdLineCompressor.main(CmdLineCompressor.java:200)

HTML in attach

Attachments

Comment #1

Posted on Dec 8, 2009 by Grumpy Hippo

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.

Comment #2

Posted on Jun 23, 2010 by Quick Horse

Actually, this issue is caused by any invalid javascript in a 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

Attachments

Comment #3

Posted on Aug 28, 2010 by Grumpy Hippo

@erin.dru Thanks. Was added in 0.9.2 version.

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

Status: Fixed

Labels:
Type-Defect Priority-Medium