Typing in a backslash "\\" returns a double backslash "\\\\" when placed in a function or json.
Answered
Khao (Ping on reply) posted this in #help-forum
Why this is a problem is because i need ANSI Colors to work and they can't work of the input isn't one backslash
Reproduce: [CodeSandbox](https://codesandbox.io/p/sandbox/tender-rgb-779fwy)
\;Reproduce: [CodeSandbox](https://codesandbox.io/p/sandbox/tender-rgb-779fwy)
Answered by joulev
if you use the unicode escape version of
\, you can see it is still one single backslash after allconsole.log({ content: command });
console.log(command === "\u005C");{ content: "\\" }
true9 Replies
I needed to do that for the title to work
Typing in a backslash "\" returns a double backslash "\\" when placed in a function or json.@Khao (Ping on reply) Why this is a problem is because i need ANSI Colors to work and they can't work of the input isn't one backslash `\`;
Reproduce: [CodeSandbox](<https://codesandbox.io/p/sandbox/tender-rgb-779fwy>)
that is just the backslash being escaped when console.log'd. same for " for example, it becomes \" when console.log'd
nothing wrong here, it's still one single backslash
if you use the unicode escape version of
\, you can see it is still one single backslash after allconsole.log({ content: command });
console.log(command === "\u005C");{ content: "\\" }
trueAnswer
@joulev that is just the backslash being escaped when console.log'd. same for " for example, it becomes \\" when console.log'd
I tried sending it thru a function in anser which was ansi to json and it still said the content was \ and wouldn't decode.
@Khao (Ping on reply) I tried sending it thru a function in anser which was ansi to json and it still said the content was \\ and wouldn't decode.
well yes, because as expected when you type one backslash you get one backslash
essentially, react is working fine here and the command contains exactly what you would expect it to have. how you use that command and whether the library taking that command does perform escaping/sanitisation is not related to react