From e48aeb72d5743ebf7c44bdefaa1aa4d89af695ca Mon Sep 17 00:00:00 2001 From: Jacob Beard Date: Mon, 9 Jul 2012 14:23:48 -0400 Subject: [PATCH] Fixed bug in node and browser platforms implementations of getDocumentFromUrl. --- lib/browser/platform.js | 2 +- lib/node/platform.js | 41 +++++++++++++++++------------------------ 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/lib/browser/platform.js b/lib/browser/platform.js index 37bec433..9713822b 100644 --- a/lib/browser/platform.js +++ b/lib/browser/platform.js @@ -8,7 +8,7 @@ module.exports = { getDocumentFromUrl : function(url,cb){ this.ajax.get(url,function(r){ cb(null,r); - },url).error(function(e){ + },"xml").error(function(e){ cb(e); }); }, diff --git a/lib/node/platform.js b/lib/node/platform.js index e544f984..9001f5b6 100644 --- a/lib/node/platform.js +++ b/lib/node/platform.js @@ -7,42 +7,35 @@ function parseDocumentFromString(str){ return (new xmldom.DOMParser()).parseFromString(str); } +function onModelCb(cb){ + return function(err,s){ + if(err){ + cb(err); + }else{ + try { + var doc = parseDocumentFromString(s); + cb(null,doc); + }catch(e){ + cb(e); + } + } + }; +} + module.exports = { pathSeparator : pathModule.join('x', 'x')[1], //used in parsing getDocumentFromUrl : function(url,cb){ - get.httpGet(url,function(err,s){ - if(err){ - cb(err); - }else{ - try { - var doc = this.parseDocumentFromString(s); - cb(null,doc); - }catch(e){ - cb(e); - } - } - }); + get.httpGet(url,onModelCb(cb)); }, parseDocumentFromString : parseDocumentFromString, //TODO: the callback is duplicate code. move this out. getDocumentFromFilesystem : function(path,cb){ - fs.readFile(path,'utf8',function(err,s){ - if(err){ - cb(err); - }else{ - try{ - var doc = parseDocumentFromString(s); - cb(null,doc); - }catch(e){ - cb(e); - } - } - }); + fs.readFile(path,'utf8',onModelCb(cb)); }, getResourceFromUrl : get.getResource,