From: Vladimir Sizikov Date: 2008-06-05T18:59:48+09:00 Subject: [ruby-core:17118] Re: [PATCH] Iconv#iconv(str, start, length) doesn't really convert str[start, length] Hi, On Thu, Jun 5, 2008 at 1:57 AM, Vincent wrote: > I Agree. That patch should have been created for 1.9 or later version > (if the core team > decided to have this change.) > > I was going to create a documentation patch for ruby_1_8, and another patch for > trunk with incompatible changes, but the latest revision 16809 just > shows up today. OK, let's recap the current situation: 1. ruby_1_8_6 branch: old behavior, out of sync with docs 2. ruby_1_8_7 branch: old behavior, out of sync with docs 3. ruby_1_8 branch: newer, backward incompatible and broken behavior: a) it is clearly broken: ruby -riconv -ve "p Iconv.open('ascii', 'ascii').iconv('abcde')" ruby 1.8.7 (2008-06-04 patchlevel 5000) [i686-linux] "" and ruby -riconv -ve "p Iconv.open('ascii', 'ascii').iconv('abcde', 2, 7)" ruby 1.8.7 (2008-06-04 patchlevel 5000) [i686-linux] "cde\000so\000" b) it is still not fully in sync with the docs: "length: conversion length; nil means whole the string from start", but /opt/ruby1.8/bin/ruby -riconv -ve "p Iconv.open('ascii', 'ascii').iconv('abcde', 0, nil)" ruby 1.8.7 (2008-06-04 patchlevel 5000) [i686-linux] "" c) Sooner or later it will be propagated to 1_8_7 branch and released as a patch level update to 1.8.7, right? So we'll end up with rather different behaviors even for the same version (1.8.7) 4. trunk: newer, backward incompatible, behavior, and: a) It differs from both 1_8_6 and 1_8 behaviors, at least it correctly handles the common case: ruby -riconv -ve "p Iconv.open('ascii', 'ascii').iconv('abcde')" ruby 1.9.0 (2008-06-05 revision 0) [i686-linux] "abcde" b) It is still out of sync with the docs, w.r.t. length argument, see 3b) c) It doesn't handle the out of bounds length correctly, see 3a) Oh, my! :) So, it seems that anybody who'd like to write cross-version compatible scripts or even cross-patchlevel compatible scripts, should not use this method at all. Thanks, --Vladimir