Skip to content

modules/niri: escape strings (mostly) in accordance to kdl spec - #193

Merged
zimward merged 1 commit into
lassulus:mainfrom
zimward:push-ymvrzyntlzrx
Sep 15, 2026
Merged

zimward merged 1 commit into
lassulus:mainfrom
zimward:push-ymvrzyntlzrx

Conversation

@zimward

@zimward zimward commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

excluding ill defined escape sequences like backspace

Fixes #192

excluding ill defined escape sequences like backspace
@zimward
zimward merged commit bc0028e into lassulus:main Sep 15, 2026
2 checks passed
@Kruemmelspalter

Kruemmelspalter commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

first of all, thankies for the quick fix! the original error is now gone

{
  matches = [
    { app-id = "xdg-desktop-portal-gtk"; }
    {
      title = "Choose a color";
      app-id = "librewolf|firefox";
    }
[...]
}

errors with:
image
i'm pretty sure the space is not supposed to be escaped

@zimward

zimward commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator Author

eh the kdl spec isn't quite clear about if it needs to be escaped, though ig its probably best to just not escape it in considering the usecase

@Kruemmelspalter

Kruemmelspalter commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

i suppose it would make sense to escape ", /, \, b, f, n, r, t and u like niri/kdl/the error in the screenshot says
even if that isn't spec because the serializer is only for this format

@zimward

zimward commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator Author

feel free to implement a full unicode parser in nix for the unicode escapes as that will definetly take a more time than i have 🙃
otherwise i need to think of a good ad-hoc way to pass escape sequences through nix without double escaping them

@Kruemmelspalter

Copy link
Copy Markdown
Contributor

i would assume that the parser would just accept unicode characters and the \u escapes are just there for readabilty?

my suggestion would be (partially uses raw nix strings with two single quotes)

''"'' => ''\"''
''/'' => ''\/''
''\'' => ''\\''
# nix does not have backspace literals (ig they could be read from a file but like. then it's okay for there to be an error
# nix does not have form feed literals either
<LF> => "\n"
<CR> => ''\r'' # also will probably not occur buy why not
<TAB> => "\t"
# disregard unicode for now and just leave it like it is

an implementation would be

escape = builtins.replaceStrings
    [''"''  "/"    ''\''   "\n"  "\r"   "\t"  ]
    [''\"'' ''\/'' ''\\'' ''\n'' ''\r'' ''\t'']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

modules/niri: kdl strings are not properly escaped

2 participants