Page MenuHomePhabricator

JavaScript minification breaks production when line starts with slash in block comments
Closed, ResolvedPublic

Description

The following code
<pre>
/**

  • Foobar:
  • {
  • 'ltr' : {
  • //Multiple rules with configurable operators
  • 'iphone' : false
  • }
  • @return Boolean true lorem ipsum */

</pre>
Is minified as:
<pre>
/**
*Foobar:
*{
*'ltr':{
*//Multiple rules with configurable operators
*'iphone':false
*}

*@return Boolean true lorem ipsum
*/
</pre>

The following line specifically is where it all breaks:
<pre>
*//Multiple rules with configurable operators
</pre>

Because it is considered as the closure of the block comment " */ " and the (unexpected) start of a regex.

"Error: unterminated regular expression literal"
Source File: http://translatewiki.net/w/load.php?debug=false&lang=fi&modules=ext.liquidThreads%7Cjquery.autoEllipsis%7Cjquery.checkboxShiftClick%7Cjquery.client%7Cjquery.collapsibleTabs%7Cjquery.cookie%7Cjquery.delayedBind%7Cjquery.highlightText%7Cjquery.makeCollapsible%7Cjquery.placeholder%7Cjquery.suggestions%7Cjquery.tabIndex%7Cjquery.ui.button%7Cjquery.ui.core%7Cjquery.ui.dialog%7Cjquery.ui.draggable%7Cjquery.ui.mouse%7Cjquery.ui.position%7C

Thanks to TranslateWiki Nikerabbit for reporting this on IRC.

I'm confused though that this is production output, why are there comments in production output ?
That empty lines were insterted in place of comments (before the minifier switch by Trevor[0]) to keep track of the line number (although that only applies to the first file of all loaded modules) was one, but keeping all comments ? We might as well disable the minifier then.

Krinkle

[0] http://lists.wikimedia.org/pipermail/wikitech-l/2011-January/051308.html


Version: 1.18.x
Severity: critical

Details

Reference
bz26931

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 11:23 PM
bzimport set Reference to bz26931.

This output does not appear to reflex the latest version of the minifier. I tested running the raw versions of these modules through the latest version and no such errors are present.

I think the old minified versions are still in cache, and need to be purged.

TWN's sandwiki has been updated to the lastest trunk 2 minutes ago:

http://translatewiki.net/sandwiki/load.php?debug=false&lang=fi&modules=ext.liquidThreads%7Cjquery.client

Search for "*"
It is still removing the space between * and
, causing the comment block to end early and a regex to be started in a wrong place:

<pre>
/**
*Checks the current browser against a support map object to determine if the browser has been black-listed or
*not.If the browser was not configured specifically it is assumed to work.It is assumed that the body
*element is classified as either"ltr"or"rtl".If neither is set,"ltr"is assumed.

*A browser map is in the following format:
*{
*'ltr':{
*Multiple rules with configurable operators
*'msie':[['>=',7],['!=',9]],
*
Blocked entirely
*'iphone':false
*},
*'rtl':{
*Test against a string
*'msie':[['!==','8.1.2.3']],
*
RTL rules do not fall through to LTR rules,you must explicity set each of them
*'iphone':false
*}
*}

*@param map Object of browser support map

*@return Boolean true if browser known or assumed to be supported,false if blacklisted
*/
</pre>

If it is going to keep comments in production mode, it should not touch touch those lines at all.

Yeah, I actually am working on a patch - I found a way to reproduce..

This should be resolved in r80979 - can someone please update tw.n and verify?

Looks fine now. Thx.
Should this be fixed upstream by the way ?

Yes, in a few days, if this stablizes a bit, I will push back upstream our code - which the author should be able to make some use of in his JavaScriptPacker.