remy / inliner

Node utility to inline images, CSS and JavaScript for a web page - useful for mobile sites
MIT License
1.1k stars 165 forks source link

All html meta tags are removed when inlined #78

Closed RoryTN closed 8 years ago

RoryTN commented 8 years ago

It appears that all html meta tags are removed in the inlining process. In the code in index.js it looks like the intention is to only remove the meta tags that specify the charset.

    if (enc !== 'utf-8') {
      // when transcoding remove any meta tags setting the charset
      $('meta').each(function charMeta() {
        var content = $(this).attr('content') || '';
        if (content.toLowerCase().indexOf('charset=')) {
          $(this).remove();
        }
      });
    }

However it looks like there is a bug in the check for the charset field, since indexOf still returns the truthy value of -1 even if the string is not found. As such in all meta tags are being removed irrespective of whether they contain a charset field or not. I am assuming the intended check should have been:

        if (content.toLowerCase().indexOf('charset=') !== -1) {
          $(this).remove();
        }