From 977ecbeb29e854254e9b5daac73b09ccfb48e7b3 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Mon, 21 Jan 2013 10:06:51 +0100 Subject: [PATCH] Return an error when "the_geom" is in skipfield for SVG output Closes #73 --- NEWS.md | 1 + app/controllers/app.js | 3 +++ test/acceptance/export/svg.js | 42 +++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/NEWS.md b/NEWS.md index 81114efe..e119673e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,7 @@ * Improve mixed-geometry export error message (#78) * Remove NULL the_geom features from topojson output (#80) * Fix crash when issuing SQL "COPY" command +* Return an error when "the_geom" is in skipfield for SVG output (#73) 1.3.3 (11/01/13) ----- diff --git a/app/controllers/app.js b/app/controllers/app.js index 26422f30..821f17a8 100755 --- a/app/controllers/app.js +++ b/app/controllers/app.js @@ -373,6 +373,9 @@ function toSVG(rows, gn, callback){ var lines = []; var points = []; _.each(rows, function(ele){ + if ( ! ele.hasOwnProperty(gn) ) { + throw new Error('column "' + gn + '" does not exist'); + } var g = ele[gn]; if ( ! g ) return; // null or empty var gdims = ele[gn + '_dimension']; diff --git a/test/acceptance/export/svg.js b/test/acceptance/export/svg.js index 6bcd1dbd..a335dde8 100644 --- a/test/acceptance/export/svg.js +++ b/test/acceptance/export/svg.js @@ -136,4 +136,46 @@ test('GET /api/v1/sql with SVG format and trimmed decimals', function(done){ }); }); +// Test adding "the_geom" to skipfields +// See http://github.com/Vizzuality/CartoDB-SQL-API/issues/73 +test('SVG format with "the_geom" in skipfields', function(done){ + var query = querystring.stringify({ + q: "SELECT 1 as cartodb_id, ST_MakePoint(5000, -54) AS the_geom ", + format: "svg", + skipfields: "the_geom" + }); + assert.response(app, { + url: '/api/v1/sql?' + query, + headers: {host: 'vizzuality.cartodb.com'}, + method: 'GET' + },{ }, function(res){ + assert.equal(res.statusCode, 400, res.statusCode + ': ' + res.body); + + assert.deepEqual(JSON.parse(res.body), { + error:['column "the_geom" does not exist'] + }); + done(); + }); +}); + +test('SVG format with missing "the_geom" field', function(done){ + var query = querystring.stringify({ + q: "SELECT 1 as cartodb_id, ST_MakePoint(5000, -54) AS something_else ", + format: "svg" + }); + assert.response(app, { + url: '/api/v1/sql?' + query, + headers: {host: 'vizzuality.cartodb.com'}, + method: 'GET' + },{ }, function(res){ + assert.equal(res.statusCode, 400, res.statusCode + ': ' + res.body); + assert.deepEqual(JSON.parse(res.body), { + error:['column "the_geom" does not exist'] + }); + done(); + }); +}); + + + });