Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Marshal load loses correct encoding for string subclass #939
I am getting unexpected behavior when using Marshal.load on a subclass of string that includes an instance variable with a value. In the example below the instance variable is an integer, but it seems to do this with anything other than nil for the instance variable.
Note that Marshal.dump seems to yield identical output in JRuby and MRI (the encoding of the Marshal.dump string is ASCII-8BIT in both cases as expected)
This problem was encountered in a Rails app after attempting to cache an object containing an object with a subclass of string.
The workaround I am using is to customize marshal_dump on the class to return an array with the string data as one element and the ivars as the other.
Turned out to be a fairly simple problem; the unmarshaling logic was buggy, looking for encoding in the last instance variable coming off the stream, rather than the first. I rewrote the logic to be less confusing and set it up to use the first variable, as in MRI.