Skip to content

Commit

Permalink
Merge pull request #704 from Rycochet/master
Browse files Browse the repository at this point in the history
Fix for passing non-string values to .html or .text
  • Loading branch information
fb55 committed Feb 1, 2016
2 parents 1b9c5c9 + 2dc84d5 commit 9d98bd7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/api/manipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ exports.html = function(str) {
el.next = el.prev = el.parent = null;
});

var content = str.cheerio ? str.clone().get() : evaluate(str, opts);
var content = str.cheerio ? str.clone().get() : evaluate('' + str, opts);

updateDOM(content, el);
});
Expand Down Expand Up @@ -402,7 +402,7 @@ exports.text = function(str) {
});

var elem = {
data: str,
data: '' + str,
type: 'text',
parent: el,
prev: null,
Expand Down
12 changes: 12 additions & 0 deletions test/cheerio.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,18 @@ describe('cheerio', function() {
expect($empty.each).to.be($.prototype.each);
});

it('should set html(number) as a string', function() {
var $elem = $('<div>');
$elem.html(123);
expect(typeof $elem.text()).to.equal('string');
});

it('should set text(number) as a string', function() {
var $elem = $('<div>');
$elem.text(123);
expect(typeof $elem.text()).to.equal('string');
});

describe('.load', function() {

it('should generate selections as proper instances', function() {
Expand Down

0 comments on commit 9d98bd7

Please sign in to comment.