Skip to content
Permalink
Browse files

Fix #11962. Standardize getter return values for empty sets.

  • Loading branch information...
antishok authored and dmethvin committed Jul 10, 2012
1 parent 376f4e8 commit 21b0db7993315f0a5390798fefe63eb21891493e
Showing with 14 additions and 3 deletions.
  1. +1 −1 src/manipulation.js
  2. +2 −2 src/offset.js
  3. +5 −0 test/unit/manipulation.js
  4. +6 −0 test/unit/offset.js
@@ -225,7 +225,7 @@ jQuery.fn.extend({
if ( value === undefined ) {
return elem.nodeType === 1 ?
elem.innerHTML.replace( rinlinejQuery, "" ) :
null;
undefined;
}

// See if we can take a shortcut and just use innerHTML
@@ -14,7 +14,7 @@ jQuery.fn.offset = function( options ) {
doc = elem && elem.ownerDocument;

if ( !doc ) {
return null;
return;
}

if ( (body = doc.body) === elem ) {
@@ -103,7 +103,7 @@ jQuery.fn.extend({

position: function() {
if ( !this[0] ) {
return null;
return;
}

var elem = this[0],
@@ -1351,6 +1351,11 @@ test("html(undefined)", function() {
equal( jQuery("#foo").html("<i>test</i>").html(undefined).html().toLowerCase(), "<i>test</i>", ".html(undefined) is chainable (#5571)" );
});

test("html() on empty set", function() {
expect(1);
strictEqual( jQuery( ).html(), undefined, ".html() returns undefined for empty sets (#11962)" );

This comment has been minimized.

Copy link
@rwaldron
});

var testHtml = function(valueObj) {
expect(35);

@@ -9,6 +9,12 @@ module("offset", { teardown: moduleTeardown });
the iframe window and the "jQuery" symbol is used to access any static methods.
*/

test("empty set", function() {
expect(2);
strictEqual( jQuery( ).offset(), undefined, "offset() returns undefined for empty set (#11962)" );

This comment has been minimized.

Copy link
@staabm

staabm Jul 10, 2012

Contributor

( ) vs () ?

This comment has been minimized.

Copy link
@antishok

antishok Jul 10, 2012

Author Contributor

Agreed. I'm wondering if I should commit & push to master and then PR, or commit to the issue branch, or open a whole new branch which seems excessive to me. Or is there some simple clean way for me to add a commit to this PR and re-open it?
(sorry, pretty new to git and jquery contrib)

This comment has been minimized.

Copy link
@dmethvin

dmethvin Jul 11, 2012

Member

This is no problem, I'll just edit it. You did the hard work, I should have noticed the space.

strictEqual( jQuery( ).position(), undefined, "position() returns undefined for empty set (#11962)" );
});

test("disconnected node", function() {
expect(2);

0 comments on commit 21b0db7

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