From ebae4354cec182d21475bd6bf4d5031f55cbe93a Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Sat, 23 Oct 2021 11:58:18 +1100 Subject: [PATCH] fix(server): Correctly resolve database name for URI connection strings URI-connection strings would incorrectly parse the database name when using additional options as part of the string (i.e. "ESXLegacy?charset=utf8mb4"). Correctly check for these options and match the string accordingly. Also just better pattern matching in general. --- server/main.lua | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/server/main.lua b/server/main.lua index 70fdff55..b6eec4d5 100644 --- a/server/main.lua +++ b/server/main.lua @@ -2,9 +2,12 @@ local function DATABASE() local connectionString = GetConvar('mysql_connection_string', ''); if connectionString == '' then error(connectionString..'\n^1Unable to start Multicharacter - unable to determine database from mysql_connection_string^0', 0) - elseif string.match(connectionString, 'mysql://') then - connectionString = string.sub(connectionString, string.find(connectionString, "/[^/]*$")+1) - return connectionString + elseif connectionString:find('mysql://') then + if connectionString:find('?*$') then + return connectionString:match('[^/][%w]*[?$]'):sub(0, -2) + else + return connectionString:match('[^/][%w]*$') + end else connectionString = {string.strsplit(';', connectionString)} for i=1, #connectionString do