Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Unescaping JavaScript string

by 1nickt (Canon)
on Mar 18, 2016 at 04:25 UTC ( [id://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\x2fexample.com"); ' https://example.com
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
    "https\x3a\x2f\x2fexample.com"
    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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2024-04-18 13:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found