@@ -149,7 +149,9 @@ protected function scan($sql2)
149149 $ stringStartCharacter = false ;
150150 $ isEscaped = false ;
151151 $ 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 ];
153155 if (!$ stringStartCharacter && in_array ($ character , [' ' , "\t" , "\n" ], true )) {
154156 if ($ currentToken !== '' ) {
155157 $ tokens [] = $ currentToken ;
@@ -165,6 +167,19 @@ protected function scan($sql2)
165167 $ currentToken = '' ;
166168 continue ;
167169 }
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+
168183 $ currentToken .= $ character ;
169184
170185 if (!$ isEscaped && in_array ($ character , ['" ' , "' " ], true )) {
@@ -217,4 +232,11 @@ private function getCharacterAtIndex($string, $index)
217232
218233 return '' ;
219234 }
235+
236+ private function parseBrackets (string $ query , int $ index ): int
237+ {
238+ $ endPosition = strpos ($ query , '] ' , $ index ) + 1 ;
239+
240+ return $ endPosition - $ index ;
241+ }
220242}
0 commit comments