From 94bd814186370bd0b1e7d47b25b7f0dc1ce3e109 Mon Sep 17 00:00:00 2001 From: dunak-debug <19434539+dunak-debug@users.noreply.github.com> Date: Sun, 12 Sep 2021 16:28:02 +0200 Subject: [PATCH] fix: patch mysql2, named-placeholders --- patches/mysql2+2.3.0.patch | 13 ++++++ patches/named-placeholders+1.1.2.patch | 61 ++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 patches/mysql2+2.3.0.patch create mode 100644 patches/named-placeholders+1.1.2.patch diff --git a/patches/mysql2+2.3.0.patch b/patches/mysql2+2.3.0.patch new file mode 100644 index 0000000..12ab4db --- /dev/null +++ b/patches/mysql2+2.3.0.patch @@ -0,0 +1,13 @@ +diff --git a/node_modules/mysql2/lib/connection.js b/node_modules/mysql2/lib/connection.js +index 47970e9..c9d6bbc 100644 +--- a/node_modules/mysql2/lib/connection.js ++++ b/node_modules/mysql2/lib/connection.js +@@ -519,7 +519,7 @@ class Connection extends EventEmitter { + _resolveNamedPlaceholders(options) { + let unnamed; + if (this.config.namedPlaceholders || options.namedPlaceholders) { +- if (Array.isArray(options.values)) { ++ if (/*Array.isArray(options.values)*/!options.sql.includes(':') && !options.sql.includes('@')) { + // if an array is provided as the values, assume the conversion is not necessary. + // this allows the usage of unnamed placeholders even if the namedPlaceholders flag is enabled. + return diff --git a/patches/named-placeholders+1.1.2.patch b/patches/named-placeholders+1.1.2.patch new file mode 100644 index 0000000..5928ba9 --- /dev/null +++ b/patches/named-placeholders+1.1.2.patch @@ -0,0 +1,61 @@ +diff --git a/node_modules/named-placeholders/index.js b/node_modules/named-placeholders/index.js +index 527d723..1a955b4 100644 +--- a/node_modules/named-placeholders/index.js ++++ b/node_modules/named-placeholders/index.js +@@ -3,7 +3,7 @@ + // based on code from Brian White @mscdex mariasql library - https://github.com/mscdex/node-mariasql/blob/master/lib/Client.js#L272-L332 + // License: https://github.com/mscdex/node-mariasql/blob/master/LICENSE + +-const RE_PARAM = /(?:\?)|(?::(\d+|(?:[a-zA-Z][a-zA-Z0-9_]*)))/g, ++const RE_PARAM = /(?:\?)|(?:[:,@](\d+|(?:[a-zA-Z][a-zA-Z0-9_]*)))/g, + DQUOTE = 34, + SQUOTE = 39, + BSLASH = 92; +@@ -94,15 +94,27 @@ function createCompiler(config) { + if (typeof params == 'undefined') + throw new Error('Named query contains placeholders, but parameters object is undefined'); + ++ let parsedParams = {} ++ ++ for(const key in params) { ++ parsedParams[key.charAt(0) == '@' ? key.substring(1) : key] = params[key] ++ } ++ + const tokens = tree[1]; + for (let i=0; i < tokens.length; ++i) { +- arr.push(params[tokens[i]]); ++ if(typeof tokens[i] === 'number') { ++ const param = parsedParams[(tokens[i] + 1).toString()]; ++ arr.push(param !== undefined ? param : null); ++ } else { ++ arr.push(parsedParams[tokens[i]] !== undefined ? parsedParams[tokens[i]] : null); ++ } + } ++ + return [tree[0], arr]; + } + + function noTailingSemicolon(s) { +- if (s.slice(-1) == ':') { ++ if (s.slice(-1) == ':' || s.slice(-1) == '@') { + return s.slice(0, -1); + } + return s; +@@ -115,7 +127,7 @@ function createCompiler(config) { + + let unnamed = noTailingSemicolon(tree[0][0]); + for (let i=1; i < tree[0].length; ++i) { +- if (tree[0][i-1].slice(-1) == ':') { ++ if (tree[0][i-1].slice(-1) == ':' || tree[0][i-1].slice(-1) == '@') { + unnamed += config.placeholder; + } + unnamed += config.placeholder; +@@ -124,7 +136,7 @@ function createCompiler(config) { + + const last = tree[0][tree[0].length -1]; + if (tree[0].length == tree[1].length) { +- if (last.slice(-1) == ':') { ++ if (last.slice(-1) == ':' || last.slice(-1) == '@') { + unnamed += config.placeholder; + } + unnamed += config.placeholder;