@@ -39,15 +39,13 @@ function get(req, res, next) {
3939 Datasets . findOne ( { where : { name : queries [ i ] . dataset } } )
4040 . then ( ( result ) => {
4141 if ( result ) {
42- const column = queries [ i ] . column
43- . replace ( / [ ` ~ ! @ # $ % ^ & * | + \- = ? ; : ' " , . < > \{ \} \[ \] \\ \/ ] / gi, "" )
44- . replace ( / [ ^ - ~ ] + / g, "" ) ;
42+ const column = queries [ i ] . column ;
4543 sequelize
4644 . query (
4745 "SELECT * FROM " +
48- result . dataValues . table +
46+ Utils . forceAlphaNumUnder ( result . dataValues . table ) +
4947 ' WHERE "' +
50- column +
48+ Utils . forceAlphaNumUnder ( column ) +
5149 '"=:search ORDER BY id ASC LIMIT 100' ,
5250 {
5351 replacements : {
@@ -175,7 +173,7 @@ router.post("/search", function (req, res, next) {
175173 sequelize
176174 . query (
177175 "SELECT properties, ST_AsGeoJSON(geom) FROM " +
178- table +
176+ Utils . forceAlphaNumUnder ( table ) +
179177 " WHERE properties ->> :key = :value;" ,
180178 {
181179 replacements : {
@@ -240,7 +238,9 @@ router.get("/download", function (req, res, next) {
240238 let table = result . dataValues . table ;
241239
242240 sequelize
243- . query ( "SELECT * FROM " + table )
241+ . query ( "SELECT * FROM " + Utils . forceAlphaNumUnder ( table ) , {
242+ replacements : { } ,
243+ } )
244244 . then ( ( [ results ] ) => {
245245 res . send ( {
246246 status : "success" ,
@@ -343,7 +343,7 @@ router.post("/upload", function (req, res, next) {
343343 if ( fields . upsert === "true" ) {
344344 let condition = "" ;
345345 fields . header . forEach ( ( elm ) => {
346- elm = elm . replace ( / [ ` ~ ! @ # $ % ^ & * | + \- = ? ; : ' " , . < > \{ \} \[ \] \\ \/ ] / gi , "" ) ;
346+ elm = Utils . forceAlphaNumUnder ( elm ) ;
347347 condition +=
348348 ' AND ( a."' +
349349 elm +
@@ -359,12 +359,15 @@ router.post("/upload", function (req, res, next) {
359359 sequelize
360360 . query (
361361 "DELETE FROM " +
362- tableName +
362+ Utils . forceAlphaNumUnder ( tableName ) +
363363 " a USING " +
364- tableName +
364+ Utils . forceAlphaNumUnder ( tableName ) +
365365 " b " +
366366 "WHERE b.id < a.id" +
367- condition
367+ condition ,
368+ {
369+ replacements : { } ,
370+ }
368371 )
369372 . then ( ( ) => {
370373 res . send ( {
@@ -461,7 +464,14 @@ router.post("/upload", function (req, res, next) {
461464 tableObj = result . tableObj ;
462465 } else {
463466 sequelize
464- . query ( "TRUNCATE TABLE " + result . table + " RESTART IDENTITY" )
467+ . query (
468+ "TRUNCATE TABLE " +
469+ Utils . forceAlphaNumUnder ( result . table ) +
470+ " RESTART IDENTITY" ,
471+ {
472+ replacements : { } ,
473+ }
474+ )
465475 . then ( ( ) => {
466476 tableObj = result . tableObj ;
467477 } )
@@ -514,7 +524,14 @@ router.post("/recreate", function (req, res, next) {
514524
515525 if ( req . body . mode == "full" ) {
516526 sequelize
517- . query ( "TRUNCATE TABLE " + result . table + " RESTART IDENTITY" )
527+ . query (
528+ "TRUNCATE TABLE " +
529+ Utils . forceAlphaNumUnder ( result . table ) +
530+ " RESTART IDENTITY" ,
531+ {
532+ replacements : { } ,
533+ }
534+ )
518535 . then ( ( ) => {
519536 populateDatasetTable (
520537 result . tableObj ,
0 commit comments