colinta / SublimeStringEncode

Converts characters from one "encoding" to another using a transformation (think HTML entities, not character encodings)
Other
150 stars 22 forks source link

Unescaping JSON for arbitrary text blocks #39

Closed BBerastegui closed 5 years ago

BBerastegui commented 5 years ago

Hi !

I was trying to unescape a big string extracted from a JSON field, and I saw that, unless it's properly quoted, the "unescaping" won't work.

Is it possible that we leave that functionality working even if we have a chunk of random text such as:

test\n\ttest

test\n\n\n\ttest

Cheers !

colinta commented 5 years ago

Not easily - the mechanism I use to determine the beginning and end of the string is to use the grammar's definition of the string.

I think it could work using selection, though, lemme look at that...

colinta commented 5 years ago

Done! Available in 2.3.0.

BBerastegui commented 5 years ago

That was fast ! Thanks !

I just tried it and for a selection in this format, for example, it doesn't work:

'fingerprint-strings': '\n  FourOhFourRequest: \n    HTTP/1.1 404 Not Found\n    P3P: CP="CAO PSA OUR"\n    Vary: Accept-Encoding\n    Content-Type: text/html;charset=ISO-8859-1\n    Cache-Control: must-revalidate,no-cache,no-store\n    Content-Length: 0\n  GetRequest: \n    HTTP/1.1 200 OK\n    Vary: Accept-Encoding\n    P3P: CP="CAO PSA OUR"\n    Content-Type: text/html;charset=UTF-8\n    Set-Cookie: cookiesession=whateverwhatever;Path=/;Secure\n    Expires: Thu, 01 Jan 1970 00:00:00 GMT\n    Content-Length: 39\n  HTTPOptions: \n    HTTP/1.1 200 OK\n    Vary: Accept-Encoding\n    P3P: CP="CAO PSA OUR"\n    Allow: GET,HEAD,POST,OPTIONS\n    Content-Length: 0\n  RTSPRequest, SIPOptions: \n    HTTP/1.1 400 Bad Request\n    Content-Length: 0\n    Connection: close',
                        'http-cookie-flags': '\n  /: \n    cookiesession: \n      httponly flag not set',
                        'http-title': "Site doesn't have a title (text/html;charset=UTF-8).",

It's probably due to the single and double quotes mix, but if I'm not wrong, it's expected to work anyway, right?

colinta commented 5 years ago

Are you selecting the entire string? Because yeah that's just not a valid JSON string.

BBerastegui commented 5 years ago

Yeah, is just a random selection of text. I thought that with the selection change this will work.