From: Cloink on
Simply: How ?

I can't believe no-one's already done it, but I can't find any exact
mention of it on the tinterweb.

Closest I got was someone suggesting a custom javascript function to
encode a URI in the style that Perl expects - no way José - what's the
point in the W3C standardising this stuff for all our benefits if we go
and write custom functions instead.

So come on - I need a Perl function to decode a URL that has been
encoded with a javascript encodeURI() or encodeURIComponent() call.

Alternatively, I can write the Perl function myself if someone can
explain how the encoding works in the js funcs?

e.g.
é (e-acute) is encoded via encodeURIComponent to %C3%A9, which doesn't
obviously tie in with the Unicode specification 00E9. But the js
references I've read claim that it is Unicode compliant, so what am I
missing?

Cheers all.
Cloink

From: Reinhard Pagitsch on
Cloink wrote:
> Simply: How ?
>
> I can't believe no-one's already done it, but I can't find any exact
> mention of it on the tinterweb.
>
> Closest I got was someone suggesting a custom javascript function to
> encode a URI in the style that Perl expects - no way Jos� - what's the
> point in the W3C standardising this stuff for all our benefits if we go
> and write custom functions instead.
>
> So come on - I need a Perl function to decode a URL that has been
> encoded with a javascript encodeURI() or encodeURIComponent() call.
>
> Alternatively, I can write the Perl function myself if someone can
> explain how the encoding works in the js funcs?
>
> e.g.
> � (e-acute) is encoded via encodeURIComponent to %C3%A9, which doesn't
> obviously tie in with the Unicode specification 00E9. But the js
> references I've read claim that it is Unicode compliant, so what am I
> missing?
>
> Cheers all.
> Cloink
>

Maybe the following modules will help you:
CGI::Deurl and CGI::Enurl

regards
Reinhard

--
PM Mails an rpirpag <at> gmx dot at
From: Michele Dondi on
On 18 Jan 2007 05:33:44 -0800, "Cloink" <Cloink_Friggson(a)ntlworld.com>
wrote:

>I can't believe no-one's already done it, but I can't find any exact
>mention of it on the tinterweb.

What is the tinterweb?!?

>So come on - I need a Perl function to decode a URL that has been
>encoded with a javascript encodeURI() or encodeURIComponent() call.

URI::Escape would seem to be a good starting point...


Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
From: Brian McCauley on


On Jan 18, 4:13 pm, Michele Dondi <bik.m...(a)tiscalinet.it> wrote:
> On 18 Jan 2007 05:33:44 -0800, "Cloink" <Cloink_Frigg...(a)ntlworld.com>
> wrote:
>
> >So come on - I need a Perl function to decode a URL that has been
> >encoded with a javascript encodeURI() or encodeURIComponent() call.

> URI::Escape would seem to be a good starting point...

The docs thereof point out that "The JavaScript encodeURI() function is
similar to uri_escape_utf8()".

Oddly, however there's no uri_unescape_utf8 provided by URI::Escape.
However combining URI::Escape::uri_unescape() and Encode::decode_utf8()
in one statement is not overly taxing.

use Encode;
use URI::Escape qw(uri_unescape);
my $decoded = decode_utf8 uri_unescape $encoded;

From: Brian McCauley on


On Jan 18, 1:33 pm, "Cloink" <Cloink_Frigg...(a)ntlworld.com> wrote:
> Simply: How ?

This is (almost) FAQ: "How do I decode or create those %-encodings on
the web?"

> I can't believe no-one's already done it, but I can't find any exact
> mention of it on the tinterweb.

But there is (almost) an exact mention in the FAQ.

> Closest I got was someone suggesting a custom javascript function to
> encode a URI in the style that Perl expects - no way José - what's the
> point in the W3C standardising this stuff for all our benefits if we go
> and write custom functions instead.

If you are going to mention a standard it's couresy to provide a link.

> So come on - I need a Perl function to decode a URL that has been
> encoded with a javascript encodeURI() or encodeURIComponent() call.
>
> Alternatively, I can write the Perl function myself if someone can
> explain how the encoding works in the js funcs?

Hang on, didn't you just say there was a W3C standard?

> e.g.
> é (e-acute) is encoded via encodeURIComponent to %C3%A9, which doesn't
> obviously tie in with the Unicode specification 00E9. But the js
> references I've read claim that it is Unicode compliant, so what am I
> missing?

Unicode gives each character a "code point". That is a pure number. The
way that number is encoded as a byte sequence is another thing. Unicode
defines a number of such encodings. The way U+E9 is represented in the
most common Unicode encoding (utf8) is the byte seqence 0xC3,0xA9. So
it looks like encodeURIComponent is encoding the utf8 byte seqence.