Pharo-users
By thread
pharo-users@lists.pharo.org
By month
Messages by month
- ----- 2026 -----
- August
- 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
- 3 participants
- 50348 messages
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
Re: [Pharo-users] ZnURL and parsing URL with diacritics
by PBKResearch
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] What oo/modelling books/articles do we recommend these days?
by Sean P. DeNigris
Tim Mackinnon wrote
> Has anyone else got any thoughts?
I think Dan North's Behavior Driven Development stuff is great and covers
both OOP and TDD. The code is in Ruby, but the concepts IMHO are on the
money. For me, the holy grail of OOP books is A Mentoring Course on
Smalltalk, but I definitely wouldn't consider it "lightweight" ha ha. I'm
sure there are others, but that's off the top of my head...
-----
Cheers,
Sean
--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
March 26, 2019
Re: [Pharo-users] What oo/modelling books/articles do we recommend these days?
by Christopher Fuhrman
On Tue, 26 Mar 2019 at 10:17, Tim Mackinnon <tim(a)testit.works> wrote:
> Wasnât there something that encouraged you to underline the nouns and
> circle the verbs and then start to identify objects and responsibilities?
> Its that kind of thing I am starting to see as the weak point in people
> approaching problems.
>
That's the Booch method which Larman mentions as the noun-phrase
identification (I actually learned that in 1986 in my first Ada course).
See slide 22 or so at
http://stg-tud.github.io/eise/WS11-EiSE-07-Domain_Modeling.pdf
You could/should cherry-pick Larman's book (there's way too much there even
for one course). There are all the references to Resp-Driven Design and
even a lightweight "domain model" pattern (which doesn't have separate
conceptual classes) from Fowler.
https://martinfowler.com/eaaCatalog/domainModel.html
In my courses I get a lot of mileage from just the two GRASP patterns (that
come from Wirfs-Brock et al if I'm not mistaken): Information Expert
<https://en.wikipedia.org/wiki/GRASP_(object-oriented_design)#Information_ex…>
and Creator, but the latter is easier to apply if you have a domain model
as a separate artifact.
IMO the older approaches to OO design get in to trouble today especially
when 1) most objects use composition (an not inheritance with polymorphism,
although it's very powerful for extending programs) and 2) inheritance is
hard to get right the first time (and is difficult to change). There's real
power in refactoring to patterns (e.g., )
There's the CRC method that Horstmann presents, too (I think that's what
Pharo even recommends in the Class Comment template). Booch and CRC are
mentioned on this page:
http://www.cs.fsu.edu/~myers/cop3331/notes/analysis1.html
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?
Cris
>
> Tim
>
> On 24 Mar 2019, at 22:47, Christopher Fuhrman <
> christopher.fuhrman(a)gmail.com> wrote:
>
> On Sun, 24 Mar 2019 at 21:26, Tim Mackinnon <tim(a)testit.works> wrote:
>
>> Any good references come to mind? As Iâll build up a list that I can
>> point people to, that hopefully puts them in a better place to solve these
>> more interesting and hopefully rewarding problems.
>>
>
> Since 2003 in one of my courses I've used Craig Larman's Applying UML and
> Patterns because it has an analysis approach (getting from a semi-complex
> problem to a working OO solution in iterations, with UML if you want). It's
> using the Point Of Sale (cash register) problem which is complex yet
> familiar enough for most people to grasp (no pun intended, GRASP are the
> patterns he pushes as underlying responsibility-driven principles).
>
> Otherwise, Cay Horstmann's 3rd edition of OO Design and Patterns (Java,
> but applies to any OO language) should be out soon (I provided feedback on
> a draft copy last year). It has some good coverage of OO qualities and also
> uses a realistic problem (Graphics Editing framework, Violet) as the basis
> of lots of examples.
>
>
>
March 26, 2019
Re: [Pharo-users] ZnURL and parsing URL with diacritics
by Sven Van Caekenberghe
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] What oo/modelling books/articles do we recommend these days?
by Tim Mackinnon
Thanks, I recall the Wires-Brock books been pretty good, its a shame you canât preview any of them (and mine are in a box in my attic somewhere). Unfortunately I canât imagine that students first staring out will want to invest - but maybe I can find something that might fill the gap leading to those.
Tim
> On 26 Mar 2019, at 11:06, Stephan Eggermont <stephan(a)stack.nl> wrote:
>
> Tim Mackinnon <tim(a)testit.works> wrote:
>> As I see Exercism students grapple with more realistic, I am wondering
>> what we point people towards to learn about OO, identifying objects and
>> more importantly responsibilities these days?
>>
>> There is the early Beck CRC paper - but looking at it again, I wonder if
>> its a bit cursory for people who missed the whole OO discovery years ago,
>> and are now faced with competing advice on how to write good programs
>> (much of which seems to eschew OO these days - rather unfairly I think).
>>
>> Any good references come to mind? As Iâll build up a list that I can
>> point people to, that hopefully puts them in a better place to solve
>> these more interesting and hopefully rewarding problems.
>
> Rebecca Wirfs-Brock and Alan McKean (2002) Object Design, Roles,
> Responsibilities, and Collaborations?
>
> Stephan
>
>
>
>
March 26, 2019