diff --git a/NEWS.md b/NEWS.md index 480f1957..138a4c66 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,7 @@ Released 2019-mm-dd Announcements: - Removed `jshint` as linter in favour of `eslint` to check syntax, find problems, and enforce code style. +- Upgrade `camshaft` to [`0.65.0`](https://github.com/CartoDB/camshaft/blob/9e8e5cd09dbfc6886c40f3f4a356fb7f235e82be/CHANGELOG.md#0650): Use quoted identifiers for column names. ## 8.0.0 Released 2019-11-13 diff --git a/lib/api/middlewares/custom-profile.js b/lib/api/middlewares/custom-profile.js new file mode 100644 index 00000000..16ce6f9f --- /dev/null +++ b/lib/api/middlewares/custom-profile.js @@ -0,0 +1,13 @@ +'use strict'; + +module.exports = function customProfile () { + return function customProfileMiddleware (req, res, next) { + const layergroupid = res.get('X-Layergroup-Id') || req.params.token; + + if (layergroupid) { + req.profiler.add({ layergroupid }); + } + + next(); + }; +}; diff --git a/lib/backends/cluster.js b/lib/backends/cluster.js index 6a3429f0..54448c36 100644 --- a/lib/backends/cluster.js +++ b/lib/backends/cluster.js @@ -7,6 +7,7 @@ const AggregationMapConfig = require('../models/aggregation/aggregation-mapconfi const WebMercatorHelper = require('cartodb-query-tables').utils.webMercatorHelper; const webmercator = new WebMercatorHelper(); +const queryUtils = require('../../lib/utils/query-utils'); module.exports = class ClusterBackend { getClusterFeatures (mapConfigProvider, params, callback) { @@ -89,7 +90,7 @@ function getColumnsName (pg, query, callback) { const fields = resultSet.fields || []; const columnNames = fields.map(field => field.name) - .filter(columnName => !SKIP_COLUMNS[columnName]); + .filter(columnName => !SKIP_COLUMNS[queryUtils.stripQuotes(columnName)]); return callback(null, columnNames); }, true); diff --git a/lib/models/mapconfig/adapter/analysis-mapconfig-adapter.js b/lib/models/mapconfig/adapter/analysis-mapconfig-adapter.js index a20347d5..29ffdabf 100644 --- a/lib/models/mapconfig/adapter/analysis-mapconfig-adapter.js +++ b/lib/models/mapconfig/adapter/analysis-mapconfig-adapter.js @@ -4,6 +4,7 @@ var queue = require('queue-async'); var debug = require('debug')('windshaft:analysis'); var camshaft = require('camshaft'); +const queryUtils = require('../../../../lib/utils/query-utils'); var dot = require('dot'); dot.templateSettings.strip = false; @@ -186,7 +187,7 @@ var SKIP_COLUMNS = { function skipColumns (columnNames) { return columnNames - .filter(function (columnName) { return !SKIP_COLUMNS[columnName]; }); + .filter(function (columnName) { return !SKIP_COLUMNS[queryUtils.stripQuotes(columnName)]; }); } var wrappedQueryTpl = dot.template([ diff --git a/lib/utils/query-utils.js b/lib/utils/query-utils.js index 02c0b28d..90c1a405 100644 --- a/lib/utils/query-utils.js +++ b/lib/utils/query-utils.js @@ -134,6 +134,19 @@ function substituteTokensForZoom (sql, zoom) { return SubstitutionTokens.replaceXYZ(sql, { z: zoom, bbox: bbox }); } +/** + * Strips leading and trailing quotes (") from a string + * @param {String} columnName, e.g. ("cartodb_id") + * @returns {String}, e.g. (cartodb_id) + */ +module.exports.stripQuotes = function (columnName) { + const quotedName = columnName.length > 2 && columnName[0] === '"' && columnName[columnName.length - 1] === '"'; + if (quotedName) { + return columnName.substring(1, columnName.length - 1); + } + return columnName; +}; + module.exports.queryPromise = queryPromise; module.exports.getQueryLimited = getQueryLimited; module.exports.substituteDummyTokens = substituteDummyTokens; diff --git a/package-lock.json b/package-lock.json index e2f45788..54094b23 100644 --- a/package-lock.json +++ b/package-lock.json @@ -442,14 +442,6 @@ } } }, - "boom": { - "version": "4.3.1", - "resolved": "https://registry.npmjs.org/boom/-/boom-4.3.1.tgz", - "integrity": "sha1-T4owBctKfjiJ90kDD9JbluAdLjE=", - "requires": { - "hoek": "4.x.x" - } - }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -510,9 +502,9 @@ "integrity": "sha1-MvxLn82vhF/N9+c7uXysImHwqwo=" }, "camshaft": { - "version": "0.64.2", - "resolved": "https://registry.npmjs.org/camshaft/-/camshaft-0.64.2.tgz", - "integrity": "sha512-BWXD8zoKmVaHZHAVFUVM/VrlXNQ+lcJFQSDSFcljRS4Yj4yuyEOs22DyULEI0dq3Xnkhwx14gUlhuFd/PgFxbA==", + "version": "0.65.0", + "resolved": "https://registry.npmjs.org/camshaft/-/camshaft-0.65.0.tgz", + "integrity": "sha512-oOUQId9H/8zRH2dQPQ30D0dV+6O9iOxQiDm5KFkI2HnKFSq1lhwbU+WLi+etmg3HZpM3GfxeC3dlJelog5kxoQ==", "requires": { "async": "^1.5.2", "bunyan": "1.8.1", @@ -520,45 +512,16 @@ "cartodb-query-tables": "^0.6.1", "debug": "^3.1.0", "dot": "^1.0.3", - "request": "2.85.0" + "request": "^2.85.0" }, "dependencies": { "cartodb-query-tables": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/cartodb-query-tables/-/cartodb-query-tables-0.6.1.tgz", - "integrity": "sha512-hQR9F5tQ6W6uGZk8Us/0fwkAsvYfbsHUzyKqBqDYue+jOa7FrGS+KpWokdLYHhR/ye3N3iR9RBTrIkwp6aoUww==", + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/cartodb-query-tables/-/cartodb-query-tables-0.6.3.tgz", + "integrity": "sha512-ijHl2Roh+0B1pP8SL3guEAu8tE6yNN3J/oxdUWCFOSKjHmXjwTzyJdjO+tONGcERmlWfS594SCFYElGIweSnQg==", "requires": { "decimal.js": "10.2.0" } - }, - "request": { - "version": "2.85.0", - "resolved": "https://registry.npmjs.org/request/-/request-2.85.0.tgz", - "integrity": "sha512-8H7Ehijd4js+s6wuVPLjwORxD4zeuyjYugprdOXlPSqaApmL/QOy+EB/beICHVCHkGMKNh5rvihb5ov+IDw4mg==", - "requires": { - "aws-sign2": "~0.7.0", - "aws4": "^1.6.0", - "caseless": "~0.12.0", - "combined-stream": "~1.0.5", - "extend": "~3.0.1", - "forever-agent": "~0.6.1", - "form-data": "~2.3.1", - "har-validator": "~5.0.3", - "hawk": "~6.0.2", - "http-signature": "~1.2.0", - "is-typedarray": "~1.0.0", - "isstream": "~0.1.2", - "json-stringify-safe": "~5.0.1", - "mime-types": "~2.1.17", - "oauth-sign": "~0.8.2", - "performance-now": "^2.1.0", - "qs": "~6.5.1", - "safe-buffer": "^5.1.1", - "stringstream": "~0.0.5", - "tough-cookie": "~2.3.3", - "tunnel-agent": "^0.6.0", - "uuid": "^3.1.0" - } } } }, @@ -614,7 +577,7 @@ }, "carto": { "version": "github:cartodb/carto#85881d99dd7fcf2c4e16478b04db67108d27a50c", - "from": "github:cartodb/carto#0.15.1-cdb5", + "from": "github:cartodb/carto#master", "requires": { "mapnik-reference": "~6.0.2", "optimist": "~0.6.0", @@ -888,24 +851,6 @@ "which": "^1.2.9" } }, - "cryptiles": { - "version": "3.1.4", - "resolved": "https://registry.npmjs.org/cryptiles/-/cryptiles-3.1.4.tgz", - "integrity": "sha512-8I1sgZHfVwcSOY6mSGpVU3lw/GSIZvusg8dD2+OGehCJpOhQRLNcH0qb9upQnOH4XhgxxFJSg6E2kx95deb1Tw==", - "requires": { - "boom": "5.x.x" - }, - "dependencies": { - "boom": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/boom/-/boom-5.2.0.tgz", - "integrity": "sha512-Z5BTk6ZRe4tXXQlkqftmsAUANpXmuwlsF5Oov8ThoMbQRzdGTA1ngYRW160GexgOgjsFOKJz0LYhoNi+2AMBUw==", - "requires": { - "hoek": "4.x.x" - } - } - } - }, "d3": { "version": "3.5.17", "resolved": "https://registry.npmjs.org/d3/-/d3-3.5.17.tgz", @@ -3156,11 +3101,6 @@ "nan": "^2.3.4" } }, - "hoek": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/hoek/-/hoek-4.2.1.tgz", - "integrity": "sha512-QLg82fGkfnJ/4iy1xZ81/9SIJiq1NGFUMGs6ParyjBZr6jW2Ufj/snDqTHixNlHdPNwN2RLVD0Pi3igeK9+JfA==" - }, "hosted-git-info": { "version": "2.8.5", "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.5.tgz", @@ -5253,14 +5193,6 @@ } } }, - "sntp": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/sntp/-/sntp-2.1.0.tgz", - "integrity": "sha512-FL1b58BDrqS3A11lJ0zEdnJ3UOKqVxawAkF3k7F0CVN7VQ34aZrV+G8BZ1WC9ZL7NyrwsW0oviwsWDgRuVYtJg==", - "requires": { - "hoek": "4.x.x" - } - }, "source-map": { "version": "0.5.7", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", @@ -5439,11 +5371,6 @@ "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=" }, - "stringstream": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.6.tgz", - "integrity": "sha512-87GEBAkegbBcweToUrdzf3eLhWNg06FJTebl4BVJz/JgWy8CvEr9dRtX5qWphiynMSQlxxi+QqN0z5T32SLlhA==" - }, "strip-ansi": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", @@ -5756,22 +5683,6 @@ "d3": "3.5.17", "turbo-carto": "^0.21.1", "turf-jenks": "~1.0.1" - }, - "dependencies": { - "carto": { - "version": "github:cartodb/carto#85881d99dd7fcf2c4e16478b04db67108d27a50c", - "from": "github:cartodb/carto#master", - "requires": { - "mapnik-reference": "~6.0.2", - "optimist": "~0.6.0", - "underscore": "1.8.3" - } - }, - "underscore": { - "version": "1.8.3", - "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.8.3.tgz", - "integrity": "sha1-Tz+1OxBuYJf8+ctBCfKl6b36UCI=" - } } }, "tough-cookie": { @@ -5983,6 +5894,15 @@ "torque.js": "3.1.1" }, "dependencies": { + "carto": { + "version": "github:cartodb/carto#85881d99dd7fcf2c4e16478b04db67108d27a50c", + "from": "github:cartodb/carto#0.15.1-cdb5", + "requires": { + "mapnik-reference": "~6.0.2", + "optimist": "~0.6.0", + "underscore": "1.8.3" + } + }, "cartodb-query-tables": { "version": "0.6.3", "resolved": "https://registry.npmjs.org/cartodb-query-tables/-/cartodb-query-tables-0.6.3.tgz", @@ -5990,6 +5910,11 @@ "requires": { "decimal.js": "10.2.0" } + }, + "underscore": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.8.3.tgz", + "integrity": "sha1-Tz+1OxBuYJf8+ctBCfKl6b36UCI=" } } }, @@ -6160,9 +6085,9 @@ }, "dependencies": { "glob": { - "version": "7.1.5", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.5.tgz", - "integrity": "sha512-J9dlskqUXK1OeTOYBEn5s8aMukWMwWfs+rPTn/jn50Ux4MNXVhubL1wu/j2t+H4NVI+cXEcCaYellqaPVGXNqQ==", + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", + "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", "requires": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", diff --git a/package.json b/package.json index fe685cf3..d2057269 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "@carto/fqdn-sync": "0.2.2", "basic-auth": "2.0.0", "body-parser": "1.18.3", - "camshaft": "^0.64.2", + "camshaft": "^0.65.0", "cartodb-psql": "0.14.0", "cartodb-query-tables": "^0.7.0", "cartodb-redis": "2.1.0",