Replace backslashes or shift them

Hello everyone. I’ve been pushed against the wall with the problem of extra-backslashes.
I have a string, that should be unzipped. This is the correct one example:

body_correct = "\u001F\x8B\b\u0000\xD0{#\\\u0002\xFF\x8B\xAEVJ\xCDM\xCC\xCCQ\xB2RP\xCAr\xC8\xD2K\xCE\xCFU\xD2QPJ\xCE\xCF+IL.\u0001\x89\x82\xB8y\x89\xB9\xA9 \xB6\u0017\x90.\u0006\t\u0014gg\xE6\xE4\u0014\u0003\x85\xA2\x95\xB4\r\u0015\xCC\xCD-,--\r\f\f̕b\x81\x92\xA9)\xA5@\x99j\xA5\xD2t\xB0\x82\x80ʒ\x8C\xFC<\xB0L\u0001D\xC49X)\xB6\xB6VGa\xE0\xEC\x8E\u0005\u0000\xEB*\xA5\xA3\xF8\u0000\u0000\u0000"

But I recieve the same string with all backslashes escaped, so it becomes invalid gzip string
Like this:

body = "\\u001F\\x8B\\b\\u0000\\xD0{#\\\\\\u0002\\xFF\\x8B\\xAEVJ\\xCDM\\xCC\\xCCQ\\xB2RP\\xCAr\\xC8\\xD2K\\xCE\\xCFU\\xD2QPJ\\xCE\\xCF+IL.\\u0001\\x89\\x82\\xB8y\\x89\\xB9\\xA9 \\xB6\\u0017\\x90.\\u0006\\t\\u0014gg\\xE6\\xE4\\u0014\\u0003\\x85\\xA2\\x95\\xB4\\r\\u0015\\xCC\\xCD-,--\\r\\f\\f̕b\\x81\\x92\\xA9)\\xA5@\\x99j\\xA5\\xD2t\\xB0\\x82\\x80ʒ\\x8C\\xFC<\\xB0L\\u0001D\\xC49X)\\xB6\\xB6VGa\\xE0\\xEC\\x8E\\u0005\\u0000\\xEB*\\xA5\\xA3\\xF8\\u0000\\u0000\\u0000"

Tried almost everything with gsub function (like .gsub(/\\/, “\”)), but it is not working.
The thing is that backslash should “activate” the part after it (ex. u001F), but extra-backslash kills it

Am I doing something wrong or maybe there is any way to get rid of it?
Thanks in advance.

If someone interested - I wrapped this text into eval and it returned exactly what I wanted. Yeah, it’s not secure, but there are no solutions found so far

1 Like