From e797dd450cd800f93a102743a556a44899acc4f2 Mon Sep 17 00:00:00 2001 From: ironchefpython Date: Wed, 3 Oct 2012 15:37:13 -0400 Subject: [PATCH] squashed commits for issue 105 - test for numeric attributes --- .gitignore | 1 + lib/utils.js | 2 +- test/api.attributes.js | 7 +++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5027a7be66..1e2497a838 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ coverage.html lib-cov .coverage_data cover_html +.c9revisions diff --git a/lib/utils.js b/lib/utils.js index 75dfcc9864..5f5b64f134 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -26,5 +26,5 @@ exports.isTag = function(type) { * 0 = XML, 1 = HTML4 and 2 = HTML5 */ -exports.encode = function(str) { return entities.encode(str, 0); }; +exports.encode = function(str) { return entities.encode(String(str), 0); }; exports.decode = function(str) { return entities.decode(str, 2); }; diff --git a/test/api.attributes.js b/test/api.attributes.js index c7b953a3a8..e875ab88c8 100644 --- a/test/api.attributes.js +++ b/test/api.attributes.js @@ -52,6 +52,13 @@ describe('$(...)', function() { $apple.attr('href', 'http://github.com/">alert("XSS!")'); }); + + it('(key, value) : should coerce values to a string', function() { + var $apple = $('.apple', fruits); + $apple.attr('data-test', 1); + expect($apple[0].attribs['data-test']).to.equal('1'); + expect($apple.attr('data-test')).to.equal('1'); + }); }); describe('.removeAttr', function() {