XRegExp breaks jQuery Animations

XRegExp is an open source JavaScript library that provides an augmented, extensible, cross-browser implementation of regular expressions, including support for additional syntax, flags, and methods.

It’s used by the popular SyntaxHighlighter script, which is in turn used by many websites (including this blog) to display syntax-highlighted source code on the client.  Thus, XRegExp has a rather wide usage base.

However, XRegExp conflicts with jQuery.  In IE, any page that includes XRegExp and runs a numeric jQuery animation will result in “TypeError: Object doesn't support this property or method”.

Demo (only fails in IE)

This bug is caused by an XRegExp fix for an IE bug in which the exec method doesn't consistently return undefined for nonparticipating capturing groups.  The fix, on line 271, assumes that the parameter passed to exec is a string.  This behavior violates the ECMAScript standard (section 15.10.6.2), which states that the parameter to exec should be converted to a string before proceeding.

jQuery relies on this behavior in its animate method, which parses a number using a regex to get the decimal portion.  (source)

Thus, calling animate with a number after loading XRegExp will fail in IE when XRegExp tries to call slice on a number.

Fortunately, it is very simple to fix XRegExp to convert its argument to a string first:

if (XRegExp) {
    var xExec = RegExp.prototype.exec;
    RegExp.prototype.exec = function(str) {
        if (!str.slice) 
            str = String(str);
        return xExec.call(this, str);
    };
}
Here is an updated demo that uses this fix and works even in IE.

30 comments:

Thanks this really saved me ...

Is this fixed at http://xregexp.com/ now?

@LeoB: Given that the last released version was in 2010, one and a half years before I wrote this, I rather doubt it.

http://xregexp.com/history/

You may be right.

I just sent a mail to Steve.

Exactly the fix I needed. Thanks!

This has finally (!) been fixed in XRegExp 1.5.1. Thanks to both of you for reporting it.

I've been also been wondering how to figure this out.

May be tough for non-coders who are looking to implement this on their site.

These tips are very helpful.
Penelope

The above article is nice and interesting, thank you willing to share! Greetings success of admin Percetakan Murah Rawamangun Jakarta Timur wish you deign to visit my website, thank you :)

This is one of the most informative post about Dissertation Help Service. I bookmarked this post and share with friends as well.

This is very nice blog i like this blog very much. here more than one important beautiful works will be displayed with quality essays
.

I love reading very much. Your article seemed instructive to me. Since I'm learning I'm interested in everything! And recently I was faced with the task of writing an ib extended essay. I sat long enough to realize that the task was too difficult for me. So I turned to the writing service, and I did great! Since I think the help is not plaintive, but instructive!

This is a very nice one and gives in-depth information. I am really happy with the quality and presentation of the article.
Full stack Training in Indore

I hope there would be an extension that would work like as XRegExp breaks jQuery animations. Can I know the name of such extension if it exists? Dissertation Proposal Writing Service

Deadlines are pretty hard on students. If a newbie enters a programming class, he needs to pick up the pace on time and finish off all the Java assignments on time as other students in the class. But it is not always possible for each and every student to finish the task on time. They need to handle other subjects too. But deadlines never wait for anyone, and if not submitted within the stipulated time, the assignments will get rejected by the professor. So, the student needs to clear the assignments on time. Hence, they look for Java programming assignment help at the hour of need.

Make sure the surface where you are placing the printer is clean and close to Pc or laptop.Check the shipped components with your inkjet printer
http //ij.start.canon,
https //ij.start.cannon

Thank you for the motivational article. It sparked my imagination. Very beneficial to me!
coloring pages

Amazing website, Love it. Great work done. Nice website. Love it. This is really nice.
Hbomax/tvsignin
Disneyplus.com/Begin
Disneyplus com login begin
Cricut.com/setup

POSITIVE SITE COME UP WITH THE INFORMATION ON THIS POSTING? I'M PLEASED I DISCOVERED IT THOUGH, ILL BE CHECKING BACK SOON TO FIND OUT WHAT ADDITIONAL POSTS YOU INCLUDE. THA NKS TO THIS!
고스톱

YOUR WEBSITE IS VERY VALUABLE. THANKS FOR SHARING.
스포츠토토

HI! THANKS FOR CREATING THIS BEAUTIFUL POST, IT'S REALLY NICE.
일본야동

You are talking about "XRegExp". XRegExp is an open source JavaScript library that provides an augmented cross-browser implementation of regular expressions. Now its time to avail Moving company in Tuscaloosa, AL for more information.

This comment has been removed by the author.

The speaker acknowledges the lack of specific information or reviews about "slaks" in their training data, which covers up until September 2021. The term could refer to various products, services, brands, or entities. To find reviews or information on "slaks" or the specific topic, they suggest providing more context or conducting an online search using relevant keywords to narrow down your query.abogado de accidentes

An open source JavaScript library that provides an augmented, extensible, cross-browser implementation of regular expressions, including support for additional syntax, flags, and methods. This post proved to be best essay help for me

The article "XRegExp Breaks jQuery Animations" reveals a potential conflict between XRegExp and jQuery animations, potentially saving developers time and debugging. It emphasizes the importance of testing and considering potential conflicts when integrating different libraries. The article serves as a valuable warning for developers working with XRegExp and jQuery, emphasizing the need for careful consideration during implementation. Offering a workaround or solution could be beneficial.
New York Divorce Laws Adultery

Post a Comment