From 289d4e0066570659792591220cfcaf5458153b73 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Tue, 11 Jan 2011 12:58:15 -0500 Subject: [PATCH] Model::escape() now coerces non-string (non-falsy) values to strings before escaping them. --- backbone.js | 2 +- test/model.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/backbone.js b/backbone.js index 356405b9..022bf6b1 100644 --- a/backbone.js +++ b/backbone.js @@ -160,7 +160,7 @@ var html; if (html = this._escapedAttributes[attr]) return html; var val = this.attributes[attr]; - return this._escapedAttributes[attr] = escapeHTML(val == null ? '' : val); + return this._escapedAttributes[attr] = escapeHTML(val == null ? '' : '' + val); }, // Returns `true` if the attribute contains a value that is not null diff --git a/test/model.js b/test/model.js index 5a313dc9..c08e9a20 100644 --- a/test/model.js +++ b/test/model.js @@ -110,6 +110,8 @@ $(document).ready(function() { equals(doc.escape('audience'), 'Bill & Bob'); doc.set({audience: 'Tim > Joan'}); equals(doc.escape('audience'), 'Tim > Joan'); + doc.set({audience: 10101}); + equals(doc.escape('audience'), '10101'); doc.unset('audience'); equals(doc.escape('audience'), ''); });