String#encode leaves garbage on resulting string
------------------------------------------------

                 Key: JRUBY-4305
                 URL: http://jira.codehaus.org/browse/JRUBY-4305
             Project: JRuby
          Issue Type: Bug
          Components: Core Classes/Modules, Ruby 1.9
    Affects Versions: JRuby 1.4, JRuby 1.x+
            Reporter: Daniel Luz
         Attachments: 
0003-1.9-Fixed-String-encode-returning-garbage-from-unuse.patch

Simple test:

    $ ruby1.9 -e 'p "caf\xe9".force_encoding("iso-8859-1").encode("utf-8")'
    "café"

    $ jruby --1.9 -e 'p "caf\xe9".force_encoding("iso-8859-1").encode("utf-8")'
    "café\x00\x00\x00\x00"

CharsetEncoder#encode doesn't guarantee the buffer won't have some spare space, 
so you have to check #limit().

Patch included. Since the returned array is brand new and not referenced 
anywhere else, I just reused it for the ByteList, rather than copying the 
resulting data over to a new array.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to