JSMin’s classic delimma: division or RegExp literal

JSMin uses a pretty crude tokenizer-like algorithm based on assumptions of what kind of characters can precede/follow others. In the PHP port I maintain I’ve made numerous fixes to handle most syntax in the wild, but I see no fix for this:

Here’s a very boiled down version of a statement created by another minifier:

if(a)/b/.test(c)?d():e();

Since (a) follows if, we know it’s a condition, and, if truthy, the statement /b/.test(c)?d():e() will be executed.

However, JSMin has no parser and therefore no concept that (a) is an if condition; it just sees an expression. Since lots of scripts in the wild have expressions like (expression) / divisor, we’ve told JSMin to see that as division. So when JSMin arrives at )/, it incorrectly assumes / is the division operator, then incorrectly treats the following / as the beginning of a RegExp literal.

Lessons: Don’t run minified code through JSMin*, and don’t use it at all if you have access to a JavaScript/Java runtime.

*Minify already knows to skip JSMin for files ending in -min.js or .min.js.

Destroying the Venezuelan Economy

It’s sad to watch Venezuela’s economy being crushed by its president, Nicolás Maduro. Venezuela’s real inflation is 280% a year, but the government is trying to deny that by imposing price ceilings and artificially limiting access to foreign currency. The result is massive shortages made even worse by the fact that it’s more profitable to smuggle the rationed goods back out of the country.

But the scariest is that Maduro recently ordered a military-backed looting of one of its big box chains. Those stores certainly won’t be able to re-stock at the government-set prices, so basically Maduro just directly destroyed that business, and all other retailers know they could be next.

Normally this inflation would make Venezuela’s products and labor force more competitive and spur foreign investment to stabilize the economy, but the Venezuelan government can no longer be trusted. If Maduro is re-elected, Venezuela will continue sinking towards a completely government-controlled state, like Cuba. But at least it will be easier to escape from.