• 
      

    Fix escaping when converting Lua patterns in queries.

    Review Request #15405 — Created Oct. 19, 2026 and submitted

    Information

    Review Board
    release-9.x

    Reviewers

    When we rewrite lua-match? predicates and gsub! directives into
    Python regexes, we pulled the pattern out of the query string by
    stripping the quotes. This never un-escaped the string first. A pattern
    containing an escaped quote, like "^@\"<html", came out as
    "^@\\\\"<html", which ends the string early and breaks the query.

    update-queries.py validates queries before writing them, so these
    failures were silent. Affected files were either dropped or fell back to
    an older commit. This is why we were missing injections for
    git_config, nix, and teal, and why systemtap and t32 were
    stuck on old highlights.

    Query strings are now un-escaped before conversion and re-escaped
    afterward.

    This exposed a second problem. lua_pattern_to_python() treated a
    backslash followed by a regex special character as an escape that had
    already been done, and passed it through. That only worked because it
    was being given the still-escaped query string. Backslashes have no
    special meaning in Lua patterns, so they're now always treated as
    literal characters. Without this, t32's pattern for 6 literal
    backslashes would have turned into a pattern for 3.

    • Ran unit tests.
    • Added a test for converting a pattern with an escaped quote.
    • Re-ran update-queries.py and verified that the missing files came
      back and that the regenerated queries all load.
    • Checked that the regenerated t32 pattern matches the same text as
      the original Lua pattern.
    Summary ID
    Fix escaping when converting Lua patterns in queries.
    When we rewrite `lua-match?` predicates and `gsub!` directives into Python regexes, we pulled the pattern out of the query string by stripping the quotes. This never un-escaped the string first. A pattern containing an escaped quote, like `"^@\"<html"`, came out as `"^@\\\\"<html"`, which ends the string early and breaks the query. `update-queries.py` validates queries before writing them, so these failures were silent. Affected files were either dropped or fell back to an older commit. This is why we were missing injections for `git_config`, `nix`, and `teal`, and why `systemtap` and `t32` were stuck on old highlights. Query strings are now un-escaped before conversion and re-escaped afterward. This exposed a second problem. `lua_pattern_to_python()` treated a backslash followed by a regex special character as an escape that had already been done, and passed it through. That only worked because it was being given the still-escaped query string. Backslashes have no special meaning in Lua patterns, so they're now always treated as literal characters. Without this, t32's pattern for 6 literal backslashes would have turned into a pattern for 3. Testing Done: - Ran unit tests. - Added a test for converting a pattern with an escaped quote. - Re-ran `update-queries.py` and verified that the missing files came back and that the regenerated queries all load. - Checked that the regenerated t32 pattern matches the same text as the original Lua pattern.
    wrqormtvyxplytvlvswkzlukwyrzxsnn
    Description From Last Updated

    We got rid of block 2 so now this and the rest of the blocks need to be renumbered.

    maubin maubin
    maubin
    1. 
        
    2. reviewboard/treesitter/lua_patterns.py (Diff revision 1)
       
       
      Show all issues

      We got rid of block 2 so now this and the rest of the blocks need to be renumbered.

    3. 
        
    david
    Review request changed
    Status:
    Completed
    Change Summary:
    Pushed to release-9.x (05f0977)