On Thu, Mar 16, 2017 at 6:25 AM, Sven Van Caekenberghe <sven@stfx.eu> wrote:
On 15 Mar 2017, at 20:52, Rein, Patrick <Patrick.Rein@hpi.de> wrote:
Unfortunately, as I am trying to fix a Travis build, I can not change the call to Zinc.
To be clear about this: I also think that squeaksource should serve UTF-8. However, at the same time a missing charset in a HTTP response means that the content should be decoded as ISO-8859-1 [1]. So in general this does seem to me like an issue in Zinc.
I see that this might be a problem to change though, so I will consider moving the project at one point (or removing that damn umlaut :) ).
Bests Patrick
(Hypertext Transfer Protocol -- HTTP/1.1) For easy reference, the pertinent part seems to be... When no explicit charset parameter is provided by the sender, media subtypes of the "text" type are defined to have a default charset value of "ISO-8859-1" when received via HTTP. Additional support... Section 6, The 'text/html' Media Type (http://www.rfc-editor.org/rfc/rfc2854.txt) [MIME] specifies "The default character set, which must be assumed in the absence of a charset parameter, is US-ASCII." [HTTP] Section 3.7.1, defines that "media subtypes of the 'text' type are defined to have a default charset value of 'ISO-8859-1'".
Hmm, OK, I never saw that paragraph, interesting. Thanks for the pointer, I will put it on my todo list to think about.
Food for thought... https://en.wikipedia.org/wiki/Robustness_principle which is implied here... https://www.w3.org/Protocols/rfc2616/rfc2616-sec7.html#sec7.2.1 Any HTTP/1.1 message containing an entity-body SHOULD include a Content-Type header field defining the media type of that body. If and only if the media type is not given by a Content-Type field, the recipient **MAY** attempt to guess the media type via inspection of its content and/or the name extension(s) of the URI used to identify the resource. Perhaps then its okay to consider the media type is not fully defined when there no character encoding is specified, and content inspection is okay - perhaps only in the face of a character encoding error. So even though at the HTML level, these articles are interesting... Character encoding in HTML https://www.w3.org/blog/2008/03/html-charset/ Encoding Divination http://nikitathespider.com/articles/EncodingDivination.html On Thu, Mar 16, 2017 at 3:55 AM, monty <monty2@programmer.net> wrote:
That isn't Zinc's responsibility; it just handles HTTP. The HTML or XML parser using it should disable Zinc's automatic decoding based on Content-Type and do its own decoding of the raw response (which can still be done using Zinc's decoders) informed by the content of the response and not just its Content-Type. XMLParser and XMLParserHTML both use Zinc this way.
But a lot of what people want to do from the image is process web data by parsing HTML or XML. So is there anything we do to make it more robust out of the box (without getting in the way) ZnClient is promoted as the "easy" way to use Zinc. Could that not have additional smarts to inspect the content to "auto" divine the encoding. Or maybe we need another user-agent tool that does this? cheers -ben
________________________________________ From: Pharo-dev <pharo-dev-bounces@lists.pharo.org> on behalf of Ben Coman <btc@openinworld.com> Sent: Wednesday, March 15, 2017 19:16 To: Pharo Development List Subject: Re: [Pharo-dev] ZnInvalidUTF8 on response from squeaksource
On Thu, Mar 16, 2017 at 1:25 AM, Sven Van Caekenberghe <sven@stfx.eu> wrote:
Hi,
This is a recurring issue.
It would be cool if some magic(TM) could raise a dialog with an explanation and pull-down list to select an encoding - but maybe that is too much hand holding.
The problem is that the server serves a resource, in this case text/html, without specifying its encoding.
I just bumped into [1] while browsing around to learn more, but I don't know fully how to interpret it. What do you make of it saying "An XHTML5 document is served as XML and has XML syntax. XML parsers do not recognise the encoding declarations in meta elements. They only recognise the XML declaration. Here is an example: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html ....
compared to the page having... <?xml version="1.0" encoding="iso-8859-1"?>
cheers -ben
[1] https://www.w3.org/International/questions/qa-html-encoding-declarations
Today, when no encoding is specified, we default to UTF-8. In this case the server silently serves a resource which is ISO-8895-1 encoded.
The error is triggered by accessing the following URL:
ZnClient new get: 'http://squeaksource.com/ical/?C=M;O%3DD'; yourself.
If you inspect the response object inside the http client, you will see that the content-type is text/html. So Zn parses the incoming text using UTF-8 which fails (Zn encoders are strict by default).
Here is how to change the default during a call:
ZnDefaultCharacterEncoder value: ZnCharacterEncoder iso88591 during: [ ZnClient new get: 'http://squeaksource.com/ical/?C=M;O%3DD'; yourself ].
The solution would be that the server adds the proper charset specification.
Consider the default in Pharo:
ZnMimeType textHtml => text/html;charset=utf-8
The server should serve this resource using the following Content-Type:
text/html;charset=iso-8859-1
This is the server's responsibility. The page in question is the MC index page, which would normally be dynamically generated. Somewhere the server decides on the encoding. That encoding does not have to change, but it should be properly indicated in the HTTP response headers.
HTH,
Sven
On 15 Mar 2017, at 17:42, David T. Lewis <lewis@mail.msen.com> wrote:
squeaksource.com is still running on a quite old image, and I know that it has problems with multibyte characters. If you are seeing problems related to this, it's not the fault of Zinc.
If you can confirm that this is what is happening, then I guess it is time to update that trusty old squeaksource.com image :-)
Dave
On Wed, Mar 15, 2017 at 8:19 PM, Patrick R. <patrick.rein@hpi.de> wrote:
Hi everyone,
I have been working on bringing http://squeaksource.com/ical/ up to speed for Squeak and wanted to make sure that it also works for Pharo.
Therefore,
I have created a travis build job for Squeak and Pharo (https://travis-ci.org/codeZeilen/ical-smalltalk/jobs/211298950) which pulls the source from squeaksource.com.
Now the issue is that loading the package in Pharo fails with a GoferException wrapping a ZnInvalidUTF8 Exception. We figured that this might be the result of the squeaksource page delivering the page as iso-8859-1 as it contains special characters. Any ideas on how to get this to work? I do not have access to the ical repository description and I would like to avoid mirroring the whole repository on GitHub.
In a fresh 60437 image, in Playground evaluating...
Metacello new configuration: 'ICal'; repository: 'github://codeZeilen/ical-smalltalk:master/repository'; onConflict: [:ex | ex allow]; load. ==> Could not resolve: ICal-Core [ICal-Core-PaulDeBruicker.5] in /home/ben/.local/share/Pharo/images/60437-01/pharo-local/package-cache http://squeaksource.com/ical ERROR: 'GoferRepositoryError: Could not access http://squeaksource.com/ical: ZnInvalidUTF8: Illegal continuation byte for utf-8 encoding'
In a new fresh 60437 Image (i.e. empty package-cache) World menu > Monticello > +Repository > squeaksource.com... MCSqueaksourceRepository location: 'http://squeaksource.com/ical' user: '' password: '' ==> open repository then errors "MCRepositoryError: Could not access http://squeaksource.com/ical: ZnInvalidUTF8: Illegal continuation byte for utf-8 encoding"
In Chrome, opening http://www.squeaksource.com/ical then clicking <Versions> and the browser's View Page Source, I see... <?xml version="1.0" encoding="iso-8859-1"?>
Googling: zinc iso-8859-1 finds... http://forum.world.st/Problem-using-Zinc-in-Pharo-4-Moose-5-1-td4825329.html but "ZnByteEncoder iso88591" errors with "KeyNotFound: key 'iso88591' not found in Dictionary" and inspecting "ZnByteEncoder byteTextConverters keys sorted" confirms this key is missing (@Sven, I'm curious why was this removed? )
Now https://en.wikipedia.org/wiki/ISO/IEC_8859-1 indicates IBM819 is an alias and " ZnByteEncoder newForEncoding: 'ibm819' " works okay
So in MCHttpRepository>>#loadAllFileNames changing... queryAt: 'C' put: 'M;O=D' ; get. to... queryAt: 'C' put: 'M;O=D' . ZnDefaultCharacterEncoder value: (ZnByteEncoder newForEncoding: 'ibm819') during: [client get].
Then from Monticello opening the previously defined http://squeaksource.com/ical works!!
Now I was hoping that reverting #loadAllFileNames and in Playground doing... converters := ZnByteEncoder byteTextConverters. converters at: 'iso-8859-1' put: (converters at: 'ibm819'). might alleviate the problem, but no luck.
Anyone know a better way to deal with this that hardcoding the encoding into #loadAllFileNames?
cheers -ben