Skip to content
Permalink
Browse files

Handle carriage return characters in className property. Fixes #7673.

  • Loading branch information...
jitter committed Dec 1, 2010
1 parent e1d6edf commit df0a3fb8531a452a7b3c6eb7cd7eb7cd59b32d88
Showing with 9 additions and 5 deletions.
  1. +1 −1 src/attributes.js
  2. +8 −4 test/unit/attributes.js
@@ -1,6 +1,6 @@
(function( jQuery ) {

var rclass = /[\n\t]/g,
var rclass = /[\n\t\r]/g,
rspaces = /\s+/,
rreturn = /\r/g,
rspecialurl = /^(?:href|src|style)$/,
@@ -719,7 +719,7 @@ test("toggleClass(Fucntion[, boolean]) with incoming value", function() {
});

test("addClass, removeClass, hasClass", function() {
expect(14);
expect(17);

var jq = jQuery("<p>Hi</p>"), x = jq[0];

@@ -739,17 +739,21 @@ test("addClass, removeClass, hasClass", function() {
ok( jq.hasClass("hi"), "Check has1" );
ok( jq.hasClass("bar"), "Check has2" );

var jq = jQuery("<p class='class1\nclass2\tcla.ss3\n'></p>");
ok( jq.hasClass("class1"), "Check hasClass with carriage return" );
ok( jq.is(".class1"), "Check is with carriage return" );
var jq = jQuery("<p class='class1\nclass2\tcla.ss3\n\rclass4'></p>");
ok( jq.hasClass("class1"), "Check hasClass with line feed" );
ok( jq.is(".class1"), "Check is with line feed" );
ok( jq.hasClass("class2"), "Check hasClass with tab" );
ok( jq.is(".class2"), "Check is with tab" );
ok( jq.hasClass("cla.ss3"), "Check hasClass with dot" );
ok( jq.hasClass("class4"), "Check hasClass with carriage return" );
ok( jq.is(".class4"), "Check is with carriage return" );

jq.removeClass("class2");
ok( jq.hasClass("class2")==false, "Check the class has been properly removed" );
jq.removeClass("cla");
ok( jq.hasClass("cla.ss3"), "Check the dotted class has not been removed" );
jq.removeClass("cla.ss3");
ok( jq.hasClass("cla.ss3")==false, "Check the dotted class has been removed" );
jq.removeClass("class4");
ok( jq.hasClass("class4")==false, "Check the class has been properly removed" );
});

0 comments on commit df0a3fb

Please sign in to comment.
You can’t perform that action at this time.