@@ -177,12 +177,14 @@ public function query(string $db_string, array $db_values = [], ?object $connect
177177
178178 // Comments that are allowed in a query are preg_removed.
179179 $ allowed_comments_from = [
180+ '~ \'\X*? \'~s ' ,
180181 '~\s+~s ' ,
181182 '~/\*!40001 SQL_NO_CACHE \*/~ ' ,
182183 '~/\*!40000 USE INDEX \([A-Za-z\_]+?\) \*/~ ' ,
183184 '~/\*!40100 ON DUPLICATE KEY UPDATE id_msg = \d+ \*/~ ' ,
184185 ];
185186 $ allowed_comments_to = [
187+ ' %s ' ,
186188 ' ' ,
187189 '' ,
188190 '' ,
@@ -216,19 +218,9 @@ public function query(string $db_string, array $db_values = [], ?object $connect
216218
217219 // First, we clean strings out of the query, reduce whitespace, lowercase, and trim - so we can check it over.
218220 if (!$ this ->disableQueryCheck ) {
219- $ clean = preg_split ('/(?<![ \'\\\\]) \'(?![ \'])/ ' , $ db_string );
220-
221- for ($ i = 0 ; $ i < \count ($ clean ); $ i ++) {
222- if ($ i % 2 === 1 ) {
223- $ clean [$ i ] = ' %s ' ;
224- }
225- }
226-
227- $ clean = trim (strtolower (preg_replace (
228- $ allowed_comments_from ,
229- $ allowed_comments_to ,
230- implode ('' , $ clean ),
231- )));
221+ // Clear out escaped single quotes first, to make it simpler to ID & remove string literals
222+ $ clean = str_replace ('\'\'' , ' ' , $ db_string );
223+ $ clean = trim (strtolower (preg_replace ($ allowed_comments_from , $ allowed_comments_to , $ clean )));
232224
233225 if (
234226 // Empty string?
@@ -1813,10 +1805,11 @@ public function create_table(string $table_name, array $columns, array $indexes
18131805 $ default = 'default nextval( \'' . $ short_table_name . '_seq \') ' ;
18141806 } elseif (isset ($ column ['default ' ]) && $ column ['default ' ] !== null ) {
18151807 // Numbers don't need quotes.
1816- if (is_numeric ($ column ['default ' ]))
1808+ if (is_numeric ($ column ['default ' ])) {
18171809 $ default = 'default ' . $ column ['default ' ];
1818- else
1810+ } else {
18191811 $ default = 'default \'' . $ this ->escape_string ($ column ['default ' ]) . '\'' ;
1812+ }
18201813 } else {
18211814 $ default = '' ;
18221815 }
0 commit comments