From 575fe8e3504d1462a309a3984a82e877c034f617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Thu, 24 Oct 2019 19:18:47 +0200 Subject: [PATCH] Remove unnecessary escape usage --- lib/api/map/tile-layergroup-controller.js | 2 +- lib/backends/template-maps.js | 4 ++-- lib/models/aggregation/time-dimension.js | 2 +- lib/utils/overviews-query-rewriter.js | 5 ++--- lib/utils/table-name-parser.js | 4 ++-- test/acceptance/analysis/named-maps-test.js | 4 ++-- test/acceptance/cluster-test.js | 4 ++-- test/acceptance/named-maps-static-view-test.js | 4 ++-- test/acceptance/ported/static-maps-test.js | 2 +- test/acceptance/turbo-carto/error-cases-test.js | 2 +- test/unit/error-middleware-test.js | 2 +- 11 files changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/api/map/tile-layergroup-controller.js b/lib/api/map/tile-layergroup-controller.js index 1db97a82..a067c2e6 100644 --- a/lib/api/map/tile-layergroup-controller.js +++ b/lib/api/map/tile-layergroup-controller.js @@ -45,7 +45,7 @@ module.exports = class TileLayergroupController { route (mapRouter) { // REGEXP: doesn't match with `val` - const not = (val) => `(?!${val})([^\/]+?)`; + const not = (val) => `(?!${val})([^\/]+?)`; // eslint-disable-line no-useless-escape // Sadly the path that matches 1 also matches with 2 so we need to tell to express // that performs only the middlewares of the first path that matches diff --git a/lib/backends/template-maps.js b/lib/backends/template-maps.js index d84e30dc..01468061 100644 --- a/lib/backends/template-maps.js +++ b/lib/backends/template-maps.js @@ -81,7 +81,7 @@ TemplateMaps.prototype._redisCmd = function (redisFunc, redisArgs, callback) { }); }; -var _reValidNameIdentifier = /^[a-z0-9][0-9a-z_\-]*$/i; +var _reValidNameIdentifier = /^[a-z0-9][0-9a-z_-]*$/i; var _reValidPlaceholderIdentifier = /^[a-z][0-9a-z_]*$/i; // jshint maxcomplexity:15 TemplateMaps.prototype._checkInvalidTemplate = function (template) { @@ -429,7 +429,7 @@ TemplateMaps.prototype.isAuthorized = function (template, authTokens) { // // @throws Error on malformed template or parameter // -var _reNumber = /^([-+]?[\d\.]?\d+([eE][+-]?\d+)?)$/; +var _reNumber = /^([-+]?[\d\.]?\d+([eE][+-]?\d+)?)$/; // eslint-disable-line no-useless-escape var _reCSSColorName = /^[a-zA-Z]+$/; var _reCSSColorVal = /^#[0-9a-fA-F]{3,6}$/; diff --git a/lib/models/aggregation/time-dimension.js b/lib/models/aggregation/time-dimension.js index 0ed32123..7f023f01 100644 --- a/lib/models/aggregation/time-dimension.js +++ b/lib/models/aggregation/time-dimension.js @@ -28,7 +28,7 @@ function timeExpression (t, tz) { function epochWithDefaults (epoch) { /* jshint maxcomplexity:9 */ // goddammit linter, I like this as is!! - const format = /^(\d\d\d\d)(?:\-?(\d\d)(?:\-?(\d\d)(?:[T\s]?(\d\d)(?:(\d\d)(?:\:(\d\d))?)?)?)?)?$/; + const format = /^(\d\d\d\d)(?:\-?(\d\d)(?:\-?(\d\d)(?:[T\s]?(\d\d)(?:(\d\d)(?:\:(\d\d))?)?)?)?)?$/; // eslint-disable-line no-useless-escape const match = (epoch || '').match(format) || []; const year = match[1] || '0001'; const month = match[2] || '01'; diff --git a/lib/utils/overviews-query-rewriter.js b/lib/utils/overviews-query-rewriter.js index 759636a5..8eac3c54 100644 --- a/lib/utils/overviews-query-rewriter.js +++ b/lib/utils/overviews-query-rewriter.js @@ -118,7 +118,7 @@ function replace_table_in_query (sql, old_table_name, replacement) { // since the pattern matches the first character of the table // it must be put back in the replacement text replacement = '$01' + replacement; - return '([^\.a-z0-9_]|^)'; + return '([^\.a-z0-9_]|^)'; // eslint-disable-line no-useless-escape } } @@ -299,8 +299,7 @@ function should_use_overviews (query, data) { } function is_supported_query (sql) { - var basic_query = - /\s*SELECT\s+[\*a-z0-9_,\s]+?\s+FROM\s+((\"[^"]+\"|[a-z0-9_]+)\.)?(\"[^"]+\"|[a-z0-9_]+)\s*;?\s*/i; + var basic_query = /\s*SELECT\s+[\*a-z0-9_,\s]+?\s+FROM\s+((\"[^"]+\"|[a-z0-9_]+)\.)?(\"[^"]+\"|[a-z0-9_]+)\s*;?\s*/i; // eslint-disable-line no-useless-escape var unwrapped_query = new RegExp('^' + basic_query.source + '$', 'i'); // queries for named maps are wrapped like this: var wrapped_query = new RegExp( diff --git a/lib/utils/table-name-parser.js b/lib/utils/table-name-parser.js index 924a82b5..110cb999 100644 --- a/lib/utils/table-name-parser.js +++ b/lib/utils/table-name-parser.js @@ -3,7 +3,7 @@ // Quote an PostgreSQL identifier if ncecessary function quote_identifier_if_needed (txt) { if (txt && !txt.match(/^[a-z_][a-z_0-9]*$/)) { - return '"' + txt.replace(/\"/g, '""') + '"'; + return '"' + txt.replace(/"/g, '""') + '"'; } else { return txt; } @@ -16,7 +16,7 @@ function parse_table_name (table) { // parse table into 'parts' that may be quoted, each part // in the parts array being an object { part: 'text', quoted: false/true } var parts = []; - var splitted = table_name.split(/\"/); + var splitted = table_name.split(/"/); for (var i = 0; i < splitted.length; i++) { if (splitted[i] === '') { if (parts.length > 0 && i < splitted.length - 1) { diff --git a/test/acceptance/analysis/named-maps-test.js b/test/acceptance/analysis/named-maps-test.js index 8b01db58..d04beadd 100644 --- a/test/acceptance/analysis/named-maps-test.js +++ b/test/acceptance/analysis/named-maps-test.js @@ -302,10 +302,10 @@ describe('named-maps analysis', function () { assert.deepStrictEqual( JSON.parse(res.body), { - errors: ['Unsupported image format \"gif\"'], + errors: ['Unsupported image format "gif"'], errors_with_context: [{ type: 'unknown', - message: 'Unsupported image format \"gif\"' + message: 'Unsupported image format "gif"' }] } ); diff --git a/test/acceptance/cluster-test.js b/test/acceptance/cluster-test.js index c2e95735..65b2e16c 100644 --- a/test/acceptance/cluster-test.js +++ b/test/acceptance/cluster-test.js @@ -612,10 +612,10 @@ describe('cluster', function () { }; const invalidColumnExpressionsError = { - errors: ['column \"wadus\" does not exist'], + errors: ['column "wadus" does not exist'], errors_with_context: [ { - message: 'column \"wadus\" does not exist', + message: 'column "wadus" does not exist', type: 'unknown' } ] diff --git a/test/acceptance/named-maps-static-view-test.js b/test/acceptance/named-maps-static-view-test.js index ee926e5b..370f9034 100644 --- a/test/acceptance/named-maps-static-view-test.js +++ b/test/acceptance/named-maps-static-view-test.js @@ -330,10 +330,10 @@ describe('named maps static view', function () { assert.deepStrictEqual( JSON.parse(res.body), { - errors: ['Unsupported image format \"gif\"'], + errors: ['Unsupported image format "gif"'], errors_with_context: [{ type: 'unknown', - message: 'Unsupported image format \"gif\"' + message: 'Unsupported image format "gif"' }] } ); diff --git a/test/acceptance/ported/static-maps-test.js b/test/acceptance/ported/static-maps-test.js index 7a45fc4f..86b6fc65 100644 --- a/test/acceptance/ported/static-maps-test.js +++ b/test/acceptance/ported/static-maps-test.js @@ -141,7 +141,7 @@ describe('static_maps', function () { var parsedBody = JSON.parse(res.body); assert.ok(parsedBody.errors); assert.ok(parsedBody.errors.length); - assert.ok(parsedBody.errors[0].match(/column \"wadus\" does not exist/)); + assert.ok(parsedBody.errors[0].match(/column "wadus" does not exist/)); done(); }); }); diff --git a/test/acceptance/turbo-carto/error-cases-test.js b/test/acceptance/turbo-carto/error-cases-test.js index 91dede60..b4bdeafe 100644 --- a/test/acceptance/turbo-carto/error-cases-test.js +++ b/test/acceptance/turbo-carto/error-cases-test.js @@ -89,7 +89,7 @@ describe('turbo-carto error cases', function () { assert.strictEqual(layergroup.errors.length, 1); assert.ok(layergroup.errors[0].match(/^Failed\sto\sprocess/)); assert.ok(layergroup.errors[0].match(/unable\sto\scompute\sramp/i)); - assert.ok(layergroup.errors[0].match(/invalid\smethod\s\"wadusmethod\"/i)); + assert.ok(layergroup.errors[0].match(/invalid\smethod\s"wadusmethod"/i)); done(); }); diff --git a/test/unit/error-middleware-test.js b/test/unit/error-middleware-test.js index 3ae31bbb..0dc07b72 100644 --- a/test/unit/error-middleware-test.js +++ b/test/unit/error-middleware-test.js @@ -124,7 +124,7 @@ describe('error-middleware', function () { }); it('should escape chars that broke logs regex', function (done) { - const badString = 'error: ( ) = " \" \' * $ & |'; + const badString = 'error: ( ) = " \" \' * $ & |'; // eslint-disable-line no-useless-escape const escapedString = 'error '; const error = new Error(badString);