#14329 closed bug (duplicate)
.html(data) incorrectly modifies regular expressions causing a global eval failure.
Reported by: | 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 9 years ago by
comment:2 follow-up: 3 Changed 9 years ago by
Resolution: | → notabug |
---|---|
Status: | new → closed |
.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 Changed 9 years ago by
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 !rnoshimcache.test( value ) ) && ( jQuery.support.leadingWhitespace !rleadingWhitespace.test( value ) ) && !wrapMap[ ( rtagName.exec( 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 9 years ago by
Resolution: | notabug |
---|---|
Status: | closed → reopened |
comment:5 Changed 9 years ago by
Component: | unfiled → manipulation |
---|---|
Priority: | undecided → low |
Resolution: | → duplicate |
Status: | reopened → closed |
Duplicate of #14370.
If .replace(/<br\/>/g,"\n\t") is changed to .replace(new RegExp("<br/>", "g"),"\n\t") everything works just fine.