From 5fe1a57fa5053ab2170258aca10032871dcd250b Mon Sep 17 00:00:00 2001 From: Ian Wojtowicz Date: Mon, 24 Jun 2013 14:19:47 -0700 Subject: [PATCH] Fix for column names with uppercase and whitespace characters. --- index.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index d67d8eb..f80c551 100644 --- a/index.js +++ b/index.js @@ -89,7 +89,7 @@ module.exports = function( ss_key, auth_id ){ var data_xml = '' + "\n"; Object.keys(data).forEach(function(key) { if (key != 'id' && key != 'title' && key != 'content' && key != '_links'){ - data_xml += '' + xmlSafeValue(data[key]) + '' + "\n" + data_xml += '' + xmlSafeValue(data[key]) + '' + "\n" } }); data_xml += ''; @@ -215,7 +215,7 @@ var SpreadsheetRow = function( spreadsheet, data, xml ){ data_xml = data_xml.replace('', ""); Object.keys( self ).forEach( function(key) { if (key.substr(0,1) != '_' && typeof( self[key] == 'string') ){ - data_xml = data_xml.replace( new RegExp('(.*?)'), ''+ xmlSafeValue(self[key]) +''); + data_xml = data_xml.replace( new RegExp('(.*?)'), ''+ xmlSafeValue(self[key]) +''); } }); spreadsheet.makeFeedRequest( self['_links']['edit'], 'PUT', data_xml, cb ); @@ -237,4 +237,10 @@ var xmlSafeValue = function(val){ .replace(//g, '>') .replace(/"/g, '"'); -} \ No newline at end of file +} +var xmlSafeColumnName = function(val){ + if (!val) return ''; + return String(val).replace(/\s+/g, '') + .toLowerCase(); +} +