@@ -211,12 +211,23 @@ def _split_by_backtick(s: str) -> list[tuple[bool, str]]:
211
211
else :
212
212
quote_index = min (single_quote_index , double_quote_index )
213
213
214
- # No quotes
215
- if quote_index == - 1 :
216
- next_backtick_index = s .find ("`" , backtick_index + 1 )
214
+ # No quotes, or
217
215
# Backtick opened before quote
218
- elif backtick_index < quote_index :
216
+ if ( quote_index == - 1 ) or ( backtick_index < quote_index ) :
219
217
next_backtick_index = s .find ("`" , backtick_index + 1 )
218
+
219
+ # Backtick is unmatched (Possibly a mistake)
220
+ if next_backtick_index == - 1 :
221
+ substrings .append ((False , substring + s [i :]))
222
+ break
223
+ # Backtick is matched
224
+ else :
225
+ if i != backtick_index :
226
+ substrings .append ((False , substring + s [i :backtick_index ]))
227
+ substrings .append ((True , s [backtick_index : next_backtick_index + 1 ]))
228
+ substring = ""
229
+ i = next_backtick_index + 1
230
+
220
231
# Quote opened before backtick
221
232
else :
222
233
next_quote_index = - 1
@@ -241,18 +252,6 @@ def _split_by_backtick(s: str) -> list[tuple[bool, str]]:
241
252
i = next_quote_index + 1
242
253
continue
243
254
244
- # Backtick is unmatched (Possibly a mistake)
245
- if next_backtick_index == - 1 :
246
- substrings .append ((False , substring + s [i :]))
247
- break
248
- # Backtick is matched
249
- else :
250
- if i != backtick_index :
251
- substrings .append ((False , substring + s [i :backtick_index ]))
252
- substrings .append ((True , s [backtick_index : next_backtick_index + 1 ]))
253
- substring = ""
254
- i = next_backtick_index + 1
255
-
256
255
return substrings
257
256
258
257
0 commit comments