From: Samuel Williams Date: 2012-06-12T01:48:39+09:00 Subject: Re: Is resolv.rb broken in 1.9.3 due to encodings? --90e6ba5bbba103f87404c2351f19 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Okay, so I just did a bit more testing and found that at least I get an error. When I try to encode a IN::TXT record that includes UTF-8 Japanese characters, I get the following error: Encoding::CompatibilityError: incompatible character encodings: ASCII-8BIT and UTF-8 I can't see why this is happening though because the initial @data =3D '' = =96 shouldn't that use the default encoding (UTF-8)? Finally, I am happy to pack UTF-8 data into the IN::TXT, but it doesn't seem that this is possible using IN::TXT as it currently stands =96 is ther= e some way to consider the UTF-8 string as ASCII-8BIT for binary data purposes? Kind regards, Samuel On 12 June 2012 04:28, Samuel Williams wrot= e: > Hi, > > I'm trying to work through some issues using 1.9.3 for my project RubyDNS= , > and I noticed the following code in resolv.rb's MessageEncoder: > > class MessageEncoder # :nodoc: > def initialize > @data =3D '' > @names =3D {} > yield self > end > > def to_s > return @data > end > > def put_bytes(d) > @data << d > end > > def put_pack(template, *d) > @data << d.pack(template) > end > > def put_length16 > length_index =3D *@data.length* > @data << "\0\0" > data_start =3D *@data.length* > yield > data_end =3D *@data.length* > * @data[length_index, 2] =3D [data_end - data_start].pack("n")* > end > > I'm just wondering, shouldn't this be using byteslice, bytesize and > friends? Isn't this code completely broken by default since we use UTF-8 > encoding? Am I missing something? > > Kind regards, > Samuel > --90e6ba5bbba103f87404c2351f19 Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Okay, so I just did a bit more testing and found that at least I get an err= or. When I try to encode a IN::TXT record that includes UTF-8 Japanese char= acters, I get the following error:

Encoding::Compatibili= tyError: incompatible character encodings: ASCII-8BIT and UTF-8

I can't see why this is happening though because the ini= tial @data =3D '' =96 shouldn't that use the default encoding (= UTF-8)?

Finally, I am happy to pack UTF-8 data int= o the IN::TXT, but it doesn't seem that this is possible using IN::TXT = as it currently stands =96 is there some way to consider the UTF-8 string a= s ASCII-8BIT for binary data purposes?

Kind regards,
Samuel

On 12 June 2012 04:28, Samuel Williams &= lt;spac= e.ship.traveller@gmail.com> wrote:
Hi,<= div>
I'm trying to work through some issues using 1.9.3 f= or my project RubyDNS, and I noticed the following code in resolv.rb's = MessageEncoder:

=A0 =A0 =A0 class MessageEncoder # :nodoc:
=A0 =A0 =A0 =A0 def initialize
=A0 =A0 =A0 =A0 =A0 @data =3D= ''
=A0 =A0 =A0 =A0 =A0 @names =3D {}
=A0 =A0 = =A0 =A0 =A0 yield self
=A0 =A0 =A0 =A0 end

=A0 =A0 =A0 =A0 def to_s
=A0 =A0 =A0 =A0 =A0 return @data
=A0 =A0 =A0 =A0 end

=A0 =A0 =A0 =A0 def put_b= ytes(d)
=A0 =A0 =A0 =A0 =A0 @data << d
=A0 =A0 = =A0 =A0 end

=A0 =A0 =A0 =A0 def put_pack(template,= *d)
=A0 =A0 =A0 =A0 =A0 @data << d.pack(template)
=A0 =A0 =A0 =A0 end

=A0 =A0 =A0 =A0 def put_l= ength16
=A0 =A0 =A0 =A0 =A0 length_index =3D @data.length<= /div>
=A0 =A0 =A0 =A0 =A0 @data << "\0\0"
=A0= =A0 =A0 =A0 =A0 data_start =3D @data.length
=A0 =A0 =A0 =A0 =A0 yield
=A0 =A0 =A0 =A0 =A0 data_end =3D <= b>@data.length
=A0 =A0 =A0 =A0 =A0 @data[length_index, 2] = =3D [data_end - data_start].pack("n")
=A0 =A0 =A0 = =A0 end

I'm just wondering, shouldn't this be using byteslice, bytesize and= friends? Isn't this code completely broken by default since we use UTF= -8 encoding? Am I missing something?

Kind regards,=
Samuel

--90e6ba5bbba103f87404c2351f19--