From f6a3395b405936f7d0d0248bef78fdc2f35b815a Mon Sep 17 00:00:00 2001 From: Rufus Pollock Date: Fri, 19 Oct 2012 07:57:47 +0100 Subject: [PATCH] [#258,model][xs]: tiny bugfix for cases where fields in raw state contain a non-string - fixes #258. --- src/model.js | 3 ++- test/model.test.js | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/model.js b/src/model.js index 712475a6..bd6b3799 100644 --- a/src/model.js +++ b/src/model.js @@ -105,11 +105,12 @@ my.Dataset = Backbone.Model.extend({ } // fields is an array of strings (i.e. list of field headings/ids) - if (fields && fields.length > 0 && typeof fields[0] === 'string') { + if (fields && fields.length > 0 && typeof(fields[0]) != 'object') { // Rename duplicate fieldIds as each field name needs to be // unique. var seen = {}; fields = _.map(fields, function(field, index) { + field = field.toString(); // cannot use trim as not supported by IE7 var fieldId = field.replace(/^\s+|\s+$/g, ''); if (fieldId === '') { diff --git a/test/model.test.js b/test/model.test.js index b5ca41c6..e6fb843a 100644 --- a/test/model.test.js +++ b/test/model.test.js @@ -180,6 +180,21 @@ test('_normalizeRecordsAndFields', function () { records: null }, }, + { + in_: { + fields: [ 1, 1, 3 ], + records: null + }, + exp: { + fields: [ + {id: '1'}, + {id: '11'}, + {id: '3'} + ], + records: null + }, + }, + // field is *not* a string // records array but no fields { in_: { @@ -267,6 +282,7 @@ test('_normalizeRecordsAndFields', function () { out = dataset._normalizeRecordsAndFields(item.in_.records, item.in_.fields); deepEqual(out, item.exp); }); + });