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

inherit encoding for interned symbols #7618

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
Expand Up @@ -6305,12 +6305,18 @@ public IRubyObject each_grapheme_cluster(ThreadContext context, Block block) {
@JRubyMethod(name = {"to_sym", "intern"})
public RubySymbol intern() {
final Ruby runtime = getRuntime();
Encoding originalEncoding = getEncoding();
int codeRange = scanForCodeRange();

if (scanForCodeRange() == CR_BROKEN) {
throw runtime.newEncodingError("invalid symbol in encoding " + getEncoding() + " :" + inspect());
if (codeRange == CR_BROKEN) {
throw runtime.newEncodingError("invalid symbol in encoding " + originalEncoding + " :" + inspect());
}

RubySymbol symbol = runtime.getSymbolTable().getSymbol(value);
boolean asciiCompatible = originalEncoding.isAsciiCompatible() && codeRange == CR_7BIT;
if (!asciiCompatible) {
symbol.associateEncoding(originalEncoding);
}
if (symbol.getBytes() == value) shareLevel = SHARE_LEVEL_BYTELIST;
return symbol;
}
Expand Down
2 changes: 0 additions & 2 deletions spec/tags/ruby/core/string/intern_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/tags/ruby/core/string/to_sym_tags.txt

This file was deleted.