Bug Tracker

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#14329 closed bug (duplicate)

.html(data) incorrectly modifies regular expressions causing a global eval failure.

Reported by: dgtanner@… Owned by:
Priority: low Milestone: None
Component: manipulation Version: 1.8.3
Keywords: Cc:
Blocked by: Blocking:

Description

Jquery .html(data) function will modify a regex script.

For example if the following page is called via $.ajax and the success function does a $('someSelector').html(response); "myString".replace(/<br\/>/g,"\n\t"); will be replaced with "myString".replace(/<br/><t/>/g,"\n\t"); which will fail when jquery calls globaleval.

<html> <head> <script> "myString".replace(/<br\/>/g,"\n\t"); </script> </head> <body> ..... some body here </body> </html>

Change History (6)

comment:1 Changed 5 years ago by dgtanner@…

If .replace(/<br\/>/g,"\n\t") is changed to .replace(new RegExp("<br/>", "g"),"\n\t") everything works just fine.

comment:2 Changed 5 years ago by scottgonzalez

Resolution: notabug
Status: newclosed

.html() doesn't have access to the regex, only to the string after the replacement, so this can't be a problem with jQuery. Please ask for help on the forums or Stack Overflow.

comment:3 in reply to:  2 Changed 5 years ago by anonymous

Replying to scott.gonzalez:

.html() doesn't have access to the regex, only to the string after the replacement, so this can't be a problem with jQuery. Please ask for help on the forums or Stack Overflow.

I assure you that the following code in the jquery .html() function is modifying the returned string (and thus the regex script). I can provide a working example if needed.

if ( typeof value === "string" && !rnoInnerhtml.test( value ) &&

( jQuery.support.htmlSerialize ( jQuery.support.leadingWhitespace !wrapMap[ ( rtagName.exec( value )
!rnoshimcache.test( value ) ) &&
!rleadingWhitespace.test( value ) ) &&
["", ""] )[1].toLowerCase() ] ) {

value = value.replace( rxhtmlTag, "<$1></$2>" );

try {

for (; i < l; i++ ) {

Remove element nodes and prevent memory leaks

elem = this[i]
{};

if ( elem.nodeType === 1 ) {

jQuery.cleanData( elem.getElementsByTagName( "*" ) ); elem.innerHTML = value;

}

}

elem = 0;

If using innerHTML throws an exception, use the fallback method } catch(e) {}

}

comment:4 Changed 5 years ago by gibson042

Resolution: notabug
Status: closedreopened

comment:5 Changed 5 years ago by gibson042

Component: unfiledmanipulation
Priority: undecidedlow
Resolution: duplicate
Status: reopenedclosed

Duplicate of #14370.

comment:6 Changed 5 years ago by gibson042

#14844 is a duplicate of this ticket.

Note: See TracTickets for help on using tickets.