Skip to content

String#encode fails with :invalid => :replace option #375

@dudleyf

Description

@dudleyf

Under MRI (1.9.3-p286):

dudley@kima ~ :> ruby -e 'puts "foo".encode("UTF-16", :invalid => :replace)'
??foo

Under JRuby (1.7.0):

dudley@kima ~ :> ruby -e '"foo".encode("UTF-16", :invalid => :replace)'     
CharsetEncoder.java:285:in `replaceWith': java.lang.IllegalArgumentException: Illegal replacement
    from CharsetTranscoder.java:201:in `getCharsetEncoder'
    from CharsetTranscoder.java:69:in `transcode'
    from CharsetTranscoder.java:58:in `transcode'
    from CharsetTranscoder.java:97:in `transcode'
    from RubyString.java:7559:in `transcode'
    from RubyString.java:7525:in `encode'
    from RubyString$INVOKER$i$encode.gen:-1:in `call'
    from MethodHandle.java:599:in `invokeWithArguments'
    from InvocationLinker.java:183:in `invocationFallback'
    from -e:1:in `__file__'
    from -e:-1:in `load'
    from Ruby.java:770:in `runScript'
    from Ruby.java:763:in `runScript'
    from Ruby.java:640:in `runNormally'
    from Ruby.java:489:in `runFromMain'
    from Main.java:375:in `doRunFromMain'
    from Main.java:264:in `internalRun'
    from Main.java:230:in `run'
    from Main.java:214:in `run'
    from Main.java:194:in `main'

According to the docs (http://www.ruby-doc.org/core-1.9.3/String.html#method-i-encode), the replacement string should default to "\uFFFD" for Unicode encoding forms, and "?" otherwise.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions