------ art_6630_25899736.1212550891253
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Hi Core,
In the documentation of Iconv#iconv(str, start length)
(http://www.ruby-doc.org/stdlib/libdoc/iconv/rdoc/classes/Iconv.html),
it says "If str is a String, converts str[start, length] and returns
the converted string."
However, this is not true:
Iconv.open 'ascii', 'ascii' do |c| c.iconv 'abcde', 3, 1 end
""
for ruby-1.8.6, ruby-1.8.7 and ruby-1.9.
If it converts str[start, length], the result should be "d":
Iconv.open 'ascii', 'ascii' do |c| c.iconv 'abcde'[3, 1] end
"d"
The current implementation treats length more like another index.
After the patch is applied, Iconv#iconv converts str[start, length].
One exception is that when str[start, length] is nil,
Iconv#iconv will behave as if it gets an empty string "".
This is because Iconv#iconv(nil) is for resetting output shift state.
I copy and paste the patch here in case Gmail uses Base64.
Index: ext/iconv/iconv.c
--- ext/iconv/iconv.c (revision 16799)
+++ ext/iconv/iconv.c (working copy)
@@ -417,17 +417,26 @@
slen STRING(str)->len;
inptr STRING(str)->ptr;
- if (start < 0 ? (start + len) < 0 : start > len)
- length ;
- else if (length < 0 && (length + len + 1) < 0)
- length ;
- else if ((length - tart) < 0)
- length ;
- else {
- inptr + tart;
- if (length > slen)
- length len;
- }
+ if (length < 0) length ;
+ else if (length > slen) length len;
+
+ if (start > slen) {
+ start len;
+ length ;
+ }
+ else if (start < 0) {
+ start + len;
+ if (start < 0) {
+ start ;
+ length ;
+ }
+ }
+
+ if (start + length > slen) {
+ length len - start;
+ }
+
+ if (start > 0 && start < len) inptr + tart;
}
instart nptr;
inlen ength;
------ art_6630_25899736.1212550891253
Content-Type: application/octet-stream;
name
onv_convert_range_check-1.8.patch
Content-Transfer-Encoding: base64
X-Attachment-Id: f_fh1dc61s0
Content-Disposition: attachment;
filename
onv_convert_range_check-1.8.patch
SW5kZXg6IGV4dC9pY29udi9pY29udi5jCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KLS0tIGV4dC9pY29udi9pY29udi5j
CShyZXZpc2lvbiAxNjc5OSkKKysrIGV4dC9pY29udi9pY29udi5jCSh3b3JraW5nIGNvcHkpCkBA
IC00MTcsMTcgKzQxNywyNiBAQAogCXNsZW4gPSBSU1RSSU5HKHN0ciktPmxlbjsKIAlpbnB0ciA9
IFJTVFJJTkcoc3RyKS0+cHRyOwogCi0JaWYgKHN0YXJ0IDwgMCA/IChzdGFydCArPSBzbGVuKSA8
IDAgOiBzdGFydCA+PSBzbGVuKQotCSAgICBsZW5ndGggPSAwOwotCWVsc2UgaWYgKGxlbmd0aCA8
IDAgJiYgKGxlbmd0aCArPSBzbGVuICsgMSkgPCAwKQotCSAgICBsZW5ndGggPSAwOwotCWVsc2Ug
aWYgKChsZW5ndGggLT0gc3RhcnQpIDwgMCkKLQkgICAgbGVuZ3RoID0gMDsKLQllbHNlIHsKLQkg
ICAgaW5wdHIgKz0gc3RhcnQ7Ci0JICAgIGlmIChsZW5ndGggPiBzbGVuKQotCQlsZW5ndGggPSBz
bGVuOwotCX0KKyAgICAgICAgaWYgKGxlbmd0aCA8IDApIGxlbmd0aCA9IDA7CisgICAgICAgIGVs
c2UgaWYgKGxlbmd0aCA+IHNsZW4pIGxlbmd0aCA9IHNsZW47CisgICAgICAgIAorICAgICAgICBp
ZiAoc3RhcnQgPiBzbGVuKSB7CisgICAgICAgICAgICBzdGFydCA9IHNsZW47CisgICAgICAgICAg
ICBsZW5ndGggPSAwOworICAgICAgICB9CisgICAgICAgIGVsc2UgaWYgKHN0YXJ0IDwgMCkgewor
ICAgICAgICAgICAgc3RhcnQgKz0gc2xlbjsKKyAgICAgICAgICAgIGlmIChzdGFydCA8IDApIHsK
KyAgICAgICAgICAgICAgICBzdGFydCA9IDA7CisgICAgICAgICAgICAgICAgbGVuZ3RoID0gMDsK
KyAgICAgICAgICAgIH0KKyAgICAgICAgfQorCisgICAgICAgIGlmIChzdGFydCArIGxlbmd0aCA+
IHNsZW4pIHsKKyAgICAgICAgICAgIGxlbmd0aCA9IHNsZW4gLSBzdGFydDsKKyAgICAgICAgfQor
CisgICAgICAgIGlmIChzdGFydCA+IDAgJiYgc3RhcnQgPD0gc2xlbikgaW5wdHIgKz0gc3RhcnQ7
CiAgICAgfQogICAgIGluc3RhcnQgPSBpbnB0cjsKICAgICBpbmxlbiA9IGxlbmd0aDsK
------ art_6630_25899736.1212550891253--