Do not use string concatenation when using __dirname and __filename

This commit is contained in:
Daniel García Aubert 2019-10-22 18:22:33 +02:00
parent da0d0d21e3
commit ad4a1ada45
12 changed files with 26 additions and 13 deletions

View File

@ -1,5 +1,7 @@
'use strict'; 'use strict';
const path = require('path');
const { Router: router } = require('express'); const { Router: router } = require('express');
const RedisPool = require('redis-mpool'); const RedisPool = require('redis-mpool');
@ -280,7 +282,7 @@ function createSurrogateKeysCacheBackends (serverOptions) {
return cacheBackends; return cacheBackends;
} }
const timeoutErrorTilePath = __dirname + '/../../assets/render-timeout-fallback.png'; const timeoutErrorTilePath = path.join(__dirname, '/../../assets/render-timeout-fallback.png');
const timeoutErrorTile = require('fs').readFileSync(timeoutErrorTilePath, { encoding: null }); const timeoutErrorTile = require('fs').readFileSync(timeoutErrorTilePath, { encoding: null });
function createRendererFactory ({ redisPool, serverOptions, environmentOptions }) { function createRendererFactory ({ redisPool, serverOptions, environmentOptions }) {

View File

@ -1,7 +1,8 @@
'use strict'; 'use strict';
const fs = require('fs'); const fs = require('fs');
const timeoutErrorVectorTile = fs.readFileSync(__dirname + '/../../../assets/render-timeout-fallback.mvt'); const path = require('path');
const timeoutErrorVectorTile = fs.readFileSync(path.join(__dirname, '/../../../assets/render-timeout-fallback.mvt'));
module.exports = function vectorError () { module.exports = function vectorError () {
return function vectorErrorMiddleware (err, req, res, next) { return function vectorErrorMiddleware (err, req, res, next) {

View File

@ -1,5 +1,6 @@
'use strict'; 'use strict';
var path = require('path');
var assert = require('../support/assert'); var assert = require('../support/assert');
var _ = require('underscore'); var _ = require('underscore');
var redis = require('redis'); var redis = require('redis');
@ -13,7 +14,7 @@ var semver = require('semver');
var helper = require('../support/test-helper'); var helper = require('../support/test-helper');
var LayergroupToken = require('../../lib/models/layergroup-token'); var LayergroupToken = require('../../lib/models/layergroup-token');
var windshaft_fixtures = __dirname + '/../../node_modules/windshaft/test/fixtures'; var windshaft_fixtures = path.join(__dirname, '/../../node_modules/windshaft/test/fixtures');
var IMAGE_EQUALS_TOLERANCE_PER_MIL = 20; var IMAGE_EQUALS_TOLERANCE_PER_MIL = 20;
var IMAGE_EQUALS_HIGHER_TOLERANCE_PER_MIL = 25; var IMAGE_EQUALS_HIGHER_TOLERANCE_PER_MIL = 25;

View File

@ -5,6 +5,7 @@ require('../../support/test-helper');
var assert = require('../../support/assert'); var assert = require('../../support/assert');
var testClient = require('./support/test-client'); var testClient = require('./support/test-client');
var fs = require('fs'); var fs = require('fs');
var path = require('path');
var http = require('http'); var http = require('http');
describe('blend layer filtering', function () { describe('blend layer filtering', function () {
@ -15,7 +16,7 @@ describe('blend layer filtering', function () {
before(function (done) { before(function (done) {
// Start a server to test external resources // Start a server to test external resources
httpRendererResourcesServer = http.createServer(function (request, response) { httpRendererResourcesServer = http.createServer(function (request, response) {
var filename = __dirname + '/../../fixtures/http/light_nolabels-1-0-0.png'; var filename = path.join(__dirname, '/../../fixtures/http/light_nolabels-1-0-0.png');
fs.readFile(filename, { encoding: 'binary' }, function (err, file) { fs.readFile(filename, { encoding: 'binary' }, function (err, file) {
response.writeHead(200); response.writeHead(200);
response.write(file, 'binary'); response.write(file, 'binary');

View File

@ -6,6 +6,7 @@ var assert = require('../../support/assert');
var testClient = require('./support/test-client'); var testClient = require('./support/test-client');
var fs = require('fs'); var fs = require('fs');
var http = require('http'); var http = require('http');
var path = require('path');
describe('blend http fallback', function () { describe('blend http fallback', function () {
var IMG_TOLERANCE_PER_MIL = 20; var IMG_TOLERANCE_PER_MIL = 20;
@ -19,9 +20,9 @@ describe('blend http fallback', function () {
response.writeHead(404); response.writeHead(404);
response.end(); response.end();
} else { } else {
var filename = __dirname + '/../../fixtures/http/light_nolabels-1-0-0.png'; var filename = path.join(__dirname, '/../../fixtures/http/light_nolabels-1-0-0.png');
if (request.url.match(/^\/dark\//)) { if (request.url.match(/^\/dark\//)) {
filename = __dirname + '/../../fixtures/http/dark_nolabels-1-0-0.png'; filename = path.join(__dirname, '/../../fixtures/http/dark_nolabels-1-0-0.png');
} }
fs.readFile(filename, { encoding: 'binary' }, function (err, file) { fs.readFile(filename, { encoding: 'binary' }, function (err, file) {
response.writeHead(200); response.writeHead(200);

View File

@ -7,6 +7,7 @@ var testClient = require('./support/test-client');
var serverOptions = require('./support/ported-server-options'); var serverOptions = require('./support/ported-server-options');
var fs = require('fs'); var fs = require('fs');
var http = require('http'); var http = require('http');
var path = require('path');
describe.skip('blend http client timeout', function () { describe.skip('blend http client timeout', function () {
var mapConfig = { var mapConfig = {
@ -43,7 +44,7 @@ describe.skip('blend http client timeout', function () {
// Start a server to test external resources // Start a server to test external resources
slowHttpRendererResourcesServer = http.createServer(function (request, response) { slowHttpRendererResourcesServer = http.createServer(function (request, response) {
setTimeout(function () { setTimeout(function () {
var filename = __dirname + '/../fixtures/http/light_nolabels-1-0-0.png'; var filename = path.join(__dirname, '/../fixtures/http/light_nolabels-1-0-0.png');
fs.readFile(filename, { encoding: 'binary' }, function (err, file) { fs.readFile(filename, { encoding: 'binary' }, function (err, file) {
response.writeHead(200); response.writeHead(200);
response.write(file, 'binary'); response.write(file, 'binary');

View File

@ -8,6 +8,7 @@ var PortedServerOptions = require('./support/ported-server-options');
var http = require('http'); var http = require('http');
var testClient = require('./support/test-client'); var testClient = require('./support/test-client');
var nock = require('nock'); var nock = require('nock');
var path = require('path');
describe('external resources', function () { describe('external resources', function () {
var res_serv; // resources server var res_serv; // resources server
@ -20,7 +21,7 @@ describe('external resources', function () {
// Start a server to test external resources // Start a server to test external resources
res_serv = http.createServer(function (request, response) { res_serv = http.createServer(function (request, response) {
++res_serv_status.numrequests; ++res_serv_status.numrequests;
var filename = __dirname + '/../../fixtures/markers' + request.url; var filename = path.join(__dirname, '/../../fixtures/markers', request.url);
fs.readFile(filename, 'binary', function (err, file) { fs.readFile(filename, 'binary', function (err, file) {
if (err) { if (err) {
response.writeHead(404, { 'Content-Type': 'text/plain' }); response.writeHead(404, { 'Content-Type': 'text/plain' });

View File

@ -3,6 +3,7 @@
require('../../support/test-helper'); require('../../support/test-helper');
var fs = require('fs'); var fs = require('fs');
var path = require('path');
var assert = require('../../support/assert'); var assert = require('../../support/assert');
var testClient = require('./support/test-client'); var testClient = require('./support/test-client');
@ -47,7 +48,7 @@ describe.skip('render limits', function () {
it('uses onTileErrorStrategy to handle error and modify response', function (done) { it('uses onTileErrorStrategy to handle error and modify response', function (done) {
serverOptions.renderer.onTileErrorStrategy = function (err, tile, headers, stats, format, callback) { serverOptions.renderer.onTileErrorStrategy = function (err, tile, headers, stats, format, callback) {
var fixture = __dirname + '/../../fixtures/limits/fallback.png'; var fixture = path.join(__dirname, '/../../fixtures/limits/fallback.png');
fs.readFile(fixture, { encoding: 'binary' }, function (err, img) { fs.readFile(fixture, { encoding: 'binary' }, function (err, img) {
callback(null, img, { 'Content-Type': 'image/png' }, {}); callback(null, img, { 'Content-Type': 'image/png' }, {});
}); });

View File

@ -5,6 +5,7 @@ var testHelper = require('../../support/test-helper');
var assert = require('../../support/assert'); var assert = require('../../support/assert');
var _ = require('underscore'); var _ = require('underscore');
var fs = require('fs'); var fs = require('fs');
var path = require('path');
var cartodbServer = require('../../../lib/server'); var cartodbServer = require('../../../lib/server');
var ServerOptions = require('./support/ported-server-options'); var ServerOptions = require('./support/ported-server-options');
@ -33,7 +34,7 @@ describe('server_png8_format', function () {
var layergroupId; var layergroupId;
before(function (done) { before(function (done) {
var testPngFilesDir = __dirname + '/../../results/png'; var testPngFilesDir = path.join(__dirname, '/../../results/png');
fs.readdirSync(testPngFilesDir) fs.readdirSync(testPngFilesDir)
.filter(function (fileName) { .filter(function (fileName) {
return /.*\.png$/.test(fileName); return /.*\.png$/.test(fileName);

View File

@ -6,6 +6,7 @@ var assert = require('../../support/assert');
var testClient = require('./support/test-client'); var testClient = require('./support/test-client');
var http = require('http'); var http = require('http');
var fs = require('fs'); var fs = require('fs');
var path = require('path');
describe('static_maps', function () { describe('static_maps', function () {
var validUrlTemplate = 'http://127.0.0.1:8033/{s}/{z}/{x}/{y}.png'; var validUrlTemplate = 'http://127.0.0.1:8033/{s}/{z}/{x}/{y}.png';
@ -16,7 +17,7 @@ describe('static_maps', function () {
before(function (done) { before(function (done) {
// Start a server to test external resources // Start a server to test external resources
httpRendererResourcesServer = http.createServer(function (request, response) { httpRendererResourcesServer = http.createServer(function (request, response) {
var filename = __dirname + '/../../fixtures/http/basemap.png'; var filename = path.join(__dirname, '/../../fixtures/http/basemap.png');
fs.readFile(filename, { encoding: 'binary' }, function (err, file) { fs.readFile(filename, { encoding: 'binary' }, function (err, file) {
response.writeHead(200); response.writeHead(200);
response.write(file, 'binary'); response.write(file, 'binary');

View File

@ -7,6 +7,7 @@ var OverviewsQueryRewriter = require('../../../../lib/utils/overviews-query-rewr
var overviewsQueryRewriter = new OverviewsQueryRewriter({ var overviewsQueryRewriter = new OverviewsQueryRewriter({
zoom_level: 'CDB_ZoomFromScale(!scale_denominator!)' zoom_level: 'CDB_ZoomFromScale(!scale_denominator!)'
}); });
var path = require('path');
module.exports = _.extend({}, serverOptions, { module.exports = _.extend({}, serverOptions, {
grainstore: { grainstore: {
@ -39,7 +40,7 @@ module.exports = _.extend({}, serverOptions, {
whitelist: ['http://127.0.0.1:8033/{s}/{z}/{x}/{y}.png'], whitelist: ['http://127.0.0.1:8033/{s}/{z}/{x}/{y}.png'],
fallbackImage: { fallbackImage: {
type: 'fs', type: 'fs',
src: __dirname + '/../../test/fixtures/http/basemap.png' src: path.join(__dirname, '/../../test/fixtures/http/basemap.png')
} }
} }
}, },

View File

@ -15,6 +15,7 @@ var redis_stats_db = 5;
process.env.PGPORT = '666'; process.env.PGPORT = '666';
process.env.PGHOST = 'fake'; process.env.PGHOST = 'fake';
var path = require('path');
var fs = require('fs'); var fs = require('fs');
var http = require('http'); var http = require('http');
@ -39,7 +40,7 @@ describe('template_api', function () {
before(function (done) { before(function (done) {
// Start a server to test external resources // Start a server to test external resources
httpRendererResourcesServer = http.createServer(function (request, response) { httpRendererResourcesServer = http.createServer(function (request, response) {
var filename = __dirname + '/../fixtures/http/light_nolabels-1-0-0.png'; var filename = path.join(__dirname, '/../fixtures/http/light_nolabels-1-0-0.png');
fs.readFile(filename, { encoding: 'binary' }, function (err, file) { fs.readFile(filename, { encoding: 'binary' }, function (err, file) {
response.writeHead(200); response.writeHead(200);
response.write(file, 'binary'); response.write(file, 'binary');