twitter / hogan.js

A compiler for the Mustache templating language
http://twitter.github.io/hogan.js
Apache License 2.0
5.14k stars 431 forks source link

Checking `exports !== undefined` can give false positives #238

Open fofr opened 8 years ago

fofr commented 8 years ago

Consider the following:

var Hogan = {};

(function(Hogan) {
  // The value of Hogan at this point is the HTML element
  // <h2 id="exports">Exports</h2>
})(typeof exports !== 'undefined' ? exports : Hogan);

This is what happened on GOV.UK on articles with content that refers to "Exports". This was one of the affected pages: https://www.gov.uk/government/publications/notice-143-a-guide-for-international-post-users/notice-143-a-guide-for-international-post-users#exports

Here's the hot fix that was applied: https://github.com/alphagov/shared_mustache/pull/8

fofr commented 8 years ago

More details in this blog post: http://paulrhayes.com/2015-12/a-problem-with-exports/