Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid reading outside of collection bounds #3769

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/manipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,11 @@ jQuery.extend( {
cleanData: function( elems ) {
var data, elem, type,
special = jQuery.event.special,
length = elems.length,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to put the lengths in a variable? I thought most JS engines optimize for this, or at least that the perf difference isn't significant.

i = 0;

for ( ; ( elem = elems[ i ] ) !== undefined; i++ ) {
for ( ; i < length; i++ ) {
elem = elems[ i ];
if ( acceptData( elem ) ) {
if ( ( data = elem[ dataPriv.expando ] ) ) {
if ( data.events ) {
Expand Down
4 changes: 3 additions & 1 deletion src/manipulation/buildFragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ function buildFragment( elems, context, scripts, selection, ignored ) {
fragment.textContent = "";

i = 0;
while ( ( elem = nodes[ i++ ] ) ) {
l = nodes.length;
for ( ; i < l; i++ ) {
elem = nodes[ i ];

// Skip elements already in the context collection (trac-4087)
if ( selection && jQuery.inArray( elem, selection ) > -1 ) {
Expand Down