@@ -149,7 +149,9 @@ protected function scan($sql2)
149
149
$ stringStartCharacter = false ;
150
150
$ isEscaped = false ;
151
151
$ escapedQuotesCount = 0 ;
152
- foreach (\str_split ($ sql2 ) as $ index => $ character ) {
152
+ $ splitString = \str_split ($ sql2 );
153
+ for ($ index = 0 ; $ index < count ($ splitString ); $ index ++) {
154
+ $ character = $ splitString [$ index ];
153
155
if (!$ stringStartCharacter && in_array ($ character , [' ' , "\t" , "\n" ], true )) {
154
156
if ($ currentToken !== '' ) {
155
157
$ tokens [] = $ currentToken ;
@@ -165,6 +167,19 @@ protected function scan($sql2)
165
167
$ currentToken = '' ;
166
168
continue ;
167
169
}
170
+
171
+ // Handling the squared brackets in queries
172
+ if (!$ isEscaped && $ character === '[ ' ) {
173
+ if ($ currentToken !== '' ) {
174
+ $ tokens [] = $ currentToken ;
175
+ }
176
+ $ stringSize = $ this ->parseBrackets ($ sql2 , $ index );
177
+ $ tokens [] = substr ($ sql2 , $ index , $ stringSize );
178
+ // We need to subtract one here because the for loop will automatically increment the index
179
+ $ index += $ stringSize - 1 ;
180
+ continue ;
181
+ }
182
+
168
183
$ currentToken .= $ character ;
169
184
170
185
if (!$ isEscaped && in_array ($ character , ['" ' , "' " ], true )) {
@@ -217,4 +232,11 @@ private function getCharacterAtIndex($string, $index)
217
232
218
233
return '' ;
219
234
}
235
+
236
+ private function parseBrackets (string $ query , int $ index ): int
237
+ {
238
+ $ endPosition = strpos ($ query , '] ' , $ index ) + 1 ;
239
+
240
+ return $ endPosition - $ index ;
241
+ }
220
242
}
0 commit comments