Search code examples
javascripthtmlinternet-explorer-8mustachetemplate-engine

Hard pro coding - strange error in IE8


Please help to find an error in library to compile HTML.

Unfortunately it won't work with <script type="text/template"></script> for IE.

"Unterminated string constant" appears in IE8 console in line with this code:

return new Function("variables", 'variables = [variables], svar = "' + block(template.replace(/"/g, '\\"').replace(/\n/g, '\\n')) + '"; return svar;');

Full code and example of init() attached here: http://jsfiddle.net/2trv57rk/


Solution

  • As it seems IE8 detects the linebreaks as \r\n but you didn't escape the \r

    Escape \r too