Pharo-users
By thread
pharo-users@lists.pharo.org
By month
Messages by month
- ----- 2026 -----
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
March 2019
- 77 participants
- 476 messages
Re: [Pharo-users] how to convert this with a stream
by Richard O'Keefe
"I have a SortedCollection of Teams. Now I need to convert *it*
to a line like ...".
Well, no. You need to convert *each team* separately to such a
line. So something like
aStream nextPutAll: '...header line...'; cr.
mySortedTeams do: [:eachTeam |
-write a formatted line describing eachTeam to aStream].
Now it gets interesting. Whose responsibility is it to write
a representation of a Team instance to a stream? Should it be
done by the Team instance, or should it be done outside?
Question 1: is there obviously one and only one format, or do
you think that in a more realistic example there might be more
than one way to print a Team object? I concluded that there
might be many different ways to do it. (I personally dislike
putting variable length fields on the left.)
Question 2: *Can* it be done from the outside or *must* it be
done inside? Is there any information in the printed representation
that the caller cannot ask the team object for? In this case, all
of the information is available through Team's public interface.
Question 3: Should Teams and printing be *coupled*? Should a Team
know about details like the dividing line between columns? In this
case, I decided that putting the formatting code inside the Team
object was highly undesirable coupling.
Question 4: Is it *possible* for a Team object to do the formatting
without knowing about all the other Teams in the collection? In this
case, the specification is rather vague. It seemed to me that all
the numeric columns should be the same width and should be wide enough
to hold the largest number with a space on each side.
In answer to question 4, my Tournament code contains
w := mySortedTeams inject: 1 into: [:acc :team |
(team matchCount max: team points) printString size max: acc].
and this clearly requires knowledge of all the teams, so it makes no
sense to put it in Team. (Of course, if the column widths are fixed,
this argument fails, but such a choice makes no sense for large problems.)
So now you need something like
aStream nextPutAll: team name; space: 30 - team name size.
and then a numeric value might be written as
aStream nextPutAll: ' | '; space: w - team points printString size;
print: team points.
Please do not use << . Historically, << had no meaning in Smalltalk.
In some Smalltalks it means leftwards bit shift. It is just too
confusing. (In a shell, you would use > for output, not <<, which
is used for a kind of input.) It is really weird to use s << String cr
instead of s cr. So idomatic Smalltalk would be
s nextPutAll: t name; cr.
Why are you writing to (an output stream over) an Array?
Surely you want a String?
But in any case, I would split this into two methods:
printTeams: teams on: aStream
-- print heading --
-- print each team --
printTeamsAsString: teams
^String streamContents: [:s | self printTeams: teams on:s]
On Wed, 27 Mar 2019 at 07:12, Roelof Wobben <r.wobben(a)home.nl> wrote:
> Hello,
>
> I have a SortedCollection of teams.
>
> Now I need to convert this to a line like this :
>
> 'Allegoric Alaskans | 1 | 1 | 0 | 0 | 3'
>
> I tried it with this :
>
> outcome := Array
> streamContents: [ :s |
> TeamStatusSorted
> do: [ :each |
> s << each name.
> s << String cr ] ].
> ^ outcome
>
>
> or String streamContents but it will not give me the right answer,
> So please some hints how I can make this work.
>
> Roelof
>
>
>
March 27, 2019
More info & examples on MAAdaptiveModel ?
by Albrecht Baur
Hi all,
I am looking for more info or usage examples of MAAdaptiveModel.
So far I found the following good resources:
* The masters thesis of Lukas Renggli and the impl. of Pier:
http://sdmeta.gforge.inria.fr/Teaching/Lille/0910-MetaModelisation/Magritte…
* In the package Magritte-Tests-Model: The test MAAdaptiveModelTest
Could someone point me to more resources on MAAdaptiveModel if there are
any?
Especially the topic searching / building search indexes on
MAAdaptiveModel data stored e.g. in mongodb as voyage root would be
helpful. -> How is the performance when searching on MAAdaptiveModel
values with and without index ?
Hints would be nice!
Albrecht
March 27, 2019
Re: [Pharo-users] how to convert this with a stream
by Roelof Wobben
Carlo,
Thanks,
This gives the output I expect
outcome
      add: 'Team                          | MP | W | D | L | P'.
   outcome
      add:
         (String
            streamContents: [ :s |
               TeamStatusSorted
                  do: [ :each |
                     s << each name.
                     s << '           '.
                     s << ' | '.
                     s << each totalPlayed.
                     s << ' | '.
                     s << each winCount.
                     s << String cr ] ]).
   ^ outcome
but I think its ugly. Hopefully someone can give me hints how to improve
this .
Roelof
Op 26-3-2019 om 20:14 schreef Carlo:
> Hi Roelof
>
> The block [] should be (). What's happening is that the block is being added to outcome which will then print itself out.
>
> Cheers
> Carlo
>
> On 26 Mar 2019, at 20:45, Roelof Wobben <r.wobben(a)home.nl> wrote:
>
> Hello
>
> Could be , im confused now
>
> I tried this :
>
> outcome
> add: 'Team | MP | W | D | L | P'.
> outcome
> add: [ String
> streamContents: [ :s |
> TeamStatusSorted
> do: [ :each |
> s << each name.
> s << String cr ] ] ].
> ^ outcome
>
> but get now a output of the header and then the code.
>
> Roelof
>
>
>
> Op 26-3-2019 om 19:38 schreef Carlo:
>> Hi Roelof
>>
>> I think you meant
>> String streamContents:
>> and not
>> Array streamContents:
>>
>>
>>
>> On 26 Mar 2019, at 20:12, Roelof Wobben <r.wobben(a)home.nl> wrote:
>>
>> Hello,
>>
>> I have a SortedCollection of teams.
>>
>> Now I need to convert this to a line like this :
>>
>> 'Allegoric Alaskans | 1 | 1 | 0 | 0 | 3'
>>
>> I tried it with this :
>>
>> outcome := Array
>> streamContents: [ :s |
>> TeamStatusSorted
>> do: [ :each |
>> s << each name.
>> s << String cr ] ].
>> ^ outcome
>>
>>
>> or String streamContents but it will not give me the right answer,
>> So please some hints how I can make this work.
>>
>> Roelof
>>
>>
>>
>>
>>
>
>
>
>
March 26, 2019
Re: [Pharo-users] how to convert this with a stream
by Carlo
Hi Roelof
The block [] should be (). What's happening is that the block is being added to outcome which will then print itself out.
Cheers
Carlo
On 26 Mar 2019, at 20:45, Roelof Wobben <r.wobben(a)home.nl> wrote:
Hello
Could be , im confused now
I tried this :
outcome
add: 'Team | MP | W | D | L | P'.
outcome
add: [ String
streamContents: [ :s |
TeamStatusSorted
do: [ :each |
s << each name.
s << String cr ] ] ].
^ outcome
but get now a output of the header and then the code.
Roelof
Op 26-3-2019 om 19:38 schreef Carlo:
> Hi Roelof
>
> I think you meant
> String streamContents:
> and not
> Array streamContents:
>
>
>
> On 26 Mar 2019, at 20:12, Roelof Wobben <r.wobben(a)home.nl> wrote:
>
> Hello,
>
> I have a SortedCollection of teams.
>
> Now I need to convert this to a line like this :
>
> 'Allegoric Alaskans | 1 | 1 | 0 | 0 | 3'
>
> I tried it with this :
>
> outcome := Array
> streamContents: [ :s |
> TeamStatusSorted
> do: [ :each |
> s << each name.
> s << String cr ] ].
> ^ outcome
>
>
> or String streamContents but it will not give me the right answer,
> So please some hints how I can make this work.
>
> Roelof
>
>
>
>
>
March 26, 2019
Re: [Pharo-users] how to convert this with a stream
by Roelof Wobben
Hello
Could be , im confused now
I tried this :
outcome
      add: 'Team                          | MP | W | D | L | P'.
   outcome
      add: [ String
            streamContents: [ :s |
               TeamStatusSorted
                  do: [ :each |
                     s << each name.
                     s << String cr ] ] ].
   ^ outcome
but get now a output of the header and then the code.
Roelof
Op 26-3-2019 om 19:38 schreef Carlo:
> Hi Roelof
>
> I think you meant
> String streamContents:
> and not
> Array streamContents:
>
>
>
> On 26 Mar 2019, at 20:12, Roelof Wobben <r.wobben(a)home.nl> wrote:
>
> Hello,
>
> I have a SortedCollection of teams.
>
> Now I need to convert this to a line like this :
>
> 'Allegoric Alaskans | 1 | 1 | 0 | 0 | 3'
>
> I tried it with this :
>
> outcome := Array
> streamContents: [ :s |
> TeamStatusSorted
> do: [ :each |
> s << each name.
> s << String cr ] ].
> ^ outcome
>
>
> or String streamContents but it will not give me the right answer,
> So please some hints how I can make this work.
>
> Roelof
>
>
>
>
>
March 26, 2019
Re: [Pharo-users] how to convert this with a stream
by Carlo
Hi Roelof
I think you meant
String streamContents:
and not
Array streamContents:
On 26 Mar 2019, at 20:12, Roelof Wobben <r.wobben(a)home.nl> wrote:
Hello,
I have a SortedCollection of teams.
Now I need to convert this to a line like this :
'Allegoric Alaskans | 1 | 1 | 0 | 0 | 3'
I tried it with this :
outcome := Array
streamContents: [ :s |
TeamStatusSorted
do: [ :each |
s << each name.
s << String cr ] ].
^ outcome
or String streamContents but it will not give me the right answer,
So please some hints how I can make this work.
Roelof
March 26, 2019
how to convert this with a stream
by Roelof Wobben
Hello,
I have a SortedCollection of teams.
Now I need to convert this to a line like this :
'Allegoric Alaskans            | 1 | 1 | 0 | 0 | 3'
I tried it with this :
outcome := Array
      streamContents: [ :s |
         TeamStatusSorted
            do: [ :each |
               s << each name.
               s << String cr ] ].
   ^ outcome
or String streamContents but it will not give me the right answer,
So please some hints how I can make this work.
Roelof
March 26, 2019
Re: [Pharo-users] What oo/modelling books/articles do we recommend these days?
by Tim Mackinnon
Actually - Iâve been making good progress on Exercism (with help from Ben and Sam) - we can almost come out of alpha (but just need more exercises converted - not sure exactly what the limit is, but 22 isnât quite enough).
Iâm just tuning the tooling - and putting some bits in place so that its easier for others to help convert exercises - as well as some tools to help with mentoring (e.g. I can load snapshots of user submissions, but would love to figure out how to re-use our diff browser). Iâm hoping to get a bit of input at Pharo days, to just nail it.
Anyway - if you want to try it - follow the instructions here: https://github.com/exercism/pharo-smalltalk <https://github.com/exercism/pharo-smalltalk> (the top section outlines how to setup, the bottom is for contributors - but best to have tried it out first before taking that plunge).
The example that triggered this off was seeing some of the beta testers struggle with: https://github.com/exercism/pharo-smalltalk/blob/master/dev/src/Exercism/To… <https://github.com/exercism/pharo-smalltalk/blob/master/dev/src/Exercism/To…> - a rather innocuous exercise, but actually the first one that wasnât just an algorithmic several lines of code.
Thanks for for everyoneâs input - I think Iâm getting some ideas for material to put into the site, and possibly something to add to the hints for that exercise.
Tim
> On 26 Mar 2019, at 14:20, Christopher Fuhrman <christopher.fuhrman(a)gmail.com> wrote:
>
> Finally - I'm not familiar with exercism exercises (I signed up but saw that smalltalk is still in alpha). Is there a sneak peak of an example exercise?
March 26, 2019
Re: [Pharo-users] ZnURL and parsing URL with diacritics
by PBKResearch
Sven
Well RFCs are unreadable - I know, because I looked at 3986 while looking at this question - but OK, I get your point. I suppose I should be looking for something that makes it easier to provide similar convenience features in Pharo. As you say, if this issue is cracked, that is a step on the way.
Peter
-----Original Message-----
From: Pharo-users <pharo-users-bounces(a)lists.pharo.org> On Behalf Of Sven Van Caekenberghe
Sent: 26 March 2019 15:08
To: Any question about pharo is welcome <pharo-users(a)lists.pharo.org>
Subject: Re: [Pharo-users] ZnURL and parsing URL with diacritics
Peter,
It *is* a bogus URL, please go and read some RFCs.
A browser's address/search box is an entirely different thing that adds convenience features, such as the issue we are discussing here.
Sven
> On 26 Mar 2019, at 16:02, PBKResearch <peter(a)pbkresearch.co.uk> wrote:
>
> Sven
>
> That would certainly work, and represents the most liberal possible
> approach. An equivalent, keeping entirely within Zinc, would be to use
> a special-purpose instance of ZnPercentEncoder, in which the safe set
> is defined as all characters between code points 33 and 126 inclusive.
> (Starting at 33 fixes your space point.)
>
> Using 'bogusUrl' as a variable name seems a bit pejorative. I am looking up French and German words in Wiktionary all the time, and I am building a Pharo app to do it for me. The version of the url with the accented characters will not work in Zinc until I have urlEncoded it, but it works perfectly well in a browser and is much easier to read.
>
> Peter Kenny
>
>
> -----Original Message-----
> From: Pharo-users <pharo-users-bounces(a)lists.pharo.org> On Behalf Of
> Sven Van Caekenberghe
> Sent: 26 March 2019 12:26
> To: Any question about pharo is welcome <pharo-users(a)lists.pharo.org>
> Subject: Re: [Pharo-users] ZnURL and parsing URL with diacritics
>
> I would use a variant of your original transformation.
>
> The issue (the error in the URL) is that all kinds of non-ASCII characters occur unencoded. We should/could assume that other special/reserved ASCII characters _are_ properly encoded (so we do not need to handle them).
>
> So I would literally patch/fix the problem, like this:
>
> | bogusUrl fixedUrl url |
> bogusUrl := 'https://en.wikipedia.org/wiki/Äeská republika'.
> fixedUrl := String streamContents: [ :out |
> bogusUrl do: [ :each |
> (each codePoint < 127 and: [ each ~= $ ])
> ifTrue: [ out nextPut: each ]
> ifFalse: [ out nextPutAll: each asString urlEncoded ] ] ].
> fixedUrl asUrl retrieveContents.
>
> I made and extra case for the space character, it works either way in the example given, but a space cannot occur freely.
>
>> On 26 Mar 2019, at 12:53, PBKResearch <peter(a)pbkresearch.co.uk> wrote:
>>
>> Sean
>>
>> I have realized that the method I proposed can be expressed entirely within the Zinc system, which may make it a bit neater and easier to follow. There probably is no completely general solution, but there is a completely general way of finding a solution for your problem domain.
>>
>> It is important to realize that String>>urlEncoded is defined as:
>> ZnPercentEncoder new encode: self.
>> ZnPercentEncoder does not attempt to parse the input string as a url. It scans the entire string, and percent encodes any character that is not in its safe set (see the comment to ZnPercentEncoder>>encode:). Sven has given as default a minimum safe set, which does not include slash, but there is a setter method to redefine the safe set.
>>
>> So the general way to find a solution for your domain is to collect a representative set of the url strings, apply String>>urlEncoded to each, and work out which characters have been percent encoded wrongly for your domain. For any url cases this is likely to include ':/?#', as well as '%' if it includes things already percent encoded, but there may be others specific to your domain. Now construct an instance of ZnPercentEncoder with the safe set extended to include these characters - note that the default safe set is given by the class method ZnPercentEncoder class>> rfc3986UnreservedCharacters. Apply this instance to encode all your test incoming url strings and verify that they work. Iterate, extending the safe set, until everything passes.
>>
>> If you want to keep the neatness being able to write something like 'incomingString urlEncoded asZnUrl', you can add a method to String; for the case of the common url characters mentioned above:
>>
>> String>> urlEncodedMyWay
>>
>> "As urlEncoded, but with the safe set extended to include characters commonly found in a url"
>>
>> ^ ZnPercentEncoder new safeSet: ':/?#%', (ZnPercentEncoder rfc3986UnreservedCharacters);
>> encode: self
>>
>> This works in much the same way as the snippet I posted originally, because my code simply reproduces the essentials of ZnPercentEncoder>>encode:.
>>
>> I seem to be trying to monopolize this thread, so I shall shut up now.
>>
>> HTH
>>
>> Peter Kenny
>>
>> -----Original Message-----
>> From: Pharo-users <pharo-users-bounces(a)lists.pharo.org> On Behalf Of
>> PBKResearch
>> Sent: 24 March 2019 15:36
>> To: 'Any question about pharo is welcome'
>> <pharo-users(a)lists.pharo.org>
>> Subject: Re: [Pharo-users] ZnURL and parsing URL with diacritics
>>
>> Well it didn't take long to find a potential problem in what I wrote, at least as a general solution. If the input string contains something which has already been percent encoded, it will re-encode the percent signs. In this case, decoding will recover the once-encoded version, but we need to decode twice to recover the original text. Any web site receiving this version will almost certainly decode once only, and so will not see the right details.
>>
>> The solution is simple - just include the percent sign in the list of excluded characters in the third line, so it becomes:
>> url asString do: [ :ch|(':/?%' includes: ch )
>>
>> -----Original Message-----
>> From: Pharo-users <pharo-users-bounces(a)lists.pharo.org> On Behalf Of
>> PBKResearch
>> Sent: 24 March 2019 12:11
>> To: 'Any question about pharo is welcome'
>> <pharo-users(a)lists.pharo.org>
>> Subject: Re: [Pharo-users] ZnURL and parsing URL with diacritics
>>
>> Sean, Sven
>>
>> Thinking about this, I have found a simple (maybe too simple) way round it. The obvious first approach is to apply 'urlEncoded' to the received url string, but this fails because it also encodes the slashes and other segment dividers. A simple-minded approach is to scan the received string, copy the slashes and other segment dividers unchanged and percent encode everything else. I cobbled together the following in a playground, but it could easily be turned into a method in String class.
>>
>> urlEncodedSegments := [ :url||outStream|
>> outStream := String new writeStream.
>> url asString do: [ :ch|(':/?' includes: ch )
>> ifTrue: [ outStream nextPut: ch ]
>> ifFalse:[outStream nextPutAll: ch asString urlEncoded ] ].
>> outStream contents].
>>
>> urlEncodedSegments value: 'https://fr.wiktionary.org/wiki/péripétie'
>> => https://fr.wiktionary.org/wiki/p%C3%A9rip%C3%A9tie
>>
>> This may fail if a slash can occur in a url other than as a segment divider. I am not sure if this is possible - could there be some sort of escaped slash within a segment? Anyway, if the received url strings are well-behaved, apart from the diacritics, this approach could be used as a hack for Sean's problem.
>>
>> HTH
>>
>> Peter Kenny
>>
>> Note to Sven: The comment to String>>urlEncoded says: ' This is an encoding where characters that are illegal in a URL are escaped.' Slashes are escaped but are quite legal. Should the comment be changed, or the method?
>>
>>
>>
>> -----Original Message-----
>> From: Pharo-users <pharo-users-bounces(a)lists.pharo.org> On Behalf Of
>> Sven Van Caekenberghe
>> Sent: 23 March 2019 20:03
>> To: Any question about pharo is welcome <pharo-users(a)lists.pharo.org>
>> Subject: Re: [Pharo-users] ZnURL and parsing URL with diacritics
>>
>>
>>
>>> On 23 Mar 2019, at 20:53, Sean P. DeNigris <sean(a)clipperadams.com> wrote:
>>>
>>> Peter Kenny wrote
>>>> And when I inspect the result, it is the address of a non-existent
>>>> file in my image directory.
>>>
>>> Ah, no. I see the same result. By "worked" I meant that it created a
>>> URL that safari accepted, but I see now it's not the same as
>>> correctly parsing it.
>>>
>>>
>>> Peter Kenny wrote
>>>> Incidentally, I tried the other trick Sven cites in the same thread.
>>>> The same url as above can be written:
>>>> 'https://fr.wiktionary.org/wiki' asUrl / 'péripétie'.
>>>
>>> Yes, this works if you are assembling the URL, but several people
>>> presented the use case of processing URLs from elsewhere, leaving
>>> one in a chicken-and-egg situation where one can't parse due to the
>>> diacritics and can't escape the diacritics (i.e. without incorrectly
>>> escaping other things) without parsing :/
>>
>> Yes, that is pretty close to a catch 22. Strictly speaking, such URLs are incorrect and can't be parsed.
>>
>> I do understand that sometimes these URLs occur in the wild, but again, strictly speaking they are in error.
>>
>> The fact that browser search boxes accept them is a service on top of the strict URL syntax, I am not 100% sure how they do it, but it probably involves a lot of heuristics and trial and error.
>>
>> The parser of ZnUrl is just 3 to 4 methods. There is nothing preventing somebody from making a new ZnLoseUrlParser, but it won't be easy.
>>
>>> -----
>>> Cheers,
>>> Sean
>>> --
>>> Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
>>>
>>
>>
>>
>>
>>
>
>
>
March 26, 2019
Re: [Pharo-users] ZnURL and parsing URL with diacritics
by Sven Van Caekenberghe
Peter,
It *is* a bogus URL, please go and read some RFCs.
A browser's address/search box is an entirely different thing that adds convenience features, such as the issue we are discussing here.
Sven
> On 26 Mar 2019, at 16:02, PBKResearch <peter(a)pbkresearch.co.uk> wrote:
>
> Sven
>
> That would certainly work, and represents the most liberal possible approach. An equivalent, keeping entirely within Zinc, would be to use a special-purpose instance of ZnPercentEncoder, in which the safe set is defined as all characters between code points 33 and 126 inclusive. (Starting at 33 fixes your space point.)
>
> Using 'bogusUrl' as a variable name seems a bit pejorative. I am looking up French and German words in Wiktionary all the time, and I am building a Pharo app to do it for me. The version of the url with the accented characters will not work in Zinc until I have urlEncoded it, but it works perfectly well in a browser and is much easier to read.
>
> Peter Kenny
>
>
> -----Original Message-----
> From: Pharo-users <pharo-users-bounces(a)lists.pharo.org> On Behalf Of Sven Van Caekenberghe
> Sent: 26 March 2019 12:26
> To: Any question about pharo is welcome <pharo-users(a)lists.pharo.org>
> Subject: Re: [Pharo-users] ZnURL and parsing URL with diacritics
>
> I would use a variant of your original transformation.
>
> The issue (the error in the URL) is that all kinds of non-ASCII characters occur unencoded. We should/could assume that other special/reserved ASCII characters _are_ properly encoded (so we do not need to handle them).
>
> So I would literally patch/fix the problem, like this:
>
> | bogusUrl fixedUrl url |
> bogusUrl := 'https://en.wikipedia.org/wiki/Äeská republika'.
> fixedUrl := String streamContents: [ :out |
> bogusUrl do: [ :each |
> (each codePoint < 127 and: [ each ~= $ ])
> ifTrue: [ out nextPut: each ]
> ifFalse: [ out nextPutAll: each asString urlEncoded ] ] ].
> fixedUrl asUrl retrieveContents.
>
> I made and extra case for the space character, it works either way in the example given, but a space cannot occur freely.
>
>> On 26 Mar 2019, at 12:53, PBKResearch <peter(a)pbkresearch.co.uk> wrote:
>>
>> Sean
>>
>> I have realized that the method I proposed can be expressed entirely within the Zinc system, which may make it a bit neater and easier to follow. There probably is no completely general solution, but there is a completely general way of finding a solution for your problem domain.
>>
>> It is important to realize that String>>urlEncoded is defined as:
>> ZnPercentEncoder new encode: self.
>> ZnPercentEncoder does not attempt to parse the input string as a url. It scans the entire string, and percent encodes any character that is not in its safe set (see the comment to ZnPercentEncoder>>encode:). Sven has given as default a minimum safe set, which does not include slash, but there is a setter method to redefine the safe set.
>>
>> So the general way to find a solution for your domain is to collect a representative set of the url strings, apply String>>urlEncoded to each, and work out which characters have been percent encoded wrongly for your domain. For any url cases this is likely to include ':/?#', as well as '%' if it includes things already percent encoded, but there may be others specific to your domain. Now construct an instance of ZnPercentEncoder with the safe set extended to include these characters - note that the default safe set is given by the class method ZnPercentEncoder class>> rfc3986UnreservedCharacters. Apply this instance to encode all your test incoming url strings and verify that they work. Iterate, extending the safe set, until everything passes.
>>
>> If you want to keep the neatness being able to write something like 'incomingString urlEncoded asZnUrl', you can add a method to String; for the case of the common url characters mentioned above:
>>
>> String>> urlEncodedMyWay
>>
>> "As urlEncoded, but with the safe set extended to include characters commonly found in a url"
>>
>> ^ ZnPercentEncoder new safeSet: ':/?#%', (ZnPercentEncoder rfc3986UnreservedCharacters);
>> encode: self
>>
>> This works in much the same way as the snippet I posted originally, because my code simply reproduces the essentials of ZnPercentEncoder>>encode:.
>>
>> I seem to be trying to monopolize this thread, so I shall shut up now.
>>
>> HTH
>>
>> Peter Kenny
>>
>> -----Original Message-----
>> From: Pharo-users <pharo-users-bounces(a)lists.pharo.org> On Behalf Of
>> PBKResearch
>> Sent: 24 March 2019 15:36
>> To: 'Any question about pharo is welcome'
>> <pharo-users(a)lists.pharo.org>
>> Subject: Re: [Pharo-users] ZnURL and parsing URL with diacritics
>>
>> Well it didn't take long to find a potential problem in what I wrote, at least as a general solution. If the input string contains something which has already been percent encoded, it will re-encode the percent signs. In this case, decoding will recover the once-encoded version, but we need to decode twice to recover the original text. Any web site receiving this version will almost certainly decode once only, and so will not see the right details.
>>
>> The solution is simple - just include the percent sign in the list of excluded characters in the third line, so it becomes:
>> url asString do: [ :ch|(':/?%' includes: ch )
>>
>> -----Original Message-----
>> From: Pharo-users <pharo-users-bounces(a)lists.pharo.org> On Behalf Of
>> PBKResearch
>> Sent: 24 March 2019 12:11
>> To: 'Any question about pharo is welcome'
>> <pharo-users(a)lists.pharo.org>
>> Subject: Re: [Pharo-users] ZnURL and parsing URL with diacritics
>>
>> Sean, Sven
>>
>> Thinking about this, I have found a simple (maybe too simple) way round it. The obvious first approach is to apply 'urlEncoded' to the received url string, but this fails because it also encodes the slashes and other segment dividers. A simple-minded approach is to scan the received string, copy the slashes and other segment dividers unchanged and percent encode everything else. I cobbled together the following in a playground, but it could easily be turned into a method in String class.
>>
>> urlEncodedSegments := [ :url||outStream|
>> outStream := String new writeStream.
>> url asString do: [ :ch|(':/?' includes: ch )
>> ifTrue: [ outStream nextPut: ch ]
>> ifFalse:[outStream nextPutAll: ch asString urlEncoded ] ].
>> outStream contents].
>>
>> urlEncodedSegments value: 'https://fr.wiktionary.org/wiki/péripétie'
>> => https://fr.wiktionary.org/wiki/p%C3%A9rip%C3%A9tie
>>
>> This may fail if a slash can occur in a url other than as a segment divider. I am not sure if this is possible - could there be some sort of escaped slash within a segment? Anyway, if the received url strings are well-behaved, apart from the diacritics, this approach could be used as a hack for Sean's problem.
>>
>> HTH
>>
>> Peter Kenny
>>
>> Note to Sven: The comment to String>>urlEncoded says: ' This is an encoding where characters that are illegal in a URL are escaped.' Slashes are escaped but are quite legal. Should the comment be changed, or the method?
>>
>>
>>
>> -----Original Message-----
>> From: Pharo-users <pharo-users-bounces(a)lists.pharo.org> On Behalf Of
>> Sven Van Caekenberghe
>> Sent: 23 March 2019 20:03
>> To: Any question about pharo is welcome <pharo-users(a)lists.pharo.org>
>> Subject: Re: [Pharo-users] ZnURL and parsing URL with diacritics
>>
>>
>>
>>> On 23 Mar 2019, at 20:53, Sean P. DeNigris <sean(a)clipperadams.com> wrote:
>>>
>>> Peter Kenny wrote
>>>> And when I inspect the result, it is the address of a non-existent
>>>> file in my image directory.
>>>
>>> Ah, no. I see the same result. By "worked" I meant that it created a
>>> URL that safari accepted, but I see now it's not the same as
>>> correctly parsing it.
>>>
>>>
>>> Peter Kenny wrote
>>>> Incidentally, I tried the other trick Sven cites in the same thread.
>>>> The same url as above can be written:
>>>> 'https://fr.wiktionary.org/wiki' asUrl / 'péripétie'.
>>>
>>> Yes, this works if you are assembling the URL, but several people
>>> presented the use case of processing URLs from elsewhere, leaving one
>>> in a chicken-and-egg situation where one can't parse due to the
>>> diacritics and can't escape the diacritics (i.e. without incorrectly
>>> escaping other things) without parsing :/
>>
>> Yes, that is pretty close to a catch 22. Strictly speaking, such URLs are incorrect and can't be parsed.
>>
>> I do understand that sometimes these URLs occur in the wild, but again, strictly speaking they are in error.
>>
>> The fact that browser search boxes accept them is a service on top of the strict URL syntax, I am not 100% sure how they do it, but it probably involves a lot of heuristics and trial and error.
>>
>> The parser of ZnUrl is just 3 to 4 methods. There is nothing preventing somebody from making a new ZnLoseUrlParser, but it won't be easy.
>>
>>> -----
>>> Cheers,
>>> Sean
>>> --
>>> Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
>>>
>>
>>
>>
>>
>>
>
>
>
March 26, 2019