Ticket #5876 (closed bug: worksforme)
domManip caching doesn't evaluate scripts
| Reported by: | molily | Owned by: | |
|---|---|---|---|
| Priority: | high | Milestone: | |
| Component: | manipulation | Version: | 1.4.4 |
| Keywords: | dommanip cache | Cc: | |
| Blocking: | #6779 | Blocked by: |
Description
buildFragment() uses jQuery.clean() to extract the JS code of <script> elements. If it uses the cached DOM Fragment, clean() isn't called. In this case, the 'scripts' array remains empty so that evalScript() isn't called any longer.
Test case:
<p><a href="" id="start">call html()</a></p>
<div id="output"></div>
<script> $(function ($) {
$('#start').click(function (e) {
$('#output').html("<script> alert('should be executed'); <\/script>"); e.preventDefault();
});
}); </script>
This works as expected for the first and second click, but the third time the cache kicks in and the embedded script isn't executed.
This used to work in jQuery 1.3. I've encountered this bug in an Ajax environment using .load(). If the Ajax response is the same three times in a row, the embedded scripts weren't executed.
Change History
comment:3 Changed 3 years ago by snover
- Blocking 6779 added
(In #6779) Beyond just not testing for strings with no HTML, I suggested to only cache strings where the first character is a <.
comment:4 Changed 3 years ago by snover
- Priority changed from major to high
- Status changed from new to open
- Version changed from 1.4 to 1.4.4
- Milestone changed from 1.4.1 to 1.5
comment:6 Changed 2 years ago by jitter
test case I can't reproduce this with 1.4.4 . snover could you reproduce this 3 weeks ago?
comment:7 Changed 2 years ago by molily
Apparently this was fixed in 1.4.2 because this version introduced more checks if a string is cacheable as a DOM fragment. Since 1.4.2, strings that match
rnocache = /<script|<object|<embed|<option|<style/i
are not cached.
This means the script execution problem I had reported does not occur an longer because HTML strings with script elements aren't cached into DOM fragments any more.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
