ZnUrls with Non-ASCII characters

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

ZnUrls with Non-ASCII characters

Sean P. DeNigris
Administrator
'https://en.wiktionary.org/wiki/prêt#French' asUrl ==>
ZnCharacterEncodingError: ASCII character expected. Ideas?



-----
Cheers,
Sean
--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: ZnUrls with Non-ASCII characters

Peter Kenny
Sean

The trick is to url encode the bit that contains the accented characters. In your case, try:
('https://en.wiktionary.org/wiki/','prêt#French' urlEncoded ) asUrl

If you use urlEncoded on the whole string, the encoded slashes seem to confuse things.

HTH

Peter Kenny


-----Original Message-----
From: Pharo-users [mailto:[hidden email]] On Behalf Of Sean P. DeNigris
Sent: 07 December 2017 14:49
To: [hidden email]
Subject: [Pharo-users] ZnUrls with Non-ASCII characters

'https://en.wiktionary.org/wiki/prêt#French' asUrl ==>
ZnCharacterEncodingError: ASCII character expected. Ideas?



-----
Cheers,
Sean
--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html


Reply | Threaded
Open this post in threaded view
|

Re: ZnUrls with Non-ASCII characters

Sven Van Caekenberghe-2
In reply to this post by Sean P. DeNigris


> On 7 Dec 2017, at 15:49, Sean P. DeNigris <[hidden email]> wrote:
>
> 'https://en.wiktionary.org/wiki/prêt#French' asUrl ==>
> ZnCharacterEncodingError: ASCII character expected. Ideas?

Non-ASCII characters are not allowed in a URL (in its external string representation, the input of the parser), they must be encoded.

When you construct a URL from parts, the encoding will be done for you, as you specify unencoded elements.

'https://en.wiktionary.org/wiki' asUrl addPathSegment: 'prêt'; fragment: #French; yourself.

  => https://en.wiktionary.org/wiki/pr%C3%AAt#French

'https://en.wiktionary.org/wiki/pr%C3%AAt#French' asUrl.

And you would be correct to remark that web browsers do allow this, which is more a UI thing.

> -----
> Cheers,
> Sean
> --
> Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
>


Reply | Threaded
Open this post in threaded view
|

Re: ZnUrls with Non-ASCII characters

Sean P. DeNigris
Administrator
Reply | Threaded
Open this post in threaded view
|

Re: ZnUrls with Non-ASCII characters

Sven Van Caekenberghe-2


> On 7 Dec 2017, at 18:00, Sean P. DeNigris <[hidden email]> wrote:
>
> Why not:
> 'https://en.wiktionary.org/wiki/prêt#French' asUrl  =>
> https://en.wiktionary.org/wiki/pr%C3%AAt#French
> ?

#asUrl invokes the URL parser that takes the EXTERNAL string representation of a URL as input. It stays strict to the specification and as such does not allow non-encoded non-ascii characters.

If you construct a URL from INTERNAL parts, that's different.

It would probably be possible to write a more lenient parser as opposed to a strict one. I have not yet given that idea much thought.

> -----
> Cheers,
> Sean
> --
> Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
>


Reply | Threaded
Open this post in threaded view
|

Re: ZnUrls with Non-ASCII characters

Sean P. DeNigris
Administrator
Sven Van Caekenberghe-2 wrote
> It would probably be possible to write a more lenient parser as opposed to
> a strict one. I have not yet given that idea much thought.

K, thanks for the explanation and assistance.



-----
Cheers,
Sean
--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

Cheers,
Sean