Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Unescaping JavaScript string

by 1nickt (Abbot)
on Mar 18, 2016 at 04:25 UTC ( #1158187=note: print w/replies, xml ) Need Help??

in reply to Unescaping JavaScript string

Hi a01, welcome to the monastery.

Your string was encoded to UTF-8, so you need to decode it using the core module Encode.

$ perl -MEncode -E' say Encode::decode_utf8("https\x3a\x2f\"); '
You may want to refer to perlunitut for an introduction to Unicode processing in Perl.

Hope this helps!

The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: Unescaping JavaScript string
by bart (Canon) on Mar 18, 2016 at 11:35 UTC
    That code is useless to the OP. You replaced single quotes (the original Javascript) with double quotes, thereby doing the decoding in the Perl source code. It won't work if the data comes from anywhere else than from the source of the Perl script itself.
Re^2: Unescaping JavaScript string
by Your Mother (Archbishop) on Mar 18, 2016 at 13:39 UTC

    It's also important, I feel, to note that this is not necessarily UTF-8.

    Latin-1 (ISO 8859-1) \x3a = 58 = : = chr(58) = "\x{3a}" \x2f = 47 = / = chr(47) = "\x{2f}" ASCII: ditto UTF-8: same same Windows-1252: also, also

    Unless it's been specifically decoded to UTF-8 (or one of the others) from a known source encoding, or it appeared in a use utf8 script literally, it is a risky assumption.

Re^2: Unescaping JavaScript string
by Anonymous Monk on Mar 18, 2016 at 04:34 UTC
    javascript has more ways to encode strings that Encode::decode_utf8 doesn't handle

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1158187]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (1)
As of 2022-01-29 14:23 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (74 votes). Check out past polls.