Js Minifier add backslash in html tags since V4.55

Dec 19, 2014 at 5:39 AM
Hi,

I wanted to update all references to a project, included AjaxMin, but one of the unit test have failed after that.

I use Minifier like this:
var minifer = new Minifier();
var codeSettings = new CodeSettings ();

var minified =  minifer.MinifyJavaScript(content, codeSettings);
The input is the following:
function test() { alert('hello'); }
document.write('<h1>This is a heading</h1>');
document.write('<p>This is a paragraph.</p>');
document.write('<p>This is another paragraph.</p>');
The output generated:
function test(){alert("hello")}document.write("<h1>This is a heading<\/h1>");document.write("<p>This is a paragraph.<\/p>");document.write("<p>This is another paragraph.<\/p>")
All HTML closing tag have an extra '\' before any '/'.
It is happening since V4.55, V4.54 doesn't add the backslashes.

Is this normal, am I missing a parameter in CodeSettings?

Sorry if the question has already been asked but I haven't found any reference about this problem.

Thanks.
Coordinator
Dec 19, 2014 at 1:34 PM
Wow, that was done a while ago. Okay, so is this script meant to go inline inside HTML markup? If so, then I had seen a spec somewhere that says closing HTML tags inside inline script should be properly escaped so as not to conflict with the actual markup. AjaxMin by default generates script safe for embedding into HTML, so you are seeing that artifact.

If your script is not meant for inline embedding in HTML, you can specify the -inline:false switch and it will skip all the extra work it does to make sure the script is safe for inline HTML placement, including escaping closing HTML tags.
Coordinator
Dec 19, 2014 at 1:36 PM
Oh, and I should add that the function of the resulting script is identical; it has just escaped that forward slash in the string so the tag doesn't look like "</p>" to browsers parsing the HTML, but the actual value of the string is still "</p>".
Dec 19, 2014 at 4:12 PM
Thanks for this great explanation, that is all I needed to know! :)