From 1fc23c948ee54b74123a46f17eb21f91cf923f88 Mon Sep 17 00:00:00 2001 From: mechanarchy <1166756+mechanarchy@users.noreply.github.com> Date: Fri, 23 Jun 2023 09:06:14 +1000 Subject: [PATCH] Fix SQL comment handling --- src/routes/api/sql.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/routes/api/sql.js b/src/routes/api/sql.js index f37b6d310..9dec60aff 100644 --- a/src/routes/api/sql.js +++ b/src/routes/api/sql.js @@ -33,13 +33,14 @@ function execute(req) { for (let query of queries) { query = query.trim(); - if (!query) { - continue; - } - while (query.startsWith('-- ') { // Query starts with one or more SQL comments, discard these before we execute. - query = query.substr(query.indexOf('\n') + 1) + const pivot = query.indexOf('\n'); + query = pivot > 0 ? query.substr(pivot + 1).trim() : ""; + } + + if (!query) { + continue; } if (query.toLowerCase().startsWith('select') || query.toLowerCase().startsWith('with')) {