Repository navigation
Conversation
Hyprland's Lua config makes every dispatcher and config value a Lua snippet, so any string interpolated into one — a workspace name, a monitor description, a command to run — goes through a Lua string literal. The crate has no way to escape one, so its consumers write theirs: hyprland-autoname-workspaces#138 carries an `escape_lua_string()` of its own and hands the Lua it built by hand to `DispatchType::Custom`. Without such escaping, a stray `"` in a name breaks the snippet, and a crafted one runs arbitrary Lua inside the compositor. Add `hyprland::lua` with `escape_string()` and `quote_string()`. Both escape `\`, `"` and the control characters — those without a mnemonic escape as zero padded `\ddd`, since an unpadded `\1` swallows a following digit of the string itself and turns `"a\11b"` into three bytes where the caller passed four. Everything else — non ASCII text included — is left untouched, `'` among it: the output belongs in a `"..."` literal, which is what `quote_string()` builds. The unit tests reuse the cases of autoname-workspaces#138. Those cases, and 403 strings generated from this code in total, were round-tripped through a running Hyprland 0.56.2 by asking Lua for the bytes of the string it parsed (`string.byte`): every one came back identical to the input. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This was referenced Sep 28, 2026
Author
|
@yavko a gentle ping on this one. Hyprland 0.57.0 was released on October 28 with Two things that may help:
Thanks for keeping the door open. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hyprland's Lua config makes every dispatcher and config value a Lua snippet, and a consumer that
wants to work on 0.55 and later has to build those snippets itself today, since the crate still
emits the old syntax (that's #391). Every string interpolated into one — a workspace name, a
monitor description, a command to run — goes through a Lua string literal, and the crate has no way
to escape one. So consumers write their own:
adds an
escape_lua_string()of its own and passes hand-built Lua toDispatchType::Custom,because
DispatchType::RenameWorkspaceno longer has any effect.luabranch (H3rmt/hyprland-rs#1,by @mitsaucepls) adds
window.moveand writes its quotes by hand as well, so the same escaping isnow hand-rolled in two independent places.
This adds
hyprland::lua, so the escaping exists once, in the library:Both escape
\,"and the ASCII control characters; everything else, non-ASCII text included, isleft untouched.
Why the control characters are zero padded
\n,\rand\tkeep their mnemonic escape. The rest become\ddd, which is a byte, and Luareads up to three digits — so without the padding the escape swallows a digit of the string itself.
Measured on 0.56.2:
The caller passed four bytes in both cases.
How it was checked
I generated the strings from this code rather than typing Lua by hand, then round-tripped each one
through a running Hyprland 0.56.2, asking Lua for the bytes it actually parsed so that no binary
data has to survive the IPC round trip:
403 strings, every one byte-identical to the input: each of the 128 ASCII codepoints alone,
surrounded (
a<c>b) and followed by a digit (a<c>1b); the seven cases of #138; U+0085, U+2028,U+2029, ZWJ and U+FEFF; trailing backslashes; an apostrophe; and injection payloads. The negative
control is the reason for all of this — interpolated naively, a name of
a" error("PROOF") --runsinside the compositor; through
quote_stringthe same name is inert data.The unit tests reuse the cases of
#138 verbatim, so it
is easy to check this covers what the copy in that PR does — plus the remaining control characters,
which it leaves alone.
Scope
Additive: one module, two functions, no new dependency, no existing behaviour changed (three added
lines in
lib.rsdeclare the module), and no feature gate — the escaping is needed with or withoutdispatch../test.shpasses, andcargo clippy --all-targetsandcargo doc --no-deps --all-featuresreport exactly what they report onmaster.This deliberately does not touch
dispatchitself. That is the larger question of #391, and thishelper is useful whichever way it is answered. If this one looks right to you, I'm happy to follow
up with the dispatchers themselves emitting Lua.
One note: the README's "This crate provides 6 modules" list is already out of date on
master(itomits
error,instance,hyprpaperand others), so I left it alone rather than half-fix it.Happy to update the whole list in a separate commit if you'd like.
🤖 Generated with Claude Code