Escaping a string when passing through multiple tools

submitted by

https://lemmy.ml/pictrs/image/9b086360-af2e-4680-b688-3abad3ec52a6.png

Escaping a string when passing through multiple tools
11
212

Log in to comment

11 Comments

Aaaaaaaaaaaaaaaaaaa No!!!!! My data! Please stop doing that!

I think I have seen a few CLI tools that put the input between an open and close arg like this “-arg1 random passthrough string -arg1-”

Now say the CLI tool is passed a string that has “-arg1-” inside it.

[[[[[["TCL/TK has \\\\\\\\\\"entered\\\\\\\\\\" the chat."]]]]]]

Oh you mean a pipiline defined in yaml, running in poweshell to execute a command in docker on windows?

I had to do this yesterday. First I tried ". Then \", finally \” worked. Which doesn’t make sense. But I’m not looking for answers, I’ve got more Jira tickets this sprint.

LOL even here it gets me . I tried slash quote, slash slash slash quote, finally slash slash quote worked.

You mean \", \\", and \\\" ?

Run a PowerShell script from batch, but call it using start-process as administrator, using a variable for the path and also pass parameters to the script.

I added an expression support to my Automod for Lemmy which can have subexpressions as parameters etc., pretty cool to work with.

Except every subexpression needs 2^n-1 slashes where n is the depth level. Fun times writing the expressions.

Comments from other communities

This meme brought to you by me trying to pass a regex from Nix into a TOML, which is certainly not the worst backslash orgy I’ve seen, but tragic in its own right. Both Nix and TOML have a way to specify raw strings, which do not need escaping. But Nix uses a normal string when passing into TOML, so I do have to escape anyways. 🫠

My regex also contains a double-quote, which was just guesswork as to how many backslashes I need there.

But Nix uses a normal string when passing into TOML, so I do have to escape anyways

What do you mean by that? You are always able to just use the '' strings instead of the " strings, they are just different syntax for the same underlying type. Or are you just using lib.generators.toINI without any arguments? Maybe try something like this:

toTomlEscapeBackslashes = toINI {
  mkKeyValue = mkKeyValueDefault { mkValueString = x: lib.escape [ ''\'' ] (toString x); } "=";
}

This will escape the values, like this:

nix-repl> :print toTomlEscapeBackslashes { my.regex = ''foo\nbar''; }
[my]
regex=foo\\nbar

Learning C: Random asterisks go

But sometimes ampersands also!