From cdb4e5f19bdd7d9dae1c70387ea685a8e4d5857c Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Fri, 11 Apr 2014 12:03:43 +0200 Subject: [PATCH] precompiled query may write regex --- app/controllers/app.js | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/app/controllers/app.js b/app/controllers/app.js index 6fe84a93..627c76df 100755 --- a/app/controllers/app.js +++ b/app/controllers/app.js @@ -71,7 +71,7 @@ Date.prototype.toJSON = function() { s += ( offset < 0 ? '+' : '-' ) + pad(Math.abs(offset / 60)) + pad(Math.abs(offset % 60)) - + } return s; } @@ -165,19 +165,16 @@ app.get(global.settings.base_url+'/version', function(req, res) { res.send(getVersion()); }); -// Return true of the given query may write to the database -// -// NOTE: this is a fuzzy check, the return could be true even -// if the query doesn't really write anything. -// But you can be pretty sure of a false return. -// +var sqlQueryMayWriteRegex = new RegExp("\\b(alter|insert|update|delete|create|drop|reindex|truncate)\\b", "i"); +/** + * This is a fuzzy check, the return could be true even if the query doesn't really write anything. But you can be + * pretty sure of a false return. + * + * @param sql + * @returns {boolean} Return true of the given query may write to the database + */ function queryMayWrite(sql) { - var mayWrite = false; - var pattern = RegExp("\\b(alter|insert|update|delete|create|drop|reindex|truncate)\\b", "i"); - if ( pattern.test(sql) ) { - mayWrite = true; - } - return mayWrite; + return sqlQueryMayWriteRegex.test(sql); } function sanitize_filename(filename) {