Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String#b improperly updates encoding of source string #2338

Closed
nirvdrum opened this Issue Dec 21, 2014 · 3 comments

Comments

Projects
None yet
3 participants
@nirvdrum
Copy link
Contributor

nirvdrum commented Dec 21, 2014

String#b is supposed to make a copy of a string and set its encoding to ASCII-8BIT. As an optimization, JRuby uses a cheap dup operation that causes the new string to share the original's backing store. The problem is any changes made to the new string's encoding are shared with the source string.

Example:

$ ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]

$ ruby -e "s = 'x'; p s.encoding.name; p s.b.encoding.name; p s.encoding.name"
"UTF-8"
"ASCII-8BIT"
"UTF-8"
$ JRUBY_OPTS="" bin/jruby -v
jruby 9.0.0.0-SNAPSHOT (2.2.0p0) 2014-12-18 766148d Java HotSpot(TM) 64-Bit Server VM 24.72-b04 on 1.7.0_72-b14 +jit [linux-amd64]

$ JRUBY_OPTS="" bin/jruby -e "s = 'x'; p s.encoding.name; p s.b.encoding.name; p s.encoding.name"
"UTF-8"
"ASCII-8BIT"
"ASCII-8BIT"

Doing a full dupe should be sufficient to fix the problem.

@enebo enebo added this to the JRuby 1.7.19 milestone Dec 22, 2014

@nirvdrum

This comment has been minimized.

Copy link
Contributor Author

nirvdrum commented Dec 24, 2014

I guess I didn't format to whatever Github's new rules are. Fixed in master as 4e40732 and on 1.7 as bee9d02.

@nirvdrum nirvdrum closed this Dec 24, 2014

@nirvdrum

This comment has been minimized.

Copy link
Contributor Author

nirvdrum commented Dec 24, 2014

While my fix passes specs in 1.7, it causes failures is master that I need to track down.

@enebo

This comment has been minimized.

Copy link
Member

enebo commented Jan 29, 2015

@nirvdrum I am closing this so it shows up in 1.7.19 commits fixed. Can you open up followup on whatever is still wrong on master?

@enebo enebo closed this Jan 29, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.