Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fofr opened this issue Dec 24, 2015 · 1 comment
Open

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

fofr opened this issue Dec 24, 2015 · 1 comment
Assignees

Comments

@fofr
Copy link

fofr commented Dec 24, 2015

Consider the following:

  • Content with a heading "Exports"
  • A publishing tool that dynamically creates IDs based on the value of that heading, id="exports"
  • A browser takes this heading and creates a global variable, window.exports returns the HTML element
  • The line typeof exports !== 'undefined' ? exports : Hogan now returns an HTML element and Hogan doesn't start properly
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:
alphagov/shared_mustache#8

@fofr
Copy link
Author

fofr commented May 25, 2016

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

@sayrer sayrer self-assigned this May 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants