From: "Martin J. Dürst" Date: 2010-01-27T18:27:16+09:00 Subject: [ruby-core:27890] Re: [Bug #2636] Incorrect UTF-16 string length On 2010/01/25 16:37, Vincent Isambart wrote: >> What needs to be fixed here is the data, nothing else: >> >> irb(main):001:> s = "\xDC\x0B\xD8\x40".force_encoding 'UTF-16BE' >> => "\xDC\x{BD8}\x40" >> irb(main):002:> s.valid_encoding? >> => false > > Yes I know the data is invalid UTF-16. I created it on purpose (to > test code I'm working on for MacRuby). > > My main concern was that what #length and #[] were doing was different. > If s[0], s[1], s[2] would have been returning "\xDC", "\x{BD8}" and > "\x40" it would have been consistent. But s[2] was returning nil even > though s.length was 3. > > And after Tanaka Akira's fix, Ruby does exactly what I was expecting. I don't oppose Akira's fix, but expecting consistent output from inconsistent input is essentially futile. I sincerely hope nobody will add this case to a test suite or will claim that this is THE right way to do things. Regards, Martin. -- #-# Martin J. D�rst, Professor, Aoyama Gakuin University #-# http://www.sw.it.aoyama.ac.jp mailto:duerst@it.aoyama.ac.jp