@@ -125,7 +125,6 @@ set_ftstring_expr(struct tok_state* tok, struct token *token, char c) {
125125    int  hash_detected  =  0 ;
126126    int  in_string  =  0 ;
127127    char  quote_char  =  0 ;
128-     char  string_quote  =  0 ;
129128
130129    for  (Py_ssize_t  i  =  0 ; i  <  tok_mode -> last_expr_size  -  tok_mode -> last_expr_end ; i ++ ) {
131130        char  ch  =  tok_mode -> last_expr_buffer [i ];
@@ -138,6 +137,13 @@ set_ftstring_expr(struct tok_state* tok, struct token *token, char c) {
138137
139138        // Handle quotes 
140139        if  (ch  ==  '"'  ||  ch  ==  '\'' ) {
140+             // The following if/else block works becase there is an off number 
141+             // of quotes in STRING tokens and the lexer only ever reaches this 
142+             // function with valid STRING tokens. 
143+             // For example: """hello""" 
144+             // First quote: in_string = 1 
145+             // Second quote: in_string = 0 
146+             // Third quote: in_string = 1 
141147            if  (!in_string ) {
142148                in_string  =  1 ;
143149                quote_char  =  ch ;
@@ -165,18 +171,19 @@ set_ftstring_expr(struct tok_state* tok, struct token *token, char c) {
165171        Py_ssize_t  i  =  0 ;  // Input position 
166172        Py_ssize_t  j  =  0 ;  // Output position 
167173        in_string  =  0 ;     // Whether we're in a string 
168-         string_quote  =  0 ;  // Current string quote char 
174+         quote_char  =  0 ;     // Current string quote char 
169175
170176        // Process each character 
171177        while  (i  <  tok_mode -> last_expr_size  -  tok_mode -> last_expr_end ) {
172178            char  ch  =  tok_mode -> last_expr_buffer [i ];
173179
174180            // Handle string quotes 
175181            if  (ch  ==  '"'  ||  ch  ==  '\'' ) {
182+                 // See comment above to understand this part 
176183                if  (!in_string ) {
177184                    in_string  =  1 ;
178-                     string_quote  =  ch ;
179-                 } else  if  (ch  ==  string_quote ) {
185+                     quote_char  =  ch ;
186+                 } else  if  (ch  ==  quote_char ) {
180187                    in_string  =  0 ;
181188                }
182189                result [j ++ ] =  ch ;
0 commit comments