Skip to main content

Bug Tracker

Side navigation

#14329 closed bug (duplicate)

Opened September 03, 2013 04:04PM UTC

Closed February 02, 2014 07:29PM UTC

Last modified April 28, 2014 07:56PM UTC

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

Reported by: dgtanner@gmail.com 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>

Attachments (0)
Change History (6)

Changed September 03, 2013 04:10PM UTC by dgtanner@gmail.com comment:1

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

Changed September 03, 2013 04:12PM UTC by scottgonzalez comment:2

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.

Changed September 03, 2013 04:18PM UTC by anonymous comment:3

Replying to [comment:2 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) {}

}

Changed February 02, 2014 07:27PM UTC by gibson042 comment:4

resolution: notabug
status: closedreopened

Changed February 02, 2014 07:29PM UTC by gibson042 comment:5

component: unfiledmanipulation
priority: undecidedlow
resolution: → duplicate
status: reopenedclosed

Duplicate of #14370.

Changed April 28, 2014 07:56PM UTC by gibson042 comment:6

#14844 is a duplicate of this ticket.