Skip to main content

Bug Tracker

Side navigation

#979 closed bug (fixed)

Opened February 19, 2007 07:33PM UTC

Closed February 25, 2007 01:29PM UTC

Last modified June 21, 2007 04:26AM UTC

Metadata: class metadata breaks removeClass in Opera

Reported by: joern Owned by:
Priority: major Milestone: 1.1.2
Component: plugin Version: 1.1.1
Keywords: Cc:
Blocked by: Blocking:
Description

Opera throws this exception:

JavaScript - http://localhost/plugins/validate/demo-test/validate-demo.html
Event thread: submit
Error:
name: SyntaxError
message: Statement on line 1312: RegExp.prototype.compile: syntax error in pattern or string
Backtrace:
  Line 1312 of linked script http://localhost/plugins/validate/demo-test/js/jquery.js
    return t && new RegExp("(^|\\s)" + c + "(\\s|$)").test(t);
  Line 1305 of linked script http://localhost/plugins/validate/demo-test/js/jquery.js
    return ! jQuery.className.has(c, cur);
  Line 1634 of linked script http://localhost/plugins/validate/demo-test/js/jquery.js
    if (! inv && fn(elems[i], i) || inv && ! fn(elems[i], i))
        Line 1306 of linked script http://localhost/plugins/validate/demo-test/js/jquery.js
    elem.className = c ? jQuery.grep(elem.className.split(/s+/), (function (cur)
{
  return ! jQuery.className.has(c, cur);
}
)).join(" ") : "";
  Line 2103 of linked script http://localhost/plugins/validate/demo-test/js/jquery.js
    jQuery.className.remove(this, c);
  Line 1273 of linked script http://localhost/plugins/validate/demo-test/js/jquery.js
    if (fn.apply(obj[i], args || [i, obj[i]]) === false)
          Line 310 of linked script http://localhost/plugins/validate/demo-test/js/jquery.js
    return jQuery.each(this, fn, args);
  Line 2118 of linked script http://localhost/plugins/validate/demo-test/js/jquery.js
    return this.each(n, arguments);
  Line 328 of linked script http://localhost/plugins/validate/jquery.validate.js
    $(element).removeClass(this.settings.errorClass);
  Line 315 of linked script http://localhost/plugins/validate/jquery.validate.js
    instance.validateElement(this);
  Line 1273 of linked script http://localhost/plugins/validate/demo-test/js/jquery.js
    if (fn.apply(obj[i], args || [i, obj[i]]) === false)
          Line 310 of linked script http://localhost/plugins/validate/demo-test/js/jquery.js
    return jQuery.each(this, fn, args);
  Line 316 of linked script http://localhost/plugins/validate/jquery.validate.js
    this.elements.each((function ()
{
  instance.validateElement(this);
}
));
  Line 232 of linked script http://localhost/plugins/validate/jquery.validate.js
    return validator.validateForm();
  Line 2819 of linked script http://localhost/plugins/validate/demo-test/js/jquery.js
    if (c[j].apply(this, args) === false)
          At unknown location
    [statement source code not available]

A test was added to the metadata testsuite:

test("try to add and remove classes on metadata elements", function() {
	$("#two li").addClass("foobar").addClass("foo bar").removeClass("foobar");
	ok( $("#two li").is(".foo") );
	ok( $("#two li").is(".bar") );
});
Attachments (0)
Change History (4)

Changed February 21, 2007 04:05AM UTC by aheimlich comment:1

Perhaps this is because metadata uses JSON syntax and parts of it (namely { : }) are also part of regular expression syntax.

You might want to try something like this:

has: function( t, c ) {
    t = t.className || t;
    t.replace(/([.\\+*?[^]$(){}=!<>|:])/g, "\\$1");
    return t && new RegExp("(^|\\s)" + c + "(\\s|$)").test( t );
}

the second line was inspired by PHP's preg_quote

Another option is to simply dump regular expressions entirely within jQuery.class.has().

Changed February 25, 2007 01:12PM UTC by joern comment:2

component: ajaxplugin

Both solutions seem valid. I wonder what would perform better, or if this has any performance impact at all.

Changed February 25, 2007 01:15PM UTC by joern comment:3

This works in Opera:

has: function( t, c ) {
	t = t.className || t;
	c = c.replace(/([.\\+*?[^]$(){}=!<>|:])/g, "\\$1");
	return t && new RegExp("(^|\\s)" + c + "(\\s|$)").test( t );
}

Changed February 25, 2007 01:29PM UTC by joern comment:4

resolution: → fixed
status: newclosed

Fixed in revision [1415].