From 83a044f1b5a733dc7ea76dbc9b7dd3a3dc4b7f25 Mon Sep 17 00:00:00 2001 From: jeresig Date: Sat, 13 Feb 2010 02:18:38 -0500 Subject: [PATCH 1/1] Make sure that no extra whitespace is leftover after an addClass. Fixes #6050. --- src/attributes.js | 2 +- test/unit/attributes.js | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/attributes.js b/src/attributes.js index d217793..3e4c5f2 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -43,7 +43,7 @@ jQuery.fn.extend({ var className = " " + elem.className + " "; for ( var c = 0, cl = classNames.length; c < cl; c++ ) { if ( className.indexOf( " " + classNames[c] + " " ) < 0 ) { - elem.className += " " + classNames[c]; + elem.className = jQuery.trim( elem.className + " " + classNames[c] ); } } } diff --git a/test/unit/attributes.js b/test/unit/attributes.js index 70ae50d..234d586 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -435,7 +435,7 @@ test("val(Function) with incoming value", function() { }); var testAddClass = function(valueObj) { - expect(2); + expect(4); var div = jQuery("div"); div.addClass( valueObj("test") ); var pass = true; @@ -448,6 +448,15 @@ var testAddClass = function(valueObj) { var j = jQuery("#nonnodes").contents(); j.addClass( valueObj("asdf") ); ok( j.hasClass("asdf"), "Check node,textnode,comment for addClass" ); + + div = jQuery("
"); + + div.addClass( valueObj("test") ); + equals( div.attr("class"), "test", "Make sure there's no extra whitespace." ); + + div.attr("class", " foo"); + div.addClass( valueObj("test") ); + equals( div.attr("class"), "foo test", "Make sure there's no extra whitespace." ); }; test("addClass(String)", function() { -- 1.7.10.4