Open rebolbot opened 14 years ago
Submitted by: PeterWood
As I understand from the documentation, read/strings will only convert UTF-8 encoded data to a string. www.rebol.com is ISO-8859-1 encoded. However, I tested with a UTF-8 encoded site and got the same problem.
>> read/string http://www.bbc.co.uk
== 64#{
PCFET0NUWVBFIGh0bWwgUFVCTElDICItLy9XM0MvL0RURCBYSFRNTCAxLjAgU3Ry
aWN0Ly9FTiIgImh0dHA6Ly93d3cudzMub3JnL1RSL3hodG1sMS9EVEQveGh0bWwx
As the built-in decoding expects to the input to be a UTF-8 encoded binary string, there will always be issues in automatically converting web pages to strings
www.rebol.com is ISO-8859-1 encoded, to string! happily converts the binary of www.rebol.com to a string:
>> to string! read http:www.rebol.com
== {html
head
META NAME="Description" CONTENT="REBOL: a Web 3.0 language and system based on new lightweight computing methods. Site includes products, downloads, documentation, and support."> META NAME="Keywords" CONTENT="REBOL, Web 3.0, Web 2.0, programming, Internet, software, domain specific language, distributed computing, collaboration, operating systems, development, rebel">
meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
title>REBOL Technologies</title>
styl...
This because rebol.com homepage has only characters in the range 0 - 127.
However if there are characters above 128 they will be incorrectly converted by to string! (Perhaps to string! only decodes UTF-8 binary strings)
>> to string! read http://localhost/iso88591.html
== {hmtl>
head>
meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
title>᧠a grave followed by e acute</title>
/head>
;; The ᧠ is an a with a grave accent followed by a e with an acute accent in the source.
[Note: I removed the leading < from the HTML tags to get the html to display in Curecode.]
Submitted by: abolka
READ (without /string) of an URL already automatically converts to a string! if the HTTP headers claim the content to be UTF8-encoded. (This could be extended to handle other encodings, but that's a separate issue.)
READ/string is intended as a shortcut for to string! read
, i.e. forced conversion from UTF-8. (to string!
of binary data always decodes using UTF-8; so would READ/string). READ/string is currently not implemented for URLs.
Submitted by: BrianH
Note, READ without /string should never convert to string, it should return a binary. If you want READ to autoconvert, please rewrite the Rebol language parser so it can parse strings. Until then, it depends on READ without /string returning a binary, and every time READ returns a string it has to be converted back into a binary before it can be parsed.
READ/string is a shortcut for TO-STRING READ, but when /string is not specified that means that the developer doesn't want it converted to a string. If they did, they would have called READ/string instead. So that means that the HTTP conversion code needs to happen a little less automatically before this ticket can be considered fixed.
Submitted by: sqlab
CC - Data [ Version: alpha 82 Type: Bug Platform: Windows Category: Native Reproduce: Always Fixed-in:none ]