fix(python): improve f-string injections (#8644)
Some checks failed
Lint / Lint Lua files (push) Has been cancelled
Lint / Lint query files (push) Has been cancelled
Lint / Lint docs (push) Has been cancelled
Tests / Build (push) Has been cancelled

Problem: Neovim removed match limits, which can lead to catastrophic performance with injection queries.

Solution: Tighten up f-string injections.
This commit is contained in:
Christian Clason 2026-07-20 00:29:57 +02:00 committed by GitHub
parent 2497714755
commit 7248feaca4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 6 deletions

View file

@ -3,7 +3,12 @@
object: (identifier) @_re)
arguments: (argument_list
(string
(string_content) @injection.content))
(string_start)
[
(string_content) @injection.content
(interpolation)
]+
(string_end)))
(#eq? @_re "re")
(#set! injection.language "regex"))
@ -12,11 +17,13 @@
object: (identifier) @_re)
arguments: (argument_list
(concatenated_string
[
(string
(string_content) @injection.content)
(comment)
]+))
(string
(string_start)
[
(string_content) @injection.content
(interpolation)
]+
(string_end))))
(#eq? @_re "re")
(#set! injection.language "regex"))

View file

@ -14,5 +14,15 @@ re_test = re.compile(
# comment
# ^ @comment
)
a.a(
f"<td class=\"a{a}\">{a}</td>"
f"<td class=\"a{a}\">{a}</td>"
f"<td class=\"a{a}\">{a}</td>"
f"<td class=\"a{a}\">{a}</td>"
f"<td class=\"a{a}\">{a}</td>"
f"<td class=\"a{a}\">{a}</td>"
f"<td class=\"a{a}\">{a}</td>"
f"<td class=\"a{a}\">{a}</td>"
)
print("foo %s bar %d" % ("arg1", 2))
# ^ @printf