Fixed situation where minified inline JavaScript includes a <script> tag - needs to be escaped.

This commit is contained in:
remy 2011-06-11 16:28:59 +01:00
parent c418d6f32c
commit 52b8f70a58
2 changed files with 7 additions and 4 deletions

View File

@ -191,7 +191,8 @@ function Inliner(url, options, callback) {
assets.scripts.each(function () {
var $script = window.$(this),
src = $script.attr('src'),
orig_code = this.innerHTML;
orig_code = this.innerHTML,
final_code = '';
// only remove the src if we have a script body
if (orig_code) {
@ -208,12 +209,12 @@ function Inliner(url, options, callback) {
ast = pro.ast_mangle(ast); // get a new AST with mangled names
ast = pro.ast_squeeze(ast); // get an AST with compression optimizations
var final_code = pro.gen_code(ast);
final_code = pro.gen_code(ast);
// some protection against putting script tags in the body
final_code = final_code.replace(/<\/script>/gi, '<\\/script>');
window.$(this).text(final_code);
window.$(this).text(final_code);
if (src) {
inliner.emit('progress', 'compress ' + URL.resolve(root, src));
} else {
@ -223,6 +224,8 @@ function Inliner(url, options, callback) {
}
inliner.todo--;
inliner.emit('jobs', (inliner.total - inliner.todo) + '/' + inliner.total);
} else if (orig_code) {
window.$(this).text(orig_code.replace(/<\/script>/gi, '<\\/script>'));
}
});
finished();

View File

@ -1,6 +1,6 @@
{
"name": "inliner",
"version": "0.1.4",
"version": "0.1.5",
"description": "Utility to inline images, CSS and JavaScript for a web page - useful for mobile sites",
"homepage": "http://github.com/remy/inliner",
"main": "inliner",