html() stripping <style> in IE sometimes

html() stripping <style> in IE sometimes

In the following test case, a textarea contains an html snippet/template that we'll try to insert into a div directly above the textarea.

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    <script type="text/javascript" src="" ></script>
    <script type="text/javascript">

    <div id="test"></div>
    <textarea id="template">
    <style type="text/css">
        .test { color: red; }
    <div id="nav_controls" class="navControls">
        <div id="test_div" class="test">A test</div>


In IE 8 (haven't tested other version of IE - works fine in FF3.6), the style will be stripped in line #4058 of 1.4.1, which is where it passes the snippet into innerHTML.

IF you put a single linebreak into the textarea before the open style tag, it works without a problem.  So you can see it's a bit delicate to reproduce, but we're definitely seeing it in the alpha release code of our jquery app which I'm trying to upgrade to 1.4.1.  Bug does not appear in 1.3.x.  I suggest strengthening the if statement on line 4047 to 4049 to try to trap this condition, but I don't have any suggestions as to how to do so.  Here's the if statement in question:

  1.         } else if ( typeof value === "string" && !/<script/i.test( value ) &&
                ( || !rleadingWhitespace.test( value )) &&
                !wrapMap[ (rtagName.exec( value ) || ["", ""])[1].toLowerCase() ] ) {

trac issue: