Skip to content

Commit 290aac3

Browse files
committed
Fix EncodingError message when an invalid Symbol is met at parse time
1 parent 071cbf4 commit 290aac3

File tree

4 files changed

+7
-11
lines changed

4 files changed

+7
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ Compatibility:
6969
* Support writing to `RData.dfree` for native extensions (#2830, #2732, #2165, @eregon).
7070
* Fix `IO#write` and support multiple arguments with different encodings (#2829, @andrykonchin).
7171
* Fix `Array` methods `reject`, `reject!`, `inject`, `map`, `select`, `each_index` and handle a case when array is modified by a passed block like CRuby does (#2822, andrykonchin, @eregon).
72+
* Fix `EncodingError` exception message when Symbol has invalid encoding (#2850, @andrykonchin).
7273

7374
Performance:
7475

spec/ruby/language/symbol_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@
9696
%I{a b #{"c"}}.should == [:a, :b, :c]
9797
end
9898

99-
it "with invalid bytes raises an EncodingError at parse time" do
99+
it "raises an EncodingError at parse time when Symbol with invalid bytes" do
100100
ScratchPad.record []
101101
-> {
102102
eval 'ScratchPad << 1; :"\xC3"'
103-
}.should raise_error(EncodingError, /invalid/)
103+
}.should raise_error(EncodingError, 'invalid symbol in encoding UTF-8 :"\xC3"')
104104
ScratchPad.recorded.should == []
105105
end
106106
end

src/main/java/org/truffleruby/core/exception/CoreExceptions.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,14 +1110,6 @@ public RubyException regexpError(String message, Node currentNode) {
11101110

11111111
// Encoding conversion errors.
11121112

1113-
@TruffleBoundary
1114-
public RubyException encodingError(String message, Node currentNode) {
1115-
RubyClass exceptionClass = context.getCoreLibrary().encodingErrorClass;
1116-
RubyString errorMessage = StringOperations.createUTF8String(context, language, message);
1117-
1118-
return ExceptionOperations.createRubyException(context, exceptionClass, errorMessage, currentNode, null);
1119-
}
1120-
11211113
@TruffleBoundary
11221114
public RubyException encodingError(Object string, RubyEncoding encoding, Node currentNode) {
11231115
RubyClass exceptionClass = context.getCoreLibrary().encodingErrorClass;

src/main/java/org/truffleruby/parser/parser/ParserSupport.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,10 @@ private void checkSymbolCodeRange(SymbolParseNode symbolParseNode) {
12591259
if (!symbolParseNode.getTString().isValidUncached(symbolParseNode.getRubyEncoding().tencoding)) {
12601260
throw new RaiseException(
12611261
RubyLanguage.getCurrentContext(),
1262-
getConfiguration().getContext().getCoreExceptions().encodingError("invalid encoding symbol", null));
1262+
getConfiguration().getContext().getCoreExceptions().encodingError(
1263+
symbolParseNode.getTString(),
1264+
symbolParseNode.getRubyEncoding(),
1265+
null));
12631266
}
12641267
}
12651268

0 commit comments

Comments
 (0)